Exemplo n.º 1
0
        private static Pair<IndexMultiKey, EventTableAndNamePair> FindIndex(
            ISet<string> keyNamesAvailable,
            ISet<string> rangeNamesAvailable,
            EventTableIndexRepository indexRepository,
            VirtualDWView virtualDataWindow,
            Attribute[] annotations)
        {
            if (virtualDataWindow != null) {
                var tablePairNoName = VirtualDWQueryPlanUtil.GetFireAndForgetDesc(
                    virtualDataWindow.EventType,
                    keyNamesAvailable,
                    rangeNamesAvailable);
                return new Pair<IndexMultiKey, EventTableAndNamePair>(
                    tablePairNoName.First,
                    new EventTableAndNamePair(tablePairNoName.Second, null));
            }

            var indexHint = IndexHint.GetIndexHint(annotations);
            IList<IndexHintInstruction> optionalIndexHintInstructions =
                indexHint != null ? indexHint.GetInstructionsFireAndForget() : null;
            return indexRepository.FindTable(keyNamesAvailable, rangeNamesAvailable, optionalIndexHintInstructions);
        }
Exemplo n.º 2
0
        public static ICollection<EventBean> Snapshot(
            QueryGraph filterQueryGraph,
            Attribute[] annotations,
            VirtualDWView virtualDataWindow,
            EventTableIndexRepository indexRepository,
            string objectName,
            AgentInstanceContext agentInstanceContext)
        {
            var queryGraphValue = filterQueryGraph == null
                ? null
                : filterQueryGraph.GetGraphValue(QueryGraphForge.SELF_STREAM, 0);
            if (queryGraphValue == null || queryGraphValue.Items.IsEmpty()) {
                if (virtualDataWindow != null) {
                    Pair<IndexMultiKey, EventTable> pair = VirtualDWQueryPlanUtil.GetFireAndForgetDesc(
                        virtualDataWindow.EventType,
                        new EmptySet<string>(),
                        new EmptySet<string>());
                    return virtualDataWindow.GetFireAndForgetData(
                        pair.Second,
                        CollectionUtil.OBJECTARRAY_EMPTY,
                        new RangeIndexLookupValue[0],
                        annotations);
                }

                return null;
            }

            // determine custom index
            var customResult = SnapshotCustomIndex(
                queryGraphValue,
                indexRepository,
                annotations,
                agentInstanceContext,
                objectName);
            if (customResult != null) {
                return customResult.Value;
            }

            // determine lookup based on hash-keys and ranges
            var keysAvailable = queryGraphValue.HashKeyProps;
            ISet<string> keyNamesAvailable = keysAvailable.Indexed.Length == 0
                ? (ISet<string>) new EmptySet<string>()
                : (ISet<string>) new HashSet<string>(keysAvailable.Indexed);
            var rangesAvailable = queryGraphValue.RangeProps;
            ISet<string> rangeNamesAvailable = rangesAvailable.Indexed.Length == 0
                ? (ISet<string>) new EmptySet<string>()
                : (ISet<string>) new HashSet<string>(rangesAvailable.Indexed);
            Pair<IndexMultiKey, EventTableAndNamePair> tablePair;

            // find index that matches the needs
            tablePair = FindIndex(
                keyNamesAvailable,
                rangeNamesAvailable,
                indexRepository,
                virtualDataWindow,
                annotations);

            // regular index lookup
            if (tablePair != null) {
                return SnapshotIndex(
                    keysAvailable,
                    rangesAvailable,
                    tablePair,
                    virtualDataWindow,
                    annotations,
                    agentInstanceContext,
                    objectName);
            }

            // in-keyword lookup
            var inkwResult = SnapshotInKeyword(
                queryGraphValue,
                indexRepository,
                virtualDataWindow,
                annotations,
                agentInstanceContext,
                objectName);
            if (inkwResult != null) {
                return inkwResult.Value;
            }

            QueryPlanReportTableScan(annotations, agentInstanceContext, objectName);
            return null;
        }