• Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • ALL
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Description

      QueryPlanner::plan() rejects a collection scan under NO_TABLE_SCAN (the notablescan knob) only when the scan is required, i.e. no indexed plan exists. When the caller sets INCLUDE_COLLSCAN and an indexed plan exists, the unbounded collection scan is still output next to the indexed plans, and the ranker can choose it. This contradicts notablescan, which should forbid queries that perform a collection scan.

      Not affected:

      • STRICT_NO_TABLE_SCAN (set by query settings allowedIndexes without $natural): the collection scan block is skipped.
      • COLLECTION_EXCEEDS_SCAN_BYTES: it clears the collection scan request before the scan is built.

      Affected callers

      • Join optimization single-table access (single_table_access.cpp): sets INCLUDE_COLLSCAN when internalJoinEnumerateCollScanPlans is true, which is the default. Its planner params come from fillOutMainCollectionPlannerParams, which adds NO_TABLE_SCAN under notablescan. CBR can therefore choose a collection scan for a join fragment under notablescan.
      • SPM-4775 (CBR-only collection scan candidate) will hit the same path once its knob is enabled.

      No existing test covers notablescan with join optimization (query_knob_correctness_pbt.js excludes notablescan).

      Repro (planner unit test, passes on master)

      TEST_F(QueryPlannerTest, IncludeCollscanIgnoresNoTableScanWhenIndexedPlanExists) {
          params.mainCollectionInfo.options =
              QueryPlannerParams::NO_TABLE_SCAN | QueryPlannerParams::INCLUDE_COLLSCAN;
          addIndex(BSON("a" << 1));
      
          runQuery(fromjson("{a: 1}"));
      
          assertNumSolutions(2U);
          assertSolutionExists("{fetch: {filter: null, node: {ixscan: {pattern: {a: 1}}}}}");
          assertSolutionExists("{cscan: {dir: 1, filter: {a: 1}}}");
      }
      

      With NO_TABLE_SCAN alone, the same query yields only the indexed plan.

            Assignee:
            Unassigned
            Reporter:
            Daniel Tabacaru
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: