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

     1  # LogicTest: local
     2  
     3  # Check that node_statement_statistics report per application
     4  
     5  statement ok
     6  SET application_name = hello; SELECT 1
     7  
     8  statement ok
     9  SET application_name = world; SELECT 2
    10  
    11  query B
    12  SELECT count > 0 FROM crdb_internal.node_statement_statistics WHERE application_name IN ('hello', 'world')
    13  ----
    14  true
    15  true
    16  true
    17  
    18  # Check that node_statement_statistics report per statement
    19  
    20  statement ok
    21  SET application_name = hello; SELECT 1; SELECT 1,2; SELECT 1
    22  
    23  # reset for other tests.
    24  statement ok
    25  SET application_name = ''
    26  
    27  query TB
    28  SELECT key, count >= 1 FROM crdb_internal.node_statement_statistics WHERE application_name = 'hello' AND key LIKE 'SELECT%' ORDER BY key
    29  ----
    30  SELECT _    true
    31  SELECT _, _ true
    32  
    33  statement ok
    34  CREATE TABLE test(x INT, y INT, z INT); INSERT INTO test(x, y, z) VALUES (0,0,0);
    35  
    36  # Disable DistSQL for most statements, so that they don't get the "+" flag.
    37  statement ok
    38  SET distsql = off
    39  
    40  statement ok
    41  SET application_name = 'valuetest'
    42  
    43  # Check that shortening goes through functions.
    44  
    45  statement ok
    46  SELECT sin(1.23)
    47  
    48  # Check stats for query errors.
    49  statement error cannot take square root
    50  SELECT sqrt(-1.0)
    51  
    52  # Check that shortened queries can use virtual tables.
    53  
    54  statement ok
    55  SELECT key FROM test.crdb_internal.node_statement_statistics
    56  
    57  # Check that multi-value clauses are shortened.
    58  
    59  statement ok
    60  SELECT x FROM (VALUES (1,2,3), (4,5,6)) AS t(x)
    61  
    62  statement ok
    63  INSERT INTO test VALUES (1, 2, 3), (4, 5, 6)
    64  
    65  # Check that the RHS of IN comparisons are shortened.
    66  
    67  statement ok
    68  SELECT x FROM test WHERE y IN (4, 5, 6, 7, 8)
    69  
    70  statement ok
    71  SELECT x FROM test WHERE y NOT IN (4, 5, 6, 7, 8)
    72  
    73  # Check that a non-constant prevents shortening.
    74  
    75  statement ok
    76  SELECT x FROM test WHERE y IN (4, 5, 6+x, 7, 8)
    77  
    78  # Check that tuples in other positions are not shortened.
    79  
    80  statement ok
    81  SELECT ROW(1,2,3,4,5) FROM test WHERE FALSE
    82  
    83  # Make one query run in distsql mode to test the flag
    84  # and flag combinations
    85  
    86  statement ok
    87  set distsql = on
    88  
    89  statement ok
    90  SELECT x FROM test WHERE y IN (4, 5, 6, 7, 8)
    91  
    92  statement error division by zero
    93  SELECT x FROM test WHERE y = 1/z
    94  
    95  # Set a cluster setting to make it show up below. Which one is set
    96  # does not matter.
    97  statement ok
    98  SET CLUSTER SETTING debug.panic_on_failed_assertions = true; RESET CLUSTER SETTING debug.panic_on_failed_assertions
    99  
   100  statement ok
   101  SHOW application_name
   102  
   103  statement ok
   104  SHOW CLUSTER SETTING debug.panic_on_failed_assertions
   105  
   106  statement ok
   107  SET application_name = ''; RESET distsql
   108  
   109  query TT colnames
   110  SELECT key,flags
   111    FROM test.crdb_internal.node_statement_statistics
   112   WHERE application_name = 'valuetest' ORDER BY key, flags
   113  ----
   114  key                                                               flags
   115  INSERT INTO test VALUES (_, _, __more1__), (__more1__)            ·
   116  SELECT (_, _, __more3__) FROM test WHERE _                        ·
   117  SELECT key FROM test.crdb_internal.node_statement_statistics      ·
   118  SELECT sin(_)                                                     ·
   119  SELECT sqrt(_)                                                    !
   120  SELECT x FROM (VALUES (_, _, __more1__), (__more1__)) AS t (x)    ·
   121  SELECT x FROM test WHERE y = (_ / z)                              !+
   122  SELECT x FROM test WHERE y IN (_, _, _ + x, _, _)                 ·
   123  SELECT x FROM test WHERE y IN (_, _, __more3__)                   ·
   124  SELECT x FROM test WHERE y IN (_, _, __more3__)                   +
   125  SELECT x FROM test WHERE y NOT IN (_, _, __more3__)               ·
   126  SET CLUSTER SETTING "debug.panic_on_failed_assertions" = DEFAULT  ·
   127  SET CLUSTER SETTING "debug.panic_on_failed_assertions" = _        ·
   128  SET application_name = _                                          ·
   129  SET distsql = "on"                                                ·
   130  SHOW CLUSTER SETTING "debug.panic_on_failed_assertions"           ·
   131  SHOW application_name                                             ·
   132  
   133  # Check that names are anonymized properly:
   134  # - virtual table names are preserved, but not the db prefix (#22700)
   135  # - function names are preserved
   136  query T
   137  SELECT anonymized
   138    FROM test.crdb_internal.node_statement_statistics
   139   WHERE application_name = 'valuetest' ORDER BY key
   140  ----
   141  INSERT INTO _ VALUES (_, _, __more1__), (__more1__)
   142  SELECT (_, _, __more3__) FROM _ WHERE _
   143  SELECT _ FROM _.crdb_internal.node_statement_statistics
   144  SELECT sin(_)
   145  SELECT sqrt(_)
   146  SELECT _ FROM (VALUES (_, _, __more1__), (__more1__)) AS _ (_)
   147  SELECT _ FROM _ WHERE _ = (_ / _)
   148  SELECT _ FROM _ WHERE _ IN (_, _, _ + _, _, _)
   149  SELECT _ FROM _ WHERE _ IN (_, _, __more3__)
   150  SELECT _ FROM _ WHERE _ IN (_, _, __more3__)
   151  SELECT _ FROM _ WHERE _ NOT IN (_, _, __more3__)
   152  SET CLUSTER SETTING "debug.panic_on_failed_assertions" = DEFAULT
   153  SET CLUSTER SETTING "debug.panic_on_failed_assertions" = _
   154  SET application_name = _
   155  SET distsql = _
   156  SHOW CLUSTER SETTING "debug.panic_on_failed_assertions"
   157  SHOW application_name
   158  
   159  # Check that the latency measurements looks reasonable, protecting
   160  # against failure to measure (#22877).
   161  
   162  # We use the keys left over by the two unary selects
   163  # performed at the start of this test above.
   164  #
   165  # The latency metrics are expressed in seconds. Check that some time
   166  # was consumed, but not so much to verify that the computation has not
   167  # incorrectly overflowed.
   168  query TBBBBB colnames
   169  SELECT key,
   170         service_lat_avg > 0 and service_lat_avg < 10 as svc_ok,
   171         parse_lat_avg > 0   and parse_lat_avg < 10   as parse_ok,
   172         plan_lat_avg > 0    and plan_lat_avg < 10    as plan_ok,
   173         run_lat_avg > 0     and run_lat_avg < 10     as run_ok,
   174                             overhead_lat_avg < 10    as ovh_ok
   175    FROM crdb_internal.node_statement_statistics
   176   WHERE key = 'SELECT _'
   177  ----
   178  key       svc_ok  parse_ok  plan_ok  run_ok  ovh_ok
   179  SELECT _  true    true      true     true    true
   180  SELECT _  true    true      true     true    true
   181  
   182  # Check that statements made in implicit transactions are separated from those
   183  # that are not.
   184  
   185  statement ok
   186  SET application_name = 'implicit_txn_test'
   187  
   188  statement ok
   189  BEGIN; SELECT x FROM test where y=1; COMMIT;
   190  
   191  statement ok
   192  BEGIN;
   193  SELECT x, z FROM test;
   194  SELECT x FROM test where y=1;
   195  COMMIT;
   196  
   197  statement ok
   198  SELECT z FROM test where y=2;
   199  
   200  statement ok
   201  SELECT x FROM test where y=1;
   202  
   203  query TB colnames rowsort
   204  SELECT key, implicit_txn
   205    FROM crdb_internal.node_statement_statistics
   206   WHERE application_name = 'implicit_txn_test' ORDER BY key, implicit_txn;
   207  ----
   208  key                             implicit_txn
   209  SELECT x FROM test WHERE y = _  false
   210  SELECT x FROM test WHERE y = _  true
   211  SELECT x, z FROM test           false
   212  SELECT z FROM test WHERE y = _  true