private static Pair <QueryPlanIndexItem, IndexMultiKey> PlanIndex(bool unique,
                                                                          IList <IndexedPropDesc> hashProps,
                                                                          IList <IndexedPropDesc> btreeProps,
                                                                          bool mustCoerce)
        {
            // not resolved as full match and not resolved as unique index match, allocate
            var indexPropKey = new IndexMultiKey(unique, hashProps, btreeProps);

            var indexedPropDescs   = hashProps.ToArray();
            var indexProps         = IndexedPropDesc.GetIndexProperties(indexedPropDescs);
            var indexCoercionTypes = IndexedPropDesc.GetCoercionTypes(indexedPropDescs);

            if (!mustCoerce)
            {
                indexCoercionTypes = null;
            }

            var rangePropDescs     = btreeProps.ToArray();
            var rangeProps         = IndexedPropDesc.GetIndexProperties(rangePropDescs);
            var rangeCoercionTypes = IndexedPropDesc.GetCoercionTypes(rangePropDescs);

            var indexItem = new QueryPlanIndexItem(indexProps, indexCoercionTypes, rangeProps, rangeCoercionTypes, unique);

            return(new Pair <QueryPlanIndexItem, IndexMultiKey>(indexItem, indexPropKey));
        }
Beispiel #2
0
        public EventTable GetJoinIndexTable(QueryPlanIndexItem queryPlanIndexItem)
        {
            IList <VirtualDataWindowLookupFieldDesc> hashFields = new List <VirtualDataWindowLookupFieldDesc>();
            var count = 0;

            if (queryPlanIndexItem.IndexProps != null)
            {
                foreach (var indexProp in queryPlanIndexItem.IndexProps)
                {
                    var coercionType = queryPlanIndexItem.OptIndexCoercionTypes == null
                        ? null
                        : queryPlanIndexItem.OptIndexCoercionTypes[count];
                    hashFields.Add(
                        new VirtualDataWindowLookupFieldDesc(indexProp, VirtualDataWindowLookupOp.EQUALS, coercionType));
                    count++;
                }
            }

            IList <VirtualDataWindowLookupFieldDesc> btreeFields = new List <VirtualDataWindowLookupFieldDesc>();

            count = 0;
            if (queryPlanIndexItem.RangeProps != null)
            {
                foreach (var btreeprop in queryPlanIndexItem.RangeProps)
                {
                    var coercionType = queryPlanIndexItem.OptRangeCoercionTypes == null
                        ? null
                        : queryPlanIndexItem.OptRangeCoercionTypes[count];
                    btreeFields.Add(new VirtualDataWindowLookupFieldDesc(btreeprop, null, coercionType));
                    count++;
                }
            }

            return(new VirtualDWEventTable(false, hashFields, btreeFields, TABLE_ORGANIZATION));
        }
 public EventTableIndexMetadataEntry(string optionalIndexName, bool primary, QueryPlanIndexItem queryPlanIndexItem)
     : base(optionalIndexName)
 {
     _primary            = primary;
     _queryPlanIndexItem = queryPlanIndexItem;
     _referencedByStmt   = primary ? null : new HashSet <string>();
 }
Beispiel #4
0
        public TableMetadata(
            string tableName,
            string eplExpression,
            string statementName,
            Type[] keyTypes,
            IDictionary<string, TableMetadataColumn> tableColumns,
            TableStateRowFactory rowFactory,
            int numberMethodAggregations,
            StatementContext createTableStatementContext,
            ObjectArrayEventType internalEventType,
            ObjectArrayEventType publicEventType,
            TableMetadataInternalEventToPublic eventToPublic,
            bool queryPlanLogging)
        {
            _tableName = tableName;
            _eplExpression = eplExpression;
            _statementName = statementName;
            _keyTypes = keyTypes;
            _tableColumns = tableColumns;
            _rowFactory = rowFactory;
            _numberMethodAggregations = numberMethodAggregations;
            _statementContextCreateTable = createTableStatementContext;
            _internalEventType = internalEventType;
            _publicEventType = publicEventType;
            _eventToPublic = eventToPublic;
            _queryPlanLogging = queryPlanLogging;

            if (keyTypes.Length > 0)
            {
                var pair = TableServiceUtil.GetIndexMultikeyForKeys(tableColumns, internalEventType);
                var queryPlanIndexItem = QueryPlanIndexItem.FromIndexMultikeyTablePrimaryKey(pair.Second);
                _eventTableIndexMetadataRepo.AddIndexExplicit(true, pair.Second, tableName, queryPlanIndexItem, createTableStatementContext.StatementName);
                _tableRowKeyFactory = new TableRowKeyFactory(pair.First);
            }
        }
Beispiel #5
0
        public void AddIndexExplicit(
            bool isPrimary,
            IndexMultiKey indexMultiKey,
            string explicitIndexName,
            string explicitIndexModuleName,
            QueryPlanIndexItem explicitIndexDesc,
            string deploymentId)
        {
            if (GetIndexByName(explicitIndexName) != null) {
                throw new ExprValidationException("An index by name '" + explicitIndexName + "' already exists");
            }

            if (Indexes.ContainsKey(indexMultiKey)) {
                throw new ExprValidationException("An index for the same columns already exists");
            }

            var entry = new EventTableIndexMetadataEntry(
                explicitIndexName,
                explicitIndexModuleName,
                isPrimary,
                explicitIndexDesc,
                explicitIndexName,
                explicitIndexModuleName,
                deploymentId);
            entry.AddReferringDeployment(deploymentId);
            Indexes.Put(indexMultiKey, entry);
        }
Beispiel #6
0
 public IndexDetail(
     IndexMultiKey indexMultiKey,
     QueryPlanIndexItem queryPlanIndexItem)
 {
     this.indexMultiKey = indexMultiKey;
     this.queryPlanIndexItem = queryPlanIndexItem;
 }
 private static void CompareIndexItem(int stream, int num, QueryPlanIndexItem expectedIndex, QueryPlanIndexItem actualIndex)
 {
     if (!expectedIndex.EqualsCompareSortedProps(actualIndex))
     {
         Assert.Fail("At stream " + stream + " index " + num + "\nExpected:\n" + expectedIndex + "\n" +
                     "Received:\n" + actualIndex + "\n");
     }
 }
 public override void AddExplicitIndex(
     string indexName,
     string indexModuleName,
     QueryPlanIndexItem explicitIndexDesc,
     bool isRecoveringResilient)
 {
     throw new UnsupportedOperationException("Ungrouped tables do not allow explicit indexes");
 }
Beispiel #9
0
 public void AddIndex(
     string indexName,
     string indexModuleName,
     IndexMultiKey imk,
     QueryPlanIndexItem optionalQueryPlanIndexItem)
 {
     IndexMetadata.AddIndexExplicit(false, imk, indexName, indexModuleName, optionalQueryPlanIndexItem, "");
 }
 public override void AddExplicitIndex(string explicitIndexName, QueryPlanIndexItem explicitIndexDesc, bool isRecoveringResilient, bool allowIndexExists)
 {
     _indexRepository.ValidateAddExplicitIndex(
         explicitIndexName,
         explicitIndexDesc,
         _tableMetadata.InternalEventType,
         new PrimaryIndexIterable(_rows),
         AgentInstanceContext,
         isRecoveringResilient || allowIndexExists, null);
 }
Beispiel #11
0
 public SubordinateQueryIndexDesc(
     IndexKeyInfo optionalIndexKeyInfo,
     string indexName,
     IndexMultiKey indexMultiKey,
     QueryPlanIndexItem queryPlanIndexItem)
 {
     OptionalIndexKeyInfo = optionalIndexKeyInfo;
     IndexName = indexName;
     IndexMultiKey = indexMultiKey;
     QueryPlanIndexItem = queryPlanIndexItem;
 }
        public static void AssertJoinOneStreamAndReset(bool unique)
        {
            Assert.IsTrue(Joins.Count == 1);
            QueryPlan              join      = Joins[0];
            QueryPlanIndex         first     = join.IndexSpecs[1];
            TableLookupIndexReqKey firstName = first.Items.Keys.First();
            QueryPlanIndexItem     index     = first.Items.Get(firstName);

            Assert.AreEqual(unique, index.IsUnique);
            Reset();
        }
        /// <summary>
        /// The AddExplicitIndex
        /// </summary>
        /// <param name="explicitIndexName">The <see cref="string"/></param>
        /// <param name="desc">The <see cref="QueryPlanIndexItem"/></param>
        /// <param name="eventType">The <see cref="EventType"/></param>
        /// <param name="dataWindowContents">The <see cref="IEnumerable{EventBean}"/></param>
        /// <param name="agentInstanceContext">The <see cref="AgentInstanceContext"/></param>
        /// <param name="optionalSerde">The <see cref="object"/></param>
        public void AddExplicitIndex(
            string explicitIndexName,
            QueryPlanIndexItem desc,
            EventType eventType,
            IEnumerable <EventBean> dataWindowContents,
            AgentInstanceContext agentInstanceContext,
            object optionalSerde)
        {
            Pair <IndexMultiKey, EventTableAndNamePair> pair = AddExplicitIndexOrReuse(desc.IsUnique, desc.HashPropsAsList, desc.BtreePropsAsList, desc.AdvancedIndexProvisionDesc, dataWindowContents, eventType, explicitIndexName, agentInstanceContext, optionalSerde);

            _explicitIndexes.Put(explicitIndexName, pair.Second.EventTable);
        }
        public static void AssertJoinAllStreamsAndReset(bool unique)
        {
            Assert.IsTrue(Joins.Count == 1);
            QueryPlan join = Joins[0];

            foreach (QueryPlanIndex index in join.IndexSpecs)
            {
                TableLookupIndexReqKey firstName = index.Items.Keys.First();
                QueryPlanIndexItem     indexDesc = index.Items.Get(firstName);
                Assert.AreEqual(unique, indexDesc.IsUnique);
            }
            Reset();
        }
        /// <summary>
        /// The AddIndex
        /// </summary>
        /// <param name="unique">The <see cref="bool"/></param>
        /// <param name="hashProps">The <see cref="IList{IndexedPropDesc}"/></param>
        /// <param name="btreeProps">The <see cref="IList{IndexedPropDesc}"/></param>
        /// <param name="advancedIndexProvisionDesc">The <see cref="EventAdvancedIndexProvisionDesc"/></param>
        /// <param name="prefilledEvents">The <see cref="IEnumerable{EventBean}"/></param>
        /// <param name="indexedType">The <see cref="EventType"/></param>
        /// <param name="indexName">The <see cref="string"/></param>
        /// <param name="mustCoerce">The <see cref="bool"/></param>
        /// <param name="agentInstanceContext">The <see cref="AgentInstanceContext"/></param>
        /// <param name="optionalSerde">The <see cref="object"/></param>
        /// <returns>The <see cref="Pair{IndexMultiKey, EventTableAndNamePair}"/></returns>
        private Pair <IndexMultiKey, EventTableAndNamePair> AddIndex(
            bool unique,
            IList <IndexedPropDesc> hashProps,
            IList <IndexedPropDesc> btreeProps,
            EventAdvancedIndexProvisionDesc advancedIndexProvisionDesc,
            IEnumerable <EventBean> prefilledEvents,
            EventType indexedType,
            string indexName,
            bool mustCoerce,
            AgentInstanceContext agentInstanceContext,
            object optionalSerde)
        {
            // not resolved as full match and not resolved as unique index match, allocate
            var indexPropKey = new IndexMultiKey(unique, hashProps, btreeProps, advancedIndexProvisionDesc == null ? null : advancedIndexProvisionDesc.IndexDesc);

            var indexedPropDescs   = hashProps.ToArray();
            var indexProps         = IndexedPropDesc.GetIndexProperties(indexedPropDescs);
            var indexCoercionTypes = IndexedPropDesc.GetCoercionTypes(indexedPropDescs);

            if (!mustCoerce)
            {
                indexCoercionTypes = null;
            }

            var rangePropDescs     = btreeProps.ToArray();
            var rangeProps         = IndexedPropDesc.GetIndexProperties(rangePropDescs);
            var rangeCoercionTypes = IndexedPropDesc.GetCoercionTypes(rangePropDescs);

            var indexItem = new QueryPlanIndexItem(indexProps, indexCoercionTypes, rangeProps, rangeCoercionTypes, unique, advancedIndexProvisionDesc);
            var table     = EventTableUtil.BuildIndex(agentInstanceContext, 0, indexItem, indexedType, true, unique, indexName, optionalSerde, false);

            // fill table since its new
            var events = new EventBean[1];

            foreach (EventBean prefilledEvent in prefilledEvents)
            {
                events[0] = prefilledEvent;
                table.Add(events, agentInstanceContext);
            }

            // add table
            _tables.Add(table);

            // add index, reference counted
            _tableIndexesRefCount.Put(indexPropKey, new EventTableIndexRepositoryEntry(indexName, table));

            return(new Pair <IndexMultiKey, EventTableAndNamePair>(indexPropKey, new EventTableAndNamePair(table, indexName)));
        }
Beispiel #16
0
 public override void AddExplicitIndex(
     string indexName,
     string indexModuleName,
     QueryPlanIndexItem explicitIndexDesc,
     bool isRecoveringResilient)
 {
     indexRepository.ValidateAddExplicitIndex(
         indexName,
         indexModuleName,
         explicitIndexDesc,
         table.MetaData.InternalEventType,
         new PrimaryIndexIterable(rows),
         AgentInstanceContext,
         isRecoveringResilient,
         null);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="StatementAgentInstanceFactoryCreateIndex"/> class.
 /// </summary>
 /// <param name="services">The <see cref="EPServicesContext"/></param>
 /// <param name="spec">The <see cref="CreateIndexDesc"/></param>
 /// <param name="finalView">The <see cref="Viewable"/></param>
 /// <param name="namedWindowProcessor">The <see cref="NamedWindowProcessor"/></param>
 /// <param name="tableName">The <see cref="string"/></param>
 /// <param name="contextName">The <see cref="string"/></param>
 /// <param name="explicitIndexDesc">The <see cref="QueryPlanIndexItem"/></param>
 public StatementAgentInstanceFactoryCreateIndex(
     EPServicesContext services,
     CreateIndexDesc spec,
     Viewable finalView,
     NamedWindowProcessor namedWindowProcessor,
     string tableName,
     string contextName,
     QueryPlanIndexItem explicitIndexDesc)
 {
     _services             = services;
     _spec                 = spec;
     _finalView            = finalView;
     _namedWindowProcessor = namedWindowProcessor;
     _tableName            = tableName;
     _contextName          = contextName;
     _explicitIndexDesc    = explicitIndexDesc;
 }
Beispiel #18
0
 public EventTableIndexMetadataEntry(
     string optionalIndexName,
     string optionalIndexModuleName,
     bool primary,
     QueryPlanIndexItem optionalQueryPlanIndexItem,
     string explicitIndexNameIfExplicit,
     string explicitIndexModuleNameIfExplicit,
     string deploymentId)
     : base(optionalIndexName, optionalIndexModuleName)
 {
     IsPrimary = primary;
     OptionalQueryPlanIndexItem = optionalQueryPlanIndexItem;
     referencedByDeployment = primary ? null : new HashSet<string>();
     ExplicitIndexNameIfExplicit = explicitIndexNameIfExplicit;
     ExplicitIndexModuleNameIfExplicit = explicitIndexModuleNameIfExplicit;
     DeploymentId = deploymentId;
 }
        /// <summary>
        /// The ValidateAddExplicitIndex
        /// </summary>
        /// <param name="explicitIndexName">The <see cref="string"/></param>
        /// <param name="explicitIndexDesc">The <see cref="QueryPlanIndexItem"/></param>
        /// <param name="eventType">The <see cref="EventType"/></param>
        /// <param name="dataWindowContents">The <see cref="IEnumerable{EventBean}"/></param>
        /// <param name="agentInstanceContext">The <see cref="AgentInstanceContext"/></param>
        /// <param name="allowIndexExists">The <see cref="bool"/></param>
        /// <param name="optionalSerde">The <see cref="object"/></param>
        public void ValidateAddExplicitIndex(
            string explicitIndexName,
            QueryPlanIndexItem explicitIndexDesc,
            EventType eventType,
            IEnumerable <EventBean> dataWindowContents,
            AgentInstanceContext agentInstanceContext,
            bool allowIndexExists,
            object optionalSerde)
        {
            if (_explicitIndexes.ContainsKey(explicitIndexName))
            {
                if (allowIndexExists)
                {
                    return;
                }
                throw new ExprValidationException("Index by name '" + explicitIndexName + "' already exists");
            }

            AddExplicitIndex(explicitIndexName, explicitIndexDesc, eventType, dataWindowContents, agentInstanceContext, optionalSerde);
        }
Beispiel #20
0
        public void ValidateAddIndexAssignUpdateStrategies(
            string createIndexStatementName,
            IndexMultiKey imk,
            string explicitIndexName,
            QueryPlanIndexItem explicitIndexDesc)
        {
            // add index - for now
            _eventTableIndexMetadataRepo.AddIndexExplicit(false, imk, explicitIndexName, explicitIndexDesc, createIndexStatementName);

            // validate strategies, rollback if required
            foreach (var stmtEntry in _stmtNameToUpdateStrategyReceivers)
            {
                foreach (var strategyReceiver in stmtEntry.Value)
                {
                    try
                    {
                        TableUpdateStrategyFactory.ValidateGetTableUpdateStrategy(
                            this, strategyReceiver.UpdateHelper, strategyReceiver.IsOnMerge);
                    }
                    catch (ExprValidationException ex)
                    {
                        _eventTableIndexMetadataRepo.RemoveIndex(imk);
                        throw new ExprValidationException(
                            "Failed to validate statement '" + stmtEntry.Key + "' as a recipient of the proposed index: " +
                            ex.Message);
                    }
                }
            }

            // assign new strategies
            foreach (var stmtEntry in _stmtNameToUpdateStrategyReceivers)
            {
                foreach (var strategyReceiver in stmtEntry.Value)
                {
                    var strategy = TableUpdateStrategyFactory.ValidateGetTableUpdateStrategy(
                        this, strategyReceiver.UpdateHelper, strategyReceiver.IsOnMerge);
                    strategyReceiver.Receiver.Update(strategy);
                }
            }
        }
Beispiel #21
0
 /// <summary>
 ///     Add an explicit index.
 /// </summary>
 /// <param name="explicitIndexDesc">index descriptor</param>
 /// <param name="explicitIndexModuleName">module name</param>
 /// <param name="isRecoveringResilient">indicator for recovering</param>
 /// <param name="explicitIndexName">index name</param>
 /// <throws>ExprValidationException if the index fails to be valid</throws>
 public void AddExplicitIndex(
     string explicitIndexName,
     string explicitIndexModuleName,
     QueryPlanIndexItem explicitIndexDesc,
     bool isRecoveringResilient)
 {
     lock (this) {
         var initIndex =
             AgentInstanceContext.StatementContext.EventTableIndexService.AllowInitIndex(isRecoveringResilient);
         var initializeFrom =
             initIndex ? DataWindowContents : CollectionUtil.NULL_EVENT_ITERABLE;
         IndexRepository.ValidateAddExplicitIndex(
             explicitIndexName,
             explicitIndexModuleName,
             explicitIndexDesc,
             rootView.EventType,
             initializeFrom,
             AgentInstanceContext,
             isRecoveringResilient,
             null);
     }
 }
Beispiel #22
0
        public void AddIndexNonExplicit(
            IndexMultiKey indexMultiKey,
            string deploymentId,
            QueryPlanIndexItem queryPlanIndexItem)
        {
            if (indexMultiKey == null) {
                throw new ArgumentException("Null index multikey");
            }

            if (Indexes.ContainsKey(indexMultiKey)) {
                return;
            }

            var entry = new EventTableIndexMetadataEntry(
                null,
                null,
                false,
                queryPlanIndexItem,
                null,
                null,
                deploymentId);
            entry.AddReferringDeployment(deploymentId);
            Indexes.Put(indexMultiKey, entry);
        }
Beispiel #23
0
        /// <summary>
        /// Build an index/table instance using the event properties for the event type.
        /// </summary>
        /// <param name="indexedStreamNum">number of stream indexed</param>
        /// <param name="item">The item.</param>
        /// <param name="eventType">type of event to expect</param>
        /// <param name="coerceOnAddOnly">if set to <c>true</c> [coerce on add only].</param>
        /// <param name="unique">if set to <c>true</c> [unique].</param>
        /// <param name="optionalIndexName">Name of the optional index.</param>
        /// <returns>table build</returns>
        public static EventTable BuildIndex(
            int indexedStreamNum,
            QueryPlanIndexItem item,
            EventType eventType,
            bool coerceOnAddOnly,
            bool unique,
            String optionalIndexName)
        {
            IList <string> indexProps         = item.IndexProps;
            IList <Type>   indexCoercionTypes = Normalize(item.OptIndexCoercionTypes);
            IList <string> rangeProps         = item.RangeProps;
            IList <Type>   rangeCoercionTypes = Normalize(item.OptRangeCoercionTypes);

            EventTable table;

            if (rangeProps == null || rangeProps.Count == 0)
            {
                if (indexProps == null || indexProps.Count == 0)
                {
                    table = new UnindexedEventTable(indexedStreamNum);
                }
                else
                {
                    // single index key
                    if (indexProps.Count == 1)
                    {
                        if (indexCoercionTypes == null || indexCoercionTypes.Count == 0)
                        {
                            var factory = new PropertyIndexedEventTableSingleFactory(
                                indexedStreamNum, eventType, indexProps[0], unique, optionalIndexName);
                            table = factory.MakeEventTables()[0];
                        }
                        else
                        {
                            if (coerceOnAddOnly)
                            {
                                var factory = new PropertyIndexedEventTableSingleCoerceAddFactory(
                                    indexedStreamNum, eventType, indexProps[0], indexCoercionTypes[0]);
                                table = factory.MakeEventTables()[0];
                            }
                            else
                            {
                                var factory = new PropertyIndexedEventTableSingleCoerceAllFactory(
                                    indexedStreamNum, eventType, indexProps[0], indexCoercionTypes[0]);
                                table = factory.MakeEventTables()[0];
                            }
                        }
                    }
                    // Multiple index keys
                    else
                    {
                        if (indexCoercionTypes == null || indexCoercionTypes.Count == 0)
                        {
                            var factory = new PropertyIndexedEventTableFactory(
                                indexedStreamNum, eventType, indexProps, unique, optionalIndexName);
                            table = factory.MakeEventTables()[0];
                        }
                        else
                        {
                            if (coerceOnAddOnly)
                            {
                                var factory = new PropertyIndexedEventTableCoerceAddFactory(
                                    indexedStreamNum, eventType, indexProps, indexCoercionTypes);
                                table = factory.MakeEventTables()[0];
                            }
                            else
                            {
                                var factory = new PropertyIndexedEventTableCoerceAllFactory(
                                    indexedStreamNum, eventType, indexProps, indexCoercionTypes);
                                table = factory.MakeEventTables()[0];
                            }
                        }
                    }
                }
            }
            else
            {
                if ((rangeProps.Count == 1) && (indexProps == null || indexProps.Count == 0))
                {
                    if (rangeCoercionTypes == null)
                    {
                        var factory = new PropertySortedEventTableFactory(indexedStreamNum, eventType, rangeProps[0]);
                        return(factory.MakeEventTables()[0]);
                    }
                    else
                    {
                        var factory = new PropertySortedEventTableCoercedFactory(
                            indexedStreamNum, eventType, rangeProps[0], rangeCoercionTypes[0]);
                        return(factory.MakeEventTables()[0]);
                    }
                }
                else
                {
                    var factory = new PropertyCompositeEventTableFactory(
                        indexedStreamNum, eventType, indexProps, indexCoercionTypes, rangeProps, rangeCoercionTypes);
                    return(factory.MakeEventTables()[0]);
                }
            }
            return(table);
        }
Beispiel #24
0
        public void AddIndex(bool isPrimary, IndexMultiKey indexMultiKey, string explicitIndexName, string statementName, bool failIfExists, QueryPlanIndexItem optionalQueryPlanIndexItem)
        {
            if (GetIndexByName(explicitIndexName) != null)
            {
                throw new ExprValidationException("An index by name '" + explicitIndexName + "' already exists");
            }
            if (indexes.ContainsKey(indexMultiKey))
            {
                if (failIfExists)
                {
                    throw new ExprValidationException("An index for the same columns already exists");
                }
                return;
            }
            EventTableIndexMetadataEntry entry = new EventTableIndexMetadataEntry(explicitIndexName, isPrimary, optionalQueryPlanIndexItem);

            entry.AddReferringStatement(statementName);
            indexes.Put(indexMultiKey, entry);
        }
 public void ValidateAddIndex(string statementName, string explicitIndexName, QueryPlanIndexItem explicitIndexDesc, IndexMultiKey imk)
 {
     _eventTableIndexMetadataRepo.AddIndexExplicit(false, imk, explicitIndexName, explicitIndexDesc, statementName);
 }
Beispiel #26
0
 public abstract void AddExplicitIndex(string explicitIndexName, QueryPlanIndexItem explicitIndexDesc, bool isRecoveringResilient, bool allowIndexExists);
        private static SubordinateQueryIndexDesc FindOrSuggestIndex(
            IDictionary <String, SubordPropHashKey> hashProps,
            IDictionary <String, SubordPropRangeKey> rangeProps,
            IndexHint optionalIndexHint,
            bool isIndexShare,
            int subqueryNumber,
            EventTableIndexMetadata indexMetadata,
            ICollection <string> optionalUniqueKeyProps,
            bool onlyUseExistingIndexes)
        {
            var indexProps          = GetIndexPropDesc(hashProps, rangeProps);
            var hashedAndBtreeProps = indexProps.ListPair;

            // Get or create the table for this index (exact match or property names, type of index and coercion type is expected)
            IndexKeyInfo       indexKeyInfo; // how needs all of IndexKeyInfo+QueryPlanIndexItem+IndexMultiKey
            IndexMultiKey      indexMultiKey;
            string             indexName     = null;
            QueryPlanIndexItem planIndexItem = null;

            if (hashedAndBtreeProps.HashedProps.IsEmpty() && hashedAndBtreeProps.BtreeProps.IsEmpty())
            {
                return(null);
            }

            Pair <IndexMultiKey, string>             existing = null;
            Pair <QueryPlanIndexItem, IndexMultiKey> planned  = null;

            // consider index hints
            IList <IndexHintInstruction> optionalIndexHintInstructions = null;

            if (optionalIndexHint != null)
            {
                optionalIndexHintInstructions = optionalIndexHint.GetInstructionsSubquery(subqueryNumber);
            }

            var indexFoundPair = EventTableIndexUtil.FindIndexConsiderTyping(indexMetadata.Indexes, hashedAndBtreeProps.HashedProps, hashedAndBtreeProps.BtreeProps, optionalIndexHintInstructions);

            if (indexFoundPair != null)
            {
                var hintIndex = indexMetadata.Indexes.Get(indexFoundPair);
                existing = new Pair <IndexMultiKey, string>(indexFoundPair, hintIndex.OptionalIndexName);
            }

            // nothing found: plan one
            if (existing == null && !onlyUseExistingIndexes)
            {
                // not found, see if the item is declared unique
                var proposedHashedProps = hashedAndBtreeProps.HashedProps;
                var proposedBtreeProps  = hashedAndBtreeProps.BtreeProps;

                // match against unique-key properties when suggesting an index
                var unique = false;
                var coerce = !isIndexShare;
                if (optionalUniqueKeyProps != null && !optionalUniqueKeyProps.IsEmpty())
                {
                    IList <IndexedPropDesc> newHashProps = new List <IndexedPropDesc>();
                    foreach (var uniqueKey in optionalUniqueKeyProps)
                    {
                        var found = false;
                        foreach (var hashProp in hashedAndBtreeProps.HashedProps)
                        {
                            if (hashProp.IndexPropName.Equals(uniqueKey))
                            {
                                newHashProps.Add(hashProp);
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            newHashProps = null;
                            break;
                        }
                    }
                    if (newHashProps != null)
                    {
                        proposedHashedProps = newHashProps;
                        proposedBtreeProps  = Collections.GetEmptyList <IndexedPropDesc>();
                        unique = true;
                        coerce = false;
                    }
                }

                planned = PlanIndex(unique, proposedHashedProps, proposedBtreeProps, coerce);
            }

            // compile index information
            if (existing == null && planned == null)
            {
                return(null);
            }
            // handle existing
            if (existing != null)
            {
                indexKeyInfo = SubordinateQueryPlannerUtil.CompileIndexKeyInfo(existing.First,
                                                                               indexProps.HashIndexPropsProvided, indexProps.HashJoinedProps,
                                                                               indexProps.RangeIndexPropsProvided, indexProps.RangeJoinedProps);
                indexName     = existing.Second;
                indexMultiKey = existing.First;
            }
            // handle planned
            else
            {
                indexKeyInfo = SubordinateQueryPlannerUtil.CompileIndexKeyInfo(planned.Second,
                                                                               indexProps.HashIndexPropsProvided, indexProps.HashJoinedProps,
                                                                               indexProps.RangeIndexPropsProvided, indexProps.RangeJoinedProps);
                indexMultiKey = planned.Second;
                planIndexItem = planned.First;
            }

            return(new SubordinateQueryIndexDesc(indexKeyInfo, indexName, indexMultiKey, planIndexItem));
        }
Beispiel #28
0
 public override void AddExplicitIndex(string explicitIndexName, QueryPlanIndexItem explicitIndexDesc, bool isRecoveringResilient, bool allowIndexExists)
 {
     throw new ExprValidationException("Tables without primary key column(s) do not allow creating an index");
 }
Beispiel #29
0
        /// <summary>
        /// Build an index/table instance using the event properties for the event type.
        /// </summary>
        /// <param name="indexedStreamNum">- number of stream indexed</param>
        /// <param name="eventType">- type of event to expect</param>
        /// <param name="optionalIndexName">index name</param>
        /// <param name="agentInstanceContext">context</param>
        /// <param name="item">plan item</param>
        /// <param name="optionalSerde">serde if any</param>
        /// <param name="isFireAndForget">indicates fire-and-forget</param>
        /// <param name="unique">indicates unique</param>
        /// <param name="coerceOnAddOnly">indicator whether to coerce on value-add</param>
        /// <returns>table build</returns>
        public static EventTable BuildIndex(AgentInstanceContext agentInstanceContext, int indexedStreamNum, QueryPlanIndexItem item, EventType eventType, bool coerceOnAddOnly, bool unique, string optionalIndexName, Object optionalSerde, bool isFireAndForget)
        {
            var indexProps         = item.IndexProps;
            var indexCoercionTypes = Normalize(item.OptIndexCoercionTypes);
            var rangeProps         = item.RangeProps;
            var rangeCoercionTypes = Normalize(item.OptRangeCoercionTypes);
            var ident = new EventTableFactoryTableIdentAgentInstance(agentInstanceContext);
            var eventTableIndexService = agentInstanceContext.StatementContext.EventTableIndexService;

            EventTable table;

            if (item.AdvancedIndexProvisionDesc != null)
            {
                table = eventTableIndexService.CreateCustom(optionalIndexName, indexedStreamNum, eventType, item.IsUnique, item.AdvancedIndexProvisionDesc).MakeEventTables(ident, agentInstanceContext)[0];
            }
            else if (rangeProps == null || rangeProps.Count == 0)
            {
                if (indexProps == null || indexProps.Count == 0)
                {
                    var factory = eventTableIndexService.CreateUnindexed(indexedStreamNum, optionalSerde, isFireAndForget);
                    table = factory.MakeEventTables(ident, agentInstanceContext)[0];
                }
                else
                {
                    // single index key
                    if (indexProps.Count == 1)
                    {
                        if (indexCoercionTypes == null || indexCoercionTypes.Count == 0)
                        {
                            var factory = eventTableIndexService.CreateSingle(indexedStreamNum, eventType, indexProps[0], unique, optionalIndexName, optionalSerde, isFireAndForget);
                            table = factory.MakeEventTables(ident, agentInstanceContext)[0];
                        }
                        else
                        {
                            if (coerceOnAddOnly)
                            {
                                var factory = eventTableIndexService.CreateSingleCoerceAdd(indexedStreamNum, eventType, indexProps[0], indexCoercionTypes[0], optionalSerde, isFireAndForget);
                                table = factory.MakeEventTables(ident, agentInstanceContext)[0];
                            }
                            else
                            {
                                var factory = eventTableIndexService.CreateSingleCoerceAll(indexedStreamNum, eventType, indexProps[0], indexCoercionTypes[0], optionalSerde, isFireAndForget);
                                table = factory.MakeEventTables(ident, agentInstanceContext)[0];
                            }
                        }
                    }
                    else
                    {
                        // Multiple index keys
                        if (indexCoercionTypes == null || indexCoercionTypes.Count == 0)
                        {
                            var factory = eventTableIndexService.CreateMultiKey(indexedStreamNum, eventType, indexProps, unique, optionalIndexName, optionalSerde, isFireAndForget);
                            table = factory.MakeEventTables(ident, agentInstanceContext)[0];
                        }
                        else
                        {
                            if (coerceOnAddOnly)
                            {
                                var factory = eventTableIndexService.CreateMultiKeyCoerceAdd(indexedStreamNum, eventType, indexProps, indexCoercionTypes, isFireAndForget);
                                table = factory.MakeEventTables(ident, agentInstanceContext)[0];
                            }
                            else
                            {
                                var factory = eventTableIndexService.CreateMultiKeyCoerceAll(indexedStreamNum, eventType, indexProps, indexCoercionTypes, isFireAndForget);
                                table = factory.MakeEventTables(ident, agentInstanceContext)[0];
                            }
                        }
                    }
                }
            }
            else
            {
                if ((rangeProps.Count == 1) && (indexProps == null || indexProps.Count == 0))
                {
                    if (rangeCoercionTypes == null)
                    {
                        var factory = eventTableIndexService.CreateSorted(indexedStreamNum, eventType, rangeProps[0], isFireAndForget);
                        return(factory.MakeEventTables(ident, agentInstanceContext)[0]);
                    }
                    else
                    {
                        var factory = eventTableIndexService.CreateSortedCoerce(indexedStreamNum, eventType, rangeProps[0], rangeCoercionTypes[0], isFireAndForget);
                        return(factory.MakeEventTables(ident, agentInstanceContext)[0]);
                    }
                }
                else
                {
                    var factory = eventTableIndexService.CreateComposite(indexedStreamNum, eventType, indexProps, indexCoercionTypes, rangeProps, rangeCoercionTypes, isFireAndForget);
                    return(factory.MakeEventTables(ident, agentInstanceContext)[0]);
                }
            }
            return(table);
        }
        public void AddIndexNonExplicit(IndexMultiKey indexMultiKey, string statementName, QueryPlanIndexItem queryPlanIndexItem)
        {
            if (_indexes.ContainsKey(indexMultiKey))
            {
                return;
            }
            var entry = new EventTableIndexMetadataEntry(null, false, queryPlanIndexItem, null);

            entry.AddReferringStatement(statementName);
            _indexes.Put(indexMultiKey, entry);
        }