public IExecutionPlanOperation GetRootOperation()
        {
            // If no join then single table select/delete.
            if (!joins.Any())
            {
                if (filters.Any())
                {
                    // Try to get a filter which can use an index.
                    var indexScanFilter = TryGetFilterWithIndex(filters);
                    var firstFilter = indexScanFilter.Key;
                    var table = database.GetTable(firstFilter.Table);
                    IExecutionPlanOperation predecessor = null;

                    if (indexScanFilter.Value != null)
                    {
                        var readOperation = new NonUniqueScanOperation(table, indexScanFilter.Value, firstFilter, repository,
                            KeyValue.GetDatabaseFileName(database.Name), table.Name);
                        predecessor = readOperation;
                    }
                    else
                    {
                        var readOperation = new FullScanOperation(table, repository, KeyValue.GetDatabaseFileName(database.Name),
                            table.Name);
                        predecessor = new FilterOperation(readOperation, firstFilter);
                    }

                    filters.Remove(firstFilter);

                    for (int i = 0; i < filters.Count; i++)
                    {
                        var operation = new FilterOperation(predecessor, filters.ElementAt(i));
                        predecessor = operation;
                    }

                    if (selections.Any())
                    {
                        predecessor = new SelectOperation(predecessor, selections.First());
                    }

                    return predecessor;
                }
                else
                {
                    var selection = selections.First();
                    var table = database.GetTable(selection.Table);
                    var fullScanOperation = new FullScanOperation(table, repository, KeyValue.GetDatabaseFileName(database.Name), table.Name);

                    return new SelectOperation(fullScanOperation, selection);
                }
            }
            else
            {
                // Handle selections with join operation.
                return null;
            }
        }
Пример #2
0
        public IExecutionPlanOperation GetRootOperation()
        {
            // If no join then single table select/delete.
            if (!joins.Any())
            {
                if (filters.Any())
                {
                    // Try to get a filter which can use an index.
                    var indexScanFilter = TryGetFilterWithIndex(filters);
                    var firstFilter     = indexScanFilter.Key;
                    var table           = database.GetTable(firstFilter.Table);
                    IExecutionPlanOperation predecessor = null;

                    if (indexScanFilter.Value != null)
                    {
                        var readOperation = new NonUniqueScanOperation(table, indexScanFilter.Value, firstFilter, repository,
                                                                       KeyValue.GetDatabaseFileName(database.Name), table.Name);
                        predecessor = readOperation;
                    }
                    else
                    {
                        var readOperation = new FullScanOperation(table, repository, KeyValue.GetDatabaseFileName(database.Name),
                                                                  table.Name);
                        predecessor = new FilterOperation(readOperation, firstFilter);
                    }

                    filters.Remove(firstFilter);

                    for (int i = 0; i < filters.Count; i++)
                    {
                        var operation = new FilterOperation(predecessor, filters.ElementAt(i));
                        predecessor = operation;
                    }

                    if (selections.Any())
                    {
                        predecessor = new SelectOperation(predecessor, selections.First());
                    }

                    return(predecessor);
                }
                else
                {
                    var selection         = selections.First();
                    var table             = database.GetTable(selection.Table);
                    var fullScanOperation = new FullScanOperation(table, repository, KeyValue.GetDatabaseFileName(database.Name), table.Name);

                    return(new SelectOperation(fullScanOperation, selection));
                }
            }
            else
            {
                // Handle selections with join operation.
                return(null);
            }
        }