github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/logictest/testdata/logic_test/vectorize_threshold (about)

     1  # LogicTest: 5node
     2  
     3  # Disable automatic stats.
     4  statement ok
     5  SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false
     6  
     7  # Check that vectorize row count threshold is respected. The test relies on the
     8  # fact that DistSQL and vectorized execution engines output execution stats in
     9  # a different format.
    10  statement ok
    11  CREATE TABLE small (a INT PRIMARY KEY)
    12  
    13  statement ok
    14  SET vectorize_row_count_threshold = 1000
    15  
    16  # There are no stats available, so this should run through the row execution
    17  # engine.
    18  query TTT
    19  EXPLAIN SELECT count(*) from small
    20  ----
    21  ·          distributed  true
    22  ·          vectorized   false
    23  group      ·            ·
    24   │         aggregate 0  count_rows()
    25   │         scalar       ·
    26   └── scan  ·            ·
    27  ·          table        small@primary
    28  ·          spans        FULL SCAN
    29  
    30  statement ok
    31  SET vectorize_row_count_threshold = 0
    32  
    33  # This should run through the vectorized execution engine because we disabled
    34  # the threshold.
    35  query TTT
    36  EXPLAIN SELECT count(*) from small
    37  ----
    38  ·          distributed  true
    39  ·          vectorized   true
    40  group      ·            ·
    41   │         aggregate 0  count_rows()
    42   │         scalar       ·
    43   └── scan  ·            ·
    44  ·          table        small@primary
    45  ·          spans        FULL SCAN
    46  
    47  statement ok
    48  SET vectorize_row_count_threshold = 1000
    49  
    50  statement ok
    51  ALTER TABLE small INJECT STATISTICS '[
    52    {
    53      "columns": ["a"],
    54      "created_at": "2018-01-01 1:00:00.00000+00:00",
    55      "row_count": 100,
    56      "distinct_count": 100
    57    }
    58  ]'
    59  
    60  # This should run through the row execution engine.
    61  query TTT
    62  EXPLAIN SELECT count(*) from small
    63  ----
    64  ·          distributed  true
    65  ·          vectorized   false
    66  group      ·            ·
    67   │         aggregate 0  count_rows()
    68   │         scalar       ·
    69   └── scan  ·            ·
    70  ·          table        small@primary
    71  ·          spans        FULL SCAN
    72  
    73  statement ok
    74  SET vectorize_row_count_threshold = 1
    75  
    76  # This should run through the vectorized execution engine because we lowered
    77  # the threshold.
    78  query TTT
    79  EXPLAIN SELECT count(*) from small
    80  ----
    81  ·          distributed  true
    82  ·          vectorized   true
    83  group      ·            ·
    84   │         aggregate 0  count_rows()
    85   │         scalar       ·
    86   └── scan  ·            ·
    87  ·          table        small@primary
    88  ·          spans        FULL SCAN
    89  
    90  statement ok
    91  SET vectorize_row_count_threshold = 1000
    92  
    93  statement ok
    94  CREATE TABLE large (a INT PRIMARY KEY)
    95  
    96  statement ok
    97  ALTER TABLE large INJECT STATISTICS '[
    98    {
    99      "columns": ["a"],
   100      "created_at": "2018-01-01 1:00:00.00000+00:00",
   101      "row_count": 100000,
   102      "distinct_count": 100000
   103    }
   104  ]'
   105  
   106  # This should run through the vectorized execution engine.
   107  query TTT
   108  EXPLAIN SELECT count(*) from large
   109  ----
   110  ·          distributed  true
   111  ·          vectorized   true
   112  group      ·            ·
   113   │         aggregate 0  count_rows()
   114   │         scalar       ·
   115   └── scan  ·            ·
   116  ·          table        large@primary
   117  ·          spans        FULL SCAN
   118  
   119  statement ok
   120  SET vectorize_row_count_threshold = 1000000
   121  
   122  # This should run through the row execution engine because we increased the
   123  # threshold.
   124  query TTT
   125  EXPLAIN SELECT count(*) from large
   126  ----
   127  ·          distributed  true
   128  ·          vectorized   false
   129  group      ·            ·
   130   │         aggregate 0  count_rows()
   131   │         scalar       ·
   132   └── scan  ·            ·
   133  ·          table        large@primary
   134  ·          spans        FULL SCAN