diff --git a/mysql-test/r/mysqld--help-notwin.result b/mysql-test/r/mysqld--help-notwin.result index df093e59a17e..c023aa2ecee8 100644 --- a/mysql-test/r/mysqld--help-notwin.result +++ b/mysql-test/r/mysqld--help-notwin.result @@ -1812,6 +1812,17 @@ The following options may be given as the first argument: --rocksdb-seconds-between-stat-computes=# Sets a number of seconds to wait between optimizer stats recomputation. Only changed indexes will be refreshed. + --rocksdb-select-bypass-fail-unsupported + Select bypass would fail for unsupported SELECT commands + (Defaults to on; use --skip-rocksdb-select-bypass-fail-unsupported to disable.) + --rocksdb-select-bypass-log-failed + Log failed SELECT bypass queries + --rocksdb-select-bypass-log-rejected + Log rejected SELECT bypass queries + (Defaults to on; use --skip-rocksdb-select-bypass-log-rejected to disable.) + --rocksdb-select-bypass-policy=# + Change bypass SELECT related policy and allow directly + talk to RocksDB --rocksdb-signal-drop-index-thread Wake up drop index thread --rocksdb-sim-cache-size=# @@ -2820,6 +2831,10 @@ rocksdb-records-in-range 0 rocksdb-reset-stats FALSE rocksdb-rollback-on-timeout FALSE rocksdb-seconds-between-stat-computes 3600 +rocksdb-select-bypass-fail-unsupported TRUE +rocksdb-select-bypass-log-failed FALSE +rocksdb-select-bypass-log-rejected TRUE +rocksdb-select-bypass-policy 0 rocksdb-signal-drop-index-thread FALSE rocksdb-sim-cache-size 0 rocksdb-skip-bloom-filter-on-read FALSE diff --git a/mysql-test/suite/rocksdb/r/bypass_select_basic.result b/mysql-test/suite/rocksdb/r/bypass_select_basic.result index ac9100c03472..3467ddbd92e4 100644 --- a/mysql-test/suite/rocksdb/r/bypass_select_basic.result +++ b/mysql-test/suite/rocksdb/r/bypass_select_basic.result @@ -329,445 +329,470 @@ insert into link_table4 values ('a1', "rk4", 5, 2, 1, 1, 'data15', 1, 1); insert into link_table4 values ('b1', "rk5", 1, 2, 1, 1, 'data21', 1, 1); insert into link_table4 values ('b1', "rk6", 2, 2, 1, 1, 'data22', 1, 1); insert into link_table4 values ('b1', "rk7", 3, 2, 1, 1, 'data32', 1, 1); -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +# Default +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +0 +SELECT @@rocksdb_select_bypass_policy INTO @save_rocksdb_select_bypass_policy; +# Always off +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +0 +SET GLOBAL rocksdb_select_bypass_policy=0; +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +0 +SELECT variable_value INTO @a FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -SELECT /*+ no_bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +SELECT /*+ no_bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -SELECT id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -id1 id2 id1_type id2_type data version -1 2 1 2 a10 125 -SELECT /*+bypassabc*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +SELECT id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 +SELECT variable_value INTO @b FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +# Should be 0 +SELECT @b-@a; +@b-@a +0 +# Always on +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +0 +SET GLOBAL rocksdb_select_bypass_policy=1; +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +1 +SELECT variable_value INTO @a FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +SELECT /*+ abc */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } Warnings: -Warning 1064 Optimizer hint syntax error near 'bypassabc*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 a' at line 1 -SELECT /*+bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -id1 id2 id1_type id2_type data version -1 2 1 2 a10 125 +Warning 1064 Optimizer hint syntax error near 'abc */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id' at line 1 +SELECT /*+ no_bypass*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } Warnings: -Warning 1064 Optimizer hint syntax error near 'bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and' at line 1 -SELECT /* +bypassabc*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +Warning 1064 Optimizer hint syntax error near 'no_bypass*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 A' at line 1 +SELECT id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +SELECT variable_value INTO @b FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +# Should be 4 +SELECT @b-@a; +@b-@a +4 +# Opt-in +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +1 +SET GLOBAL rocksdb_select_bypass_policy=2; +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +2 +SELECT variable_value into @a FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +SELECT /*+ no_bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -SELECT /*aaaaaaaaabbbbbbbbb*/ id1,id2,id1_type,id2_type,data,version -from link_table WHERE id1=1 and id2=2 and link_type=3; +SELECT id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -SELECT /*+*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +SELECT /*+bypassabc*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 Warnings: -Warning 1064 Optimizer hint syntax error near '*/' at line 1 -SELECT /*+b*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +Warning 1064 Optimizer hint syntax error near 'bypassabc*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 A' at line 1 +SELECT /*+bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 Warnings: -Warning 1064 Optimizer hint syntax error near 'b*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2' at line 1 -SELECT /*+byp*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +Warning 1064 Optimizer hint syntax error near 'bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND' at line 1 +SELECT /*+ bypass*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 Warnings: -Warning 1064 Optimizer hint syntax error near 'byp*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2' at line 1 -SELECT /*+bypw*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +Warning 1064 Optimizer hint syntax error near 'bypass*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND ' at line 1 +SELECT /* +bypassabc*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -Warnings: -Warning 1064 Optimizer hint syntax error near 'bypw*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id' at line 1 -SELECT /*-b*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +SELECT /*aaaaaaaaabbbbbbbbb*/ id1,id2,id1_type,id2_type,data,version +FROM link_table WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -SELECT /**/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +SELECT /*+*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -# Point query -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +Warnings: +Warning 1064 Optimizer hint syntax error near '*/' at line 1 +SELECT /*+b*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +id1 id2 id1_type id2_type data version +1 2 1 2 a10 125 +Warnings: +Warning 1064 Optimizer hint syntax error near 'b*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2' at line 1 +SELECT /*+byp*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2 IN (2, 3, 4) and link_type=3; +Warnings: +Warning 1064 Optimizer hint syntax error near 'byp*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2' at line 1 +SELECT /*+bypw*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -1 3 1 2 a11 125 -1 4 1 2 a11 125 -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2 IN (2) and link_type=3; +Warnings: +Warning 1064 Optimizer hint syntax error near 'bypw*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id' at line 1 +SELECT /*-b*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1 IN (1) and id2 IN (2) and link_type=3; +SELECT /**/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1 IN (1, 2) and id2 IN (2, 3, 4) and link_type=3; +SELECT variable_value INTO @b FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +# Should be 1 +SELECT @b-@a; +@b-@a +1 +# Opt-out +select @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +2 +set global rocksdb_select_bypass_policy=3; +select @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +3 +SELECT variable_value INTO @a FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +SELECT /*+bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +Warnings: +Warning 1064 Optimizer hint syntax error near 'bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND' at line 1 +SELECT /*+*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +Warnings: +Warning 1064 Optimizer hint syntax error near '*/' at line 1 +SELECT id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +SELECT variable_value INTO @b FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +# Should be 4 +SELECT @b-@a; +@b-@a +4 +SELECT /*+ no_bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -1 3 1 2 a11 125 -1 4 1 2 a11 125 -2 2 1 2 a10 125 -2 3 1 2 a11 125 -2 4 1 2 a11 125 +SELECT /*+ no_bypass*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +Warnings: +Warning 1064 Optimizer hint syntax error near 'no_bypass*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 A' at line 1 +SELECT /*+no_bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +Warnings: +Warning 1064 Optimizer hint syntax error near 'no_bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 ' at line 1 +SELECT /*+no_bypassabc */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +Warnings: +Warning 1064 Optimizer hint syntax error near 'no_bypassabc */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1' at line 1 +SELECT variable_value INTO @c FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +# Should be 3 +SELECT @c-@b; +@c-@b +3 +# Point query +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2 IN (2, 3, 4) AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 IN (2,3,4)), (link_type == 3) } +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2 IN (2) AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1 IN (1) AND id2 IN (2) AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1 IN (1, 2) AND id2 IN (2, 3, 4) AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 IN (1,2)), (id2 IN (2,3,4)), (link_type == 3) } # Prefix range query # Prefix range query with SK SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 3 AND time = 10 ORDER BY TIME DESC LIMIT 10; -id1 id2 link_type visibility data time version -1 2 3 3 a10 10 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 3), (time == 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 3 AND time = 10 ORDER BY TIME ASC LIMIT 10; -id1 id2 link_type visibility data time version -1 2 3 3 a10 10 125 +Dump +Index=1, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 3), (time == 10) } # Prefix range query with SK with limits SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC; -id1 id2 link_type visibility data time version -1 10 3 4 a15 15 125 -1 9 3 4 a14 14 125 -1 8 3 4 a13 13 125 -1 7 3 4 a12 12 125 -1 6 3 4 a12 12 125 -1 4 3 4 a11 11 125 -1 3 3 4 a11 11 125 -1 1 3 4 a10 10 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 10; -id1 id2 link_type visibility data time version -1 10 3 4 a15 15 125 -1 9 3 4 a14 14 125 -1 8 3 4 a13 13 125 -1 7 3 4 a12 12 125 -1 6 3 4 a12 12 125 -1 4 3 4 a11 11 125 -1 3 3 4 a11 11 125 -1 1 3 4 a10 10 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 5; -id1 id2 link_type visibility data time version -1 10 3 4 a15 15 125 -1 9 3 4 a14 14 125 -1 8 3 4 a13 13 125 -1 7 3 4 a12 12 125 -1 6 3 4 a12 12 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 1; -id1 id2 link_type visibility data time version -1 10 3 4 a15 15 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 0; -id1 id2 link_type visibility data time version +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 0,10; -id1 id2 link_type visibility data time version -1 10 3 4 a15 15 125 -1 9 3 4 a14 14 125 -1 8 3 4 a13 13 125 -1 7 3 4 a12 12 125 -1 6 3 4 a12 12 125 -1 4 3 4 a11 11 125 -1 3 3 4 a11 11 125 -1 1 3 4 a10 10 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 0,5; -id1 id2 link_type visibility data time version -1 10 3 4 a15 15 125 -1 9 3 4 a14 14 125 -1 8 3 4 a13 13 125 -1 7 3 4 a12 12 125 -1 6 3 4 a12 12 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 0,1; -id1 id2 link_type visibility data time version -1 10 3 4 a15 15 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 1,0; -id1 id2 link_type visibility data time version +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 1,10; -id1 id2 link_type visibility data time version -1 9 3 4 a14 14 125 -1 8 3 4 a13 13 125 -1 7 3 4 a12 12 125 -1 6 3 4 a12 12 125 -1 4 3 4 a11 11 125 -1 3 3 4 a11 11 125 -1 1 3 4 a10 10 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 1,5; -id1 id2 link_type visibility data time version -1 9 3 4 a14 14 125 -1 8 3 4 a13 13 125 -1 7 3 4 a12 12 125 -1 6 3 4 a12 12 125 -1 4 3 4 a11 11 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 1,1; -id1 id2 link_type visibility data time version -1 9 3 4 a14 14 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 1,0; -id1 id2 link_type visibility data time version +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 5,10; -id1 id2 link_type visibility data time version -1 4 3 4 a11 11 125 -1 3 3 4 a11 11 125 -1 1 3 4 a10 10 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 5,5; -id1 id2 link_type visibility data time version -1 4 3 4 a11 11 125 -1 3 3 4 a11 11 125 -1 1 3 4 a10 10 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 5,1; -id1 id2 link_type visibility data time version -1 4 3 4 a11 11 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 5,0; -id1 id2 link_type visibility data time version +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 10,10; -id1 id2 link_type visibility data time version +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 10,5; -id1 id2 link_type visibility data time version +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 10,1; -id1 id2 link_type visibility data time version +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 10,0; -id1 id2 link_type visibility data time version +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } # Prefix range query with PK SELECT /*+ bypass */ id1, id2, link_type FROM link_table FORCE INDEX (PRIMARY) -WHERE link_type=3 and id1=1 ORDER BY id2 DESC; -id1 id2 link_type -1 10 3 -1 9 3 -1 8 3 -1 7 3 -1 6 3 -1 5 3 -1 4 3 -1 3 3 -1 2 3 -1 1 3 +WHERE link_type=3 AND id1=1 ORDER BY id2 DESC; +Dump +Index=0, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4) }, Cond={ (link_type == 3), (id1 == 1) } SELECT /*+ bypass */ id1, id2, link_type FROM link_table FORCE INDEX (PRIMARY) -WHERE link_type=3 and id1=1 ORDER BY id2 ASC; -id1 id2 link_type -1 1 3 -1 2 3 -1 3 3 -1 4 3 -1 5 3 -1 6 3 -1 7 3 -1 8 3 -1 9 3 -1 10 3 +WHERE link_type=3 AND id1=1 ORDER BY id2 ASC; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4) }, Cond={ (link_type == 3), (id1 == 1) } # Prefix range query with PK + value SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (PRIMARY) -WHERE link_type=3 and id1=1 ORDER BY id2 DESC; -id1 id2 link_type visibility data time version -1 10 3 4 a15 15 125 -1 9 3 4 a14 14 125 -1 8 3 4 a13 13 125 -1 7 3 4 a12 12 125 -1 6 3 4 a12 12 125 -1 5 3 3 a12 12 125 -1 4 3 4 a11 11 125 -1 3 3 4 a11 11 125 -1 2 3 3 a10 10 125 -1 1 3 4 a10 10 125 +WHERE link_type=3 AND id1=1 ORDER BY id2 DESC; +Dump +Index=0, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (PRIMARY) -WHERE link_type=3 and id1=1 ORDER BY id2 ASC; -id1 id2 link_type visibility data time version -1 1 3 4 a10 10 125 -1 2 3 3 a10 10 125 -1 3 3 4 a11 11 125 -1 4 3 4 a11 11 125 -1 5 3 3 a12 12 125 -1 6 3 4 a12 12 125 -1 7 3 4 a12 12 125 -1 8 3 4 a13 13 125 -1 9 3 4 a14 14 125 -1 10 3 4 a15 15 125 +WHERE link_type=3 AND id1=1 ORDER BY id2 ASC; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1) } # Transaction BEGIN; -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -id1 id2 id1_type id2_type data version -1 2 1 2 a10 125 -UPDATE link_table set data="bcd" WHERE id1=1 and id2=2 and link_type = 3; -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -id1 id2 id1_type id2_type data version -1 2 1 2 bcd 125 +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +UPDATE link_table set data="bcd" WHERE id1=1 AND id2=2 AND link_type = 3; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } COMMIT; BEGIN; -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -id1 id2 id1_type id2_type data version -1 2 1 2 bcd 125 -UPDATE link_table set data="cde" WHERE id1=1 and id2=2 and link_type = 3; -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -id1 id2 id1_type id2_type data version -1 2 1 2 cde 125 +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +UPDATE link_table set data="cde" WHERE id1=1 AND id2=2 AND link_type = 3; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } ROLLBACK; -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -id1 id2 id1_type id2_type data version -1 2 1 2 bcd 125 +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } # Data types SELECT /*+ bypass */ id1 FROM link_table where link_type="3"; -id1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0) }, Cond={ (link_type == 3) } SELECT /*+ bypass */ id1 FROM link_table where link_type="3" AND id1="1"; -id1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0) }, Cond={ (link_type == 3), (id1 == 1) } SELECT /*+ bypass */ id1 FROM link_table where link_type="3" AND id1=True; -id1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0) }, Cond={ (link_type == 3), (id1 == 1) } SELECT /*+ bypass */ id1 FROM link_table where link_type="3" AND id1=b'1'; -id1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -SELECT /*+ bypass */ id1 FROM link_table where link_type="3" AND id1=x'01'; -id1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0) }, Cond={ (link_type == 3), (id1 == 1) } +SELECT /*+ bypass */ id1 FROM link_table where link_type="3" AND id1=x'61'; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0) }, Cond={ (link_type == 3), (id1 == 97) } SELECT /*+ bypass */ id1 FROM link_table where link_type="3" AND id1=NULL; -id1 +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0) }, Cond={ (link_type == 3), (id1 == NULL) } +# Full table scan +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1_type=1; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1_type == 1) } DROP TABLE count_table; DROP TABLE link_table; DROP TABLE link_table3; @@ -777,3 +802,10 @@ DROP TABLE node_table; DROP TABLE link_table5; DROP TABLE link_table6; DROP TABLE link_table4; +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +3 +set global rocksdb_select_bypass_policy=@save_rocksdb_select_bypass_policy; +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +0 diff --git a/mysql-test/suite/rocksdb/r/bypass_select_basic_bloom.result b/mysql-test/suite/rocksdb/r/bypass_select_basic_bloom.result index ac9100c03472..3467ddbd92e4 100644 --- a/mysql-test/suite/rocksdb/r/bypass_select_basic_bloom.result +++ b/mysql-test/suite/rocksdb/r/bypass_select_basic_bloom.result @@ -329,445 +329,470 @@ insert into link_table4 values ('a1', "rk4", 5, 2, 1, 1, 'data15', 1, 1); insert into link_table4 values ('b1', "rk5", 1, 2, 1, 1, 'data21', 1, 1); insert into link_table4 values ('b1', "rk6", 2, 2, 1, 1, 'data22', 1, 1); insert into link_table4 values ('b1', "rk7", 3, 2, 1, 1, 'data32', 1, 1); -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +# Default +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +0 +SELECT @@rocksdb_select_bypass_policy INTO @save_rocksdb_select_bypass_policy; +# Always off +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +0 +SET GLOBAL rocksdb_select_bypass_policy=0; +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +0 +SELECT variable_value INTO @a FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -SELECT /*+ no_bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +SELECT /*+ no_bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -SELECT id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -id1 id2 id1_type id2_type data version -1 2 1 2 a10 125 -SELECT /*+bypassabc*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +SELECT id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 +SELECT variable_value INTO @b FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +# Should be 0 +SELECT @b-@a; +@b-@a +0 +# Always on +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +0 +SET GLOBAL rocksdb_select_bypass_policy=1; +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +1 +SELECT variable_value INTO @a FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +SELECT /*+ abc */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } Warnings: -Warning 1064 Optimizer hint syntax error near 'bypassabc*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 a' at line 1 -SELECT /*+bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -id1 id2 id1_type id2_type data version -1 2 1 2 a10 125 +Warning 1064 Optimizer hint syntax error near 'abc */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id' at line 1 +SELECT /*+ no_bypass*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } Warnings: -Warning 1064 Optimizer hint syntax error near 'bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and' at line 1 -SELECT /* +bypassabc*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +Warning 1064 Optimizer hint syntax error near 'no_bypass*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 A' at line 1 +SELECT id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +SELECT variable_value INTO @b FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +# Should be 4 +SELECT @b-@a; +@b-@a +4 +# Opt-in +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +1 +SET GLOBAL rocksdb_select_bypass_policy=2; +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +2 +SELECT variable_value into @a FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +SELECT /*+ no_bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -SELECT /*aaaaaaaaabbbbbbbbb*/ id1,id2,id1_type,id2_type,data,version -from link_table WHERE id1=1 and id2=2 and link_type=3; +SELECT id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -SELECT /*+*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +SELECT /*+bypassabc*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 Warnings: -Warning 1064 Optimizer hint syntax error near '*/' at line 1 -SELECT /*+b*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +Warning 1064 Optimizer hint syntax error near 'bypassabc*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 A' at line 1 +SELECT /*+bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 Warnings: -Warning 1064 Optimizer hint syntax error near 'b*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2' at line 1 -SELECT /*+byp*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +Warning 1064 Optimizer hint syntax error near 'bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND' at line 1 +SELECT /*+ bypass*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 Warnings: -Warning 1064 Optimizer hint syntax error near 'byp*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2' at line 1 -SELECT /*+bypw*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +Warning 1064 Optimizer hint syntax error near 'bypass*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND ' at line 1 +SELECT /* +bypassabc*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -Warnings: -Warning 1064 Optimizer hint syntax error near 'bypw*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id' at line 1 -SELECT /*-b*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +SELECT /*aaaaaaaaabbbbbbbbb*/ id1,id2,id1_type,id2_type,data,version +FROM link_table WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -SELECT /**/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +SELECT /*+*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -# Point query -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +Warnings: +Warning 1064 Optimizer hint syntax error near '*/' at line 1 +SELECT /*+b*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +id1 id2 id1_type id2_type data version +1 2 1 2 a10 125 +Warnings: +Warning 1064 Optimizer hint syntax error near 'b*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2' at line 1 +SELECT /*+byp*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2 IN (2, 3, 4) and link_type=3; +Warnings: +Warning 1064 Optimizer hint syntax error near 'byp*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2' at line 1 +SELECT /*+bypw*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -1 3 1 2 a11 125 -1 4 1 2 a11 125 -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2 IN (2) and link_type=3; +Warnings: +Warning 1064 Optimizer hint syntax error near 'bypw*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id' at line 1 +SELECT /*-b*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1 IN (1) and id2 IN (2) and link_type=3; +SELECT /**/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1 IN (1, 2) and id2 IN (2, 3, 4) and link_type=3; +SELECT variable_value INTO @b FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +# Should be 1 +SELECT @b-@a; +@b-@a +1 +# Opt-out +select @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +2 +set global rocksdb_select_bypass_policy=3; +select @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +3 +SELECT variable_value INTO @a FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +SELECT /*+bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +Warnings: +Warning 1064 Optimizer hint syntax error near 'bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND' at line 1 +SELECT /*+*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +Warnings: +Warning 1064 Optimizer hint syntax error near '*/' at line 1 +SELECT id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +SELECT variable_value INTO @b FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +# Should be 4 +SELECT @b-@a; +@b-@a +4 +SELECT /*+ no_bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; id1 id2 id1_type id2_type data version 1 2 1 2 a10 125 -1 3 1 2 a11 125 -1 4 1 2 a11 125 -2 2 1 2 a10 125 -2 3 1 2 a11 125 -2 4 1 2 a11 125 +SELECT /*+ no_bypass*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +Warnings: +Warning 1064 Optimizer hint syntax error near 'no_bypass*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 A' at line 1 +SELECT /*+no_bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +Warnings: +Warning 1064 Optimizer hint syntax error near 'no_bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 ' at line 1 +SELECT /*+no_bypassabc */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +Warnings: +Warning 1064 Optimizer hint syntax error near 'no_bypassabc */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1' at line 1 +SELECT variable_value INTO @c FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +# Should be 3 +SELECT @c-@b; +@c-@b +3 +# Point query +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2 IN (2, 3, 4) AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 IN (2,3,4)), (link_type == 3) } +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2 IN (2) AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1 IN (1) AND id2 IN (2) AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1 IN (1, 2) AND id2 IN (2, 3, 4) AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 IN (1,2)), (id2 IN (2,3,4)), (link_type == 3) } # Prefix range query # Prefix range query with SK SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 3 AND time = 10 ORDER BY TIME DESC LIMIT 10; -id1 id2 link_type visibility data time version -1 2 3 3 a10 10 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 3), (time == 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 3 AND time = 10 ORDER BY TIME ASC LIMIT 10; -id1 id2 link_type visibility data time version -1 2 3 3 a10 10 125 +Dump +Index=1, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 3), (time == 10) } # Prefix range query with SK with limits SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC; -id1 id2 link_type visibility data time version -1 10 3 4 a15 15 125 -1 9 3 4 a14 14 125 -1 8 3 4 a13 13 125 -1 7 3 4 a12 12 125 -1 6 3 4 a12 12 125 -1 4 3 4 a11 11 125 -1 3 3 4 a11 11 125 -1 1 3 4 a10 10 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 10; -id1 id2 link_type visibility data time version -1 10 3 4 a15 15 125 -1 9 3 4 a14 14 125 -1 8 3 4 a13 13 125 -1 7 3 4 a12 12 125 -1 6 3 4 a12 12 125 -1 4 3 4 a11 11 125 -1 3 3 4 a11 11 125 -1 1 3 4 a10 10 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 5; -id1 id2 link_type visibility data time version -1 10 3 4 a15 15 125 -1 9 3 4 a14 14 125 -1 8 3 4 a13 13 125 -1 7 3 4 a12 12 125 -1 6 3 4 a12 12 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 1; -id1 id2 link_type visibility data time version -1 10 3 4 a15 15 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 0; -id1 id2 link_type visibility data time version +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 0,10; -id1 id2 link_type visibility data time version -1 10 3 4 a15 15 125 -1 9 3 4 a14 14 125 -1 8 3 4 a13 13 125 -1 7 3 4 a12 12 125 -1 6 3 4 a12 12 125 -1 4 3 4 a11 11 125 -1 3 3 4 a11 11 125 -1 1 3 4 a10 10 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 0,5; -id1 id2 link_type visibility data time version -1 10 3 4 a15 15 125 -1 9 3 4 a14 14 125 -1 8 3 4 a13 13 125 -1 7 3 4 a12 12 125 -1 6 3 4 a12 12 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 0,1; -id1 id2 link_type visibility data time version -1 10 3 4 a15 15 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 1,0; -id1 id2 link_type visibility data time version +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 1,10; -id1 id2 link_type visibility data time version -1 9 3 4 a14 14 125 -1 8 3 4 a13 13 125 -1 7 3 4 a12 12 125 -1 6 3 4 a12 12 125 -1 4 3 4 a11 11 125 -1 3 3 4 a11 11 125 -1 1 3 4 a10 10 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 1,5; -id1 id2 link_type visibility data time version -1 9 3 4 a14 14 125 -1 8 3 4 a13 13 125 -1 7 3 4 a12 12 125 -1 6 3 4 a12 12 125 -1 4 3 4 a11 11 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 1,1; -id1 id2 link_type visibility data time version -1 9 3 4 a14 14 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 1,0; -id1 id2 link_type visibility data time version +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 5,10; -id1 id2 link_type visibility data time version -1 4 3 4 a11 11 125 -1 3 3 4 a11 11 125 -1 1 3 4 a10 10 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 5,5; -id1 id2 link_type visibility data time version -1 4 3 4 a11 11 125 -1 3 3 4 a11 11 125 -1 1 3 4 a10 10 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 5,1; -id1 id2 link_type visibility data time version -1 4 3 4 a11 11 125 +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 5,0; -id1 id2 link_type visibility data time version +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 10,10; -id1 id2 link_type visibility data time version +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 10,5; -id1 id2 link_type visibility data time version +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 10,1; -id1 id2 link_type visibility data time version +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (id1_type) WHERE link_type = 3 AND id1 = 1 AND visibility = 4 AND time >= 10 ORDER BY TIME DESC LIMIT 10,0; -id1 id2 link_type visibility data time version +Dump +Index=1, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1), (visibility == 4), (time >= 10) } # Prefix range query with PK SELECT /*+ bypass */ id1, id2, link_type FROM link_table FORCE INDEX (PRIMARY) -WHERE link_type=3 and id1=1 ORDER BY id2 DESC; -id1 id2 link_type -1 10 3 -1 9 3 -1 8 3 -1 7 3 -1 6 3 -1 5 3 -1 4 3 -1 3 3 -1 2 3 -1 1 3 +WHERE link_type=3 AND id1=1 ORDER BY id2 DESC; +Dump +Index=0, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4) }, Cond={ (link_type == 3), (id1 == 1) } SELECT /*+ bypass */ id1, id2, link_type FROM link_table FORCE INDEX (PRIMARY) -WHERE link_type=3 and id1=1 ORDER BY id2 ASC; -id1 id2 link_type -1 1 3 -1 2 3 -1 3 3 -1 4 3 -1 5 3 -1 6 3 -1 7 3 -1 8 3 -1 9 3 -1 10 3 +WHERE link_type=3 AND id1=1 ORDER BY id2 ASC; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4) }, Cond={ (link_type == 3), (id1 == 1) } # Prefix range query with PK + value SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (PRIMARY) -WHERE link_type=3 and id1=1 ORDER BY id2 DESC; -id1 id2 link_type visibility data time version -1 10 3 4 a15 15 125 -1 9 3 4 a14 14 125 -1 8 3 4 a13 13 125 -1 7 3 4 a12 12 125 -1 6 3 4 a12 12 125 -1 5 3 3 a12 12 125 -1 4 3 4 a11 11 125 -1 3 3 4 a11 11 125 -1 2 3 3 a10 10 125 -1 1 3 4 a10 10 125 +WHERE link_type=3 AND id1=1 ORDER BY id2 DESC; +Dump +Index=0, Order=DESC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1) } SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (PRIMARY) -WHERE link_type=3 and id1=1 ORDER BY id2 ASC; -id1 id2 link_type visibility data time version -1 1 3 4 a10 10 125 -1 2 3 3 a10 10 125 -1 3 3 4 a11 11 125 -1 4 3 4 a11 11 125 -1 5 3 3 a12 12 125 -1 6 3 4 a12 12 125 -1 7 3 4 a12 12 125 -1 8 3 4 a13 13 125 -1 9 3 4 a14 14 125 -1 10 3 4 a15 15 125 +WHERE link_type=3 AND id1=1 ORDER BY id2 ASC; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=link_type, Index=4), (Name=visibility, Index=5), (Name=data, Index=6), (Name=time, Index=7), (Name=version, Index=8) }, Cond={ (link_type == 3), (id1 == 1) } # Transaction BEGIN; -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -id1 id2 id1_type id2_type data version -1 2 1 2 a10 125 -UPDATE link_table set data="bcd" WHERE id1=1 and id2=2 and link_type = 3; -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -id1 id2 id1_type id2_type data version -1 2 1 2 bcd 125 +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +UPDATE link_table set data="bcd" WHERE id1=1 AND id2=2 AND link_type = 3; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } COMMIT; BEGIN; -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -id1 id2 id1_type id2_type data version -1 2 1 2 bcd 125 -UPDATE link_table set data="cde" WHERE id1=1 and id2=2 and link_type = 3; -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -id1 id2 id1_type id2_type data version -1 2 1 2 cde 125 +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } +UPDATE link_table set data="cde" WHERE id1=1 AND id2=2 AND link_type = 3; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } ROLLBACK; -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -id1 id2 id1_type id2_type data version -1 2 1 2 bcd 125 +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1 == 1), (id2 == 2), (link_type == 3) } # Data types SELECT /*+ bypass */ id1 FROM link_table where link_type="3"; -id1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0) }, Cond={ (link_type == 3) } SELECT /*+ bypass */ id1 FROM link_table where link_type="3" AND id1="1"; -id1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0) }, Cond={ (link_type == 3), (id1 == 1) } SELECT /*+ bypass */ id1 FROM link_table where link_type="3" AND id1=True; -id1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0) }, Cond={ (link_type == 3), (id1 == 1) } SELECT /*+ bypass */ id1 FROM link_table where link_type="3" AND id1=b'1'; -id1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -SELECT /*+ bypass */ id1 FROM link_table where link_type="3" AND id1=x'01'; -id1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0) }, Cond={ (link_type == 3), (id1 == 1) } +SELECT /*+ bypass */ id1 FROM link_table where link_type="3" AND id1=x'61'; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0) }, Cond={ (link_type == 3), (id1 == 97) } SELECT /*+ bypass */ id1 FROM link_table where link_type="3" AND id1=NULL; -id1 +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0) }, Cond={ (link_type == 3), (id1 == NULL) } +# Full table scan +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1_type=1; +Dump +Index=0, Order=ASC, Fields={ (Name=id1, Index=0), (Name=id2, Index=2), (Name=id1_type, Index=1), (Name=id2_type, Index=3), (Name=data, Index=6), (Name=version, Index=8) }, Cond={ (id1_type == 1) } DROP TABLE count_table; DROP TABLE link_table; DROP TABLE link_table3; @@ -777,3 +802,10 @@ DROP TABLE node_table; DROP TABLE link_table5; DROP TABLE link_table6; DROP TABLE link_table4; +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +3 +set global rocksdb_select_bypass_policy=@save_rocksdb_select_bypass_policy; +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +0 diff --git a/mysql-test/suite/rocksdb/r/bypass_select_unsupported.result b/mysql-test/suite/rocksdb/r/bypass_select_unsupported.result new file mode 100644 index 000000000000..30c571a0e6ec --- /dev/null +++ b/mysql-test/suite/rocksdb/r/bypass_select_unsupported.result @@ -0,0 +1,275 @@ +# restart +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +0 +SELECT @@rocksdb_select_bypass_policy into @save_rocksdb_select_bypass_policy; +set global rocksdb_select_bypass_policy=2; +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +2 +create table t1 (pk INT PRIMARY KEY, a INT, b INT, c INT, KEY a (a, b, c)) +ENGINE=ROCKSDB; +create table t2 (pk INT PRIMARY KEY, a INT, b INT, c INT, KEY a (a, b, c)) +ENGINE=ROCKSDB; +create table t3 (pk INT PRIMARY KEY, a INT, b INT, c VARCHAR(15) CHARACTER SET latin1, KEY a (a, b)) +ENGINE=ROCKSDB; +SELECT @@rocksdb_select_bypass_fail_unsupported; +@@rocksdb_select_bypass_fail_unsupported +1 +SELECT @@rocksdb_select_bypass_fail_unsupported into @save_fail_unsupported; +set global rocksdb_select_bypass_fail_unsupported=true; +SELECT @@rocksdb_select_bypass_fail_unsupported; +@@rocksdb_select_bypass_fail_unsupported +1 +SELECT /*+ bypass */ pk from t1 WHERE pk=1 having pk=1; +ERROR 42000: SELECT statement pattern not supported: HAVING not supported +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 0 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 1 +SELECT /*+ bypass */ pk from t1 WHERE pk=1 group by pk; +ERROR 42000: SELECT statement pattern not supported: GROUP BY not supported +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 0 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 2 +SELECT /*+ bypass */ * from t1 WHERE pk=1; +Dump +Index=0, Order=ASC, Fields={ (Name=pk, Index=0), (Name=a, Index=1), (Name=b, Index=2), (Name=c, Index=3) }, Cond={ (pk == 1) } +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 1 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 2 +SELECT /*+ bypass */ 1 from t1 WHERE pk=1; +ERROR 42000: SELECT statement pattern not supported: SELECT expressions can only be field +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 1 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 3 +SELECT /*+ bypass */ 1+2 from t1 WHERE pk=1; +ERROR 42000: SELECT statement pattern not supported: SELECT expressions can only be field +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 1 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 4 +SELECT /*+ bypass */ COUNT(*) from t1 WHERE pk=1; +ERROR 42000: SELECT statement pattern not supported: SELECT expressions can only be field +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 1 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 5 +SELECT /*+ bypass */ COUNT(pk) from t1 WHERE pk=1; +ERROR 42000: SELECT statement pattern not supported: SELECT expressions can only be field +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 1 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 6 +SELECT /*+ bypass */ pk+1 from t1 WHERE pk=1; +ERROR 42000: SELECT statement pattern not supported: SELECT expressions can only be field +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 1 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 7 +SELECT /*+ bypass */ pk from t1 USE INDEX (PRIMARY) WHERE pk=1; +ERROR 42000: SELECT statement pattern not supported: Index hint must be FORCE INDEX +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 1 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 8 +SELECT /*+ bypass */ pk from t1; +ERROR 42000: SELECT statement pattern not supported: Unsupported WHERE: should be expr [(AND expr)*] where expr only contains >, >=, <, <=, =, IN +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 1 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 9 +SELECT /*+ bypass */ pk from t1 WHERE pk=1 or pk=2; +ERROR 42000: SELECT statement pattern not supported: Unsupported WHERE: should be expr [(AND expr)*] where expr only contains >, >=, <, <=, =, IN +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 1 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 10 +SELECT /*+ bypass */ pk from t1 WHERE pk<=>1; +ERROR 42000: SELECT statement pattern not supported: Unsupported WHERE - needs to be >, >=, <, <=, =, IN +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 1 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 11 +SELECT /*+ bypass */ pk from t1 WHERE pk=(1,2,3); +ERROR 21000: Operand should contain 1 column(s) +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 1 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 11 +SELECT /*+ bypass */ pk from t1 WHERE pk=DATE '2019-03-25'; +Dump +Index=0, Order=ASC, Fields={ (Name=pk, Index=0) }, Cond={ (pk == 2019-03-25) } +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 2 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 11 +SELECT /*+ bypass */ pk from t1 WHERE pk=TIME '18:01:00'; +Dump +Index=0, Order=ASC, Fields={ (Name=pk, Index=0) }, Cond={ (pk == 18:01:00) } +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 3 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 11 +SELECT /*+ bypass */ pk from t1 WHERE pk=TIMESTAMP '2019-03-25 18:01:00'; +Dump +Index=0, Order=ASC, Fields={ (Name=pk, Index=0) }, Cond={ (pk == 2019-03-25 18:01:00) } +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 4 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 11 +SELECT /*+ bypass */ pk from t1 WHERE pk>ALL (SELECT pk FROM t1); +ERROR 42000: SELECT statement pattern not supported: Unsupported WHERE - needs to be >, >=, <, <=, =, IN +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 4 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 12 +SELECT /*+ bypass */ DISTINCT a from t1; +ERROR 42000: SELECT statement pattern not supported: SELECT options not supported (such as SELECT DISTINCT) +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 4 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 13 +SELECT /*+ bypass */ ALL a, b from t1; +ERROR 42000: SELECT statement pattern not supported: Unsupported WHERE: should be expr [(AND expr)*] where expr only contains >, >=, <, <=, =, IN +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 4 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 14 +SELECT /*+ bypass */ t1.pk, t2.pk from t1, t2; +pk pk +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 4 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 14 +SELECT /*+ bypass */ t1.pk FROM t1 LEFT JOIN t2 using (pk) +WHERE t1.pk=1; +pk +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 4 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 14 +SELECT /*+ bypass */ pk, a from (SELECT pk, a FROM t1) AS t1_temp; +pk a +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 4 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 14 +SELECT /*+ bypass */ pk FROM t1 WHERE pk=3 UNION DISTINCT +SELECT pk FROM t2 WHERE pk=3; +pk +SELECT /*+ bypass */ pk FROM t1 WHERE pk=3 UNION ALL +SELECT pk FROM t2 WHERE pk=3; +pk +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 4 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 14 +SELECT /*+ bypass */ a, b, c FROM t1 WHERE a=1 ORDER BY a; +ERROR 42000: SELECT statement pattern not supported: ORDER BY field doesn't belong to the index +SELECT /*+ bypass */ a, b, c FROM t1 FORCE INDEX(`a`) WHERE a=1 ORDER BY b, a; +ERROR 42000: SELECT statement pattern not supported: ORDER BY is not in index order +SELECT /*+ bypass */ a, b, c FROM t1 FORCE INDEX(`a`) WHERE a=1 +ORDER BY a, b, c, c, c, a, b, c, d; +ERROR 42S22: Unknown column 'd' in 'order clause' +SELECT /*+ bypass */ a, b, c FROM t1 FORCE INDEX(`a`) WHERE a=1 ORDER BY c, a; +ERROR 42000: SELECT statement pattern not supported: ORDER BY is not in index order +SELECT /*+ bypass */ a, b, c FROM t1 FORCE INDEX(`a`) WHERE a=1 ORDER BY a, a; +ERROR 42000: SELECT statement pattern not supported: ORDER BY is not in index order +SELECT /*+ bypass */ a, b, c FROM t1 FORCE INDEX(`a`) WHERE a=1 +ORDER BY a, a, a, a, a, a, a, a; +ERROR 42000: SELECT statement pattern not supported: ORDER BY is not in index order +SELECT /*+ bypass */ a, b, c FROM t1 FORCE INDEX(`a`) WHERE a=1 ORDER BY b, b; +ERROR 42000: SELECT statement pattern not supported: ORDER BY is not in index order +SELECT /*+ bypass */ a, b, c FROM t3 FORCE INDEX(`a`) WHERE a=1 ORDER BY b, b; +ERROR 42000: SELECT statement pattern not supported: only utf8_bin, latin1_bin is supported for varchar field +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 4 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 21 +SELECT /*+ bypass */ a, b, c FROM t1 FORCE INDEX(`abc`) WHERE a=1 ORDER BY b, a; +ERROR 42000: Key 'abc' doesn't exist in table 't1' +SELECT /*+ bypass */ a from t1 WHERE a=1 INTO OUTFILE 'datadir/select.out'; +ERROR 42000: SELECT statement pattern not supported: SELECT INTO/DUMP not supported +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 4 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 22 +SELECT /*+ bypass */ a from t1 WHERE a=1 INTO DUMPFILE 'datadir/select.dump'; +ERROR 42000: SELECT statement pattern not supported: SELECT INTO/DUMP not supported +SHOW STATUS LIKE 'rocksdb_select_bypass%'; +Variable_name Value +rocksdb_select_bypass_executed 4 +rocksdb_select_bypass_failed 0 +rocksdb_select_bypass_rejected 23 +SELECT /*+ bypass */ a, b, c FROM t3 WHERE pk=1 FOR UPDATE; +ERROR 42000: SELECT statement pattern not supported: Only SELECT with default READ lock is supported +SELECT /*+ bypass */ a, b, c FROM t3 WHERE pk=1 FOR UPDATE SKIP LOCKED; +ERROR 42000: This version of MySQL doesn't yet support 'SKIP LOCKED | NOWAIT is not yet supported in RocksDB storage engine' +SELECT /*+ bypass */ a, b, c FROM t3 WHERE pk=1 FOR UPDATE NOWAIT; +ERROR 42000: This version of MySQL doesn't yet support 'SKIP LOCKED | NOWAIT is not yet supported in RocksDB storage engine' +SELECT /*+ bypass */ a, b, c FROM t3 WHERE pk=1 LOCK IN SHARE MODE; +ERROR 42000: SELECT statement pattern not supported: Only SELECT with default READ lock is supported +SELECT /*+ bypass */ HIGH_PRIORITY a, b, c FROM t3 WHERE pk=1; +ERROR 42000: SELECT statement pattern not supported: Only SELECT with default READ lock is supported +SELECT /*+ bypass */ a,a,a,a,a, a,a,a,a,a, a,a,a,a,a, a,a FROM t3 WHERE pk=1; +ERROR 42000: SELECT statement pattern not supported: Too many SELECT expressions +SELECT /*+ bypass */ a FROM t3 WHERE a=1 AND a=1 AND a=1 AND a=1 AND a=1 AND +a=1 AND a=1 AND a=1 AND a=1 AND a=1 AND +a=1 AND a=1 AND a=1 AND a=1 AND a=1 AND +a=1 AND a=1; +ERROR 42000: SELECT statement pattern not supported: Too many WHERE expressions +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +2 +set global rocksdb_select_bypass_policy=@save_rocksdb_select_bypass_policy; +SELECT @@rocksdb_select_bypass_policy; +@@rocksdb_select_bypass_policy +0 +SELECT @@rocksdb_select_bypass_fail_unsupported; +@@rocksdb_select_bypass_fail_unsupported +1 +set global rocksdb_select_bypass_fail_unsupported=false; +SELECT @@rocksdb_select_bypass_fail_unsupported; +@@rocksdb_select_bypass_fail_unsupported +0 +SELECT /*+ bypass */ * from t1; +pk a b c +SELECT @@rocksdb_select_bypass_fail_unsupported; +@@rocksdb_select_bypass_fail_unsupported +0 +set global rocksdb_select_bypass_fail_unsupported=@save_fail_unsupported; +SELECT @@rocksdb_select_bypass_fail_unsupported; +@@rocksdb_select_bypass_fail_unsupported +1 +drop table t1; +drop table t2; +drop table t3; diff --git a/mysql-test/suite/rocksdb/r/rocksdb.result b/mysql-test/suite/rocksdb/r/rocksdb.result index d2c729f23580..15ef343a00d0 100644 --- a/mysql-test/suite/rocksdb/r/rocksdb.result +++ b/mysql-test/suite/rocksdb/r/rocksdb.result @@ -1004,6 +1004,10 @@ rocksdb_records_in_range 50 rocksdb_reset_stats OFF rocksdb_rollback_on_timeout OFF rocksdb_seconds_between_stat_computes 3600 +rocksdb_select_bypass_fail_unsupported ON +rocksdb_select_bypass_log_failed OFF +rocksdb_select_bypass_log_rejected ON +rocksdb_select_bypass_policy 0 rocksdb_signal_drop_index_thread OFF rocksdb_sim_cache_size 0 rocksdb_skip_bloom_filter_on_read OFF @@ -1634,6 +1638,9 @@ rocksdb_number_superversion_cleanups # rocksdb_number_superversion_releases # rocksdb_row_lock_deadlocks # rocksdb_row_lock_wait_timeouts # +rocksdb_select_bypass_executed # +rocksdb_select_bypass_failed # +rocksdb_select_bypass_rejected # rocksdb_snapshot_conflict_errors # rocksdb_stall_l0_file_count_limit_slowdowns # rocksdb_stall_locked_l0_file_count_limit_slowdowns # @@ -1743,6 +1750,9 @@ ROCKSDB_ROWS_READ ROCKSDB_ROWS_UPDATED ROCKSDB_ROW_LOCK_DEADLOCKS ROCKSDB_ROW_LOCK_WAIT_TIMEOUTS +ROCKSDB_SELECT_BYPASS_EXECUTED +ROCKSDB_SELECT_BYPASS_FAILED +ROCKSDB_SELECT_BYPASS_REJECTED ROCKSDB_SNAPSHOT_CONFLICT_ERRORS ROCKSDB_STALL_L0_FILE_COUNT_LIMIT_SLOWDOWNS ROCKSDB_STALL_L0_FILE_COUNT_LIMIT_STOPS @@ -1861,6 +1871,9 @@ ROCKSDB_ROWS_READ ROCKSDB_ROWS_UPDATED ROCKSDB_ROW_LOCK_DEADLOCKS ROCKSDB_ROW_LOCK_WAIT_TIMEOUTS +ROCKSDB_SELECT_BYPASS_EXECUTED +ROCKSDB_SELECT_BYPASS_FAILED +ROCKSDB_SELECT_BYPASS_REJECTED ROCKSDB_SNAPSHOT_CONFLICT_ERRORS ROCKSDB_STALL_L0_FILE_COUNT_LIMIT_SLOWDOWNS ROCKSDB_STALL_L0_FILE_COUNT_LIMIT_STOPS diff --git a/mysql-test/suite/rocksdb/t/bypass_select_basic.inc b/mysql-test/suite/rocksdb/t/bypass_select_basic.inc index 1f5c9fbb3f27..cc7380e05b77 100644 --- a/mysql-test/suite/rocksdb/t/bypass_select_basic.inc +++ b/mysql-test/suite/rocksdb/t/bypass_select_basic.inc @@ -2,45 +2,142 @@ --source ../include/bypass_create_table.inc -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -SELECT /*+ no_bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -SELECT id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; - -SELECT /*+bypassabc*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -SELECT /*+bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -SELECT /* +bypassabc*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +--echo # Default +SELECT @@rocksdb_select_bypass_policy; +SELECT @@rocksdb_select_bypass_policy INTO @save_rocksdb_select_bypass_policy; + +--echo # Always off +SELECT @@rocksdb_select_bypass_policy; +SET GLOBAL rocksdb_select_bypass_policy=0; +SELECT @@rocksdb_select_bypass_policy; + +SELECT variable_value INTO @a FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; + +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT /*+ no_bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; + +SELECT variable_value INTO @b FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +--echo # Should be 0 +SELECT @b-@a; + +--echo # Always on +SELECT @@rocksdb_select_bypass_policy; +SET GLOBAL rocksdb_select_bypass_policy=1; +SELECT @@rocksdb_select_bypass_policy; + +SELECT variable_value INTO @a FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; + +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT /*+ abc */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT /*+ no_bypass*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; + +SELECT variable_value INTO @b FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +--echo # Should be 4 +SELECT @b-@a; + +--echo # Opt-in +SELECT @@rocksdb_select_bypass_policy; +SET GLOBAL rocksdb_select_bypass_policy=2; +SELECT @@rocksdb_select_bypass_policy; + +SELECT variable_value into @a FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; + +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT /*+ no_bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; + +SELECT /*+bypassabc*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT /*+bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT /*+ bypass*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT /* +bypassabc*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; SELECT /*aaaaaaaaabbbbbbbbb*/ id1,id2,id1_type,id2_type,data,version -from link_table WHERE id1=1 and id2=2 and link_type=3; -SELECT /*+*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -SELECT /*+b*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -SELECT /*+byp*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -SELECT /*+bypw*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -SELECT /*-b*/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -SELECT /**/ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +FROM link_table WHERE id1=1 AND id2=2 AND link_type=3; +SELECT /*+*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT /*+b*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT /*+byp*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT /*+bypw*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT /*-b*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT /**/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; + +SELECT variable_value INTO @b FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +--echo # Should be 1 +SELECT @b-@a; + +--echo # Opt-out +select @@rocksdb_select_bypass_policy; +set global rocksdb_select_bypass_policy=3; +select @@rocksdb_select_bypass_policy; + +SELECT variable_value INTO @a FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; + +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT /*+bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT /*+*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; + +SELECT variable_value INTO @b FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +--echo # Should be 4 +SELECT @b-@a; + +SELECT /*+ no_bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT /*+ no_bypass*/ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT /*+no_bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT /*+no_bypassabc */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; + +SELECT variable_value INTO @c FROM performance_schema.global_status WHERE +variable_name="rocksdb_select_bypass_executed"; +--echo # Should be 3 +SELECT @c-@b; --echo # Point query -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2 IN (2, 3, 4) and link_type=3; -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2 IN (2) and link_type=3; -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1 IN (1) and id2 IN (2) and link_type=3; -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1 IN (1, 2) and id2 IN (2, 3, 4) and link_type=3; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2 IN (2, 3, 4) AND link_type=3; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2 IN (2) AND link_type=3; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1 IN (1) AND id2 IN (2) AND link_type=3; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1 IN (1, 2) AND id2 IN (2, 3, 4) AND link_type=3; --echo # Prefix range query @@ -162,46 +259,50 @@ ORDER BY TIME DESC LIMIT 10,0; --echo # Prefix range query with PK SELECT /*+ bypass */ id1, id2, link_type FROM link_table FORCE INDEX (PRIMARY) -WHERE link_type=3 and id1=1 ORDER BY id2 DESC; +WHERE link_type=3 AND id1=1 ORDER BY id2 DESC; SELECT /*+ bypass */ id1, id2, link_type FROM link_table FORCE INDEX (PRIMARY) -WHERE link_type=3 and id1=1 ORDER BY id2 ASC; +WHERE link_type=3 AND id1=1 ORDER BY id2 ASC; --echo # Prefix range query with PK + value SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (PRIMARY) -WHERE link_type=3 and id1=1 ORDER BY id2 DESC; +WHERE link_type=3 AND id1=1 ORDER BY id2 DESC; SELECT /*+ bypass */ id1, id2, link_type, visibility, data, time, version FROM link_table FORCE INDEX (PRIMARY) -WHERE link_type=3 and id1=1 ORDER BY id2 ASC; +WHERE link_type=3 AND id1=1 ORDER BY id2 ASC; --echo # Transaction BEGIN; -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -UPDATE link_table set data="bcd" WHERE id1=1 and id2=2 and link_type = 3; -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +UPDATE link_table set data="bcd" WHERE id1=1 AND id2=2 AND link_type = 3; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; COMMIT; BEGIN; -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; -UPDATE link_table set data="cde" WHERE id1=1 and id2=2 and link_type = 3; -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; +UPDATE link_table set data="cde" WHERE id1=1 AND id2=2 AND link_type = 3; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; ROLLBACK; -SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version from link_table -WHERE id1=1 and id2=2 and link_type=3; +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1=1 AND id2=2 AND link_type=3; --echo # Data types SELECT /*+ bypass */ id1 FROM link_table where link_type="3"; SELECT /*+ bypass */ id1 FROM link_table where link_type="3" AND id1="1"; SELECT /*+ bypass */ id1 FROM link_table where link_type="3" AND id1=True; SELECT /*+ bypass */ id1 FROM link_table where link_type="3" AND id1=b'1'; -SELECT /*+ bypass */ id1 FROM link_table where link_type="3" AND id1=x'01'; +SELECT /*+ bypass */ id1 FROM link_table where link_type="3" AND id1=x'61'; SELECT /*+ bypass */ id1 FROM link_table where link_type="3" AND id1=NULL; +--echo # Full table scan +SELECT /*+ bypass */ id1,id2,id1_type,id2_type,data,version FROM link_table +WHERE id1_type=1; + DROP TABLE count_table; DROP TABLE link_table; DROP TABLE link_table3; @@ -211,3 +312,8 @@ DROP TABLE node_table; DROP TABLE link_table5; DROP TABLE link_table6; DROP TABLE link_table4; + +SELECT @@rocksdb_select_bypass_policy; +set global rocksdb_select_bypass_policy=@save_rocksdb_select_bypass_policy; +SELECT @@rocksdb_select_bypass_policy; + diff --git a/mysql-test/suite/rocksdb/t/bypass_select_unsupported.test b/mysql-test/suite/rocksdb/t/bypass_select_unsupported.test new file mode 100644 index 000000000000..6c18e6d2f1e3 --- /dev/null +++ b/mysql-test/suite/rocksdb/t/bypass_select_unsupported.test @@ -0,0 +1,225 @@ +--source include/have_rocksdb.inc + +# increase counter because of "bulk_load*" tests that may be run in background +--let $explicit_default_counter= 10000 +# Make sure we have a fresh server with all status variables initialized to 0 +--source include/restart_mysqld.inc + +SELECT @@rocksdb_select_bypass_policy; +SELECT @@rocksdb_select_bypass_policy into @save_rocksdb_select_bypass_policy; +set global rocksdb_select_bypass_policy=2; +SELECT @@rocksdb_select_bypass_policy; + +create table t1 (pk INT PRIMARY KEY, a INT, b INT, c INT, KEY a (a, b, c)) +ENGINE=ROCKSDB; +create table t2 (pk INT PRIMARY KEY, a INT, b INT, c INT, KEY a (a, b, c)) +ENGINE=ROCKSDB; +create table t3 (pk INT PRIMARY KEY, a INT, b INT, c VARCHAR(15) CHARACTER SET latin1, KEY a (a, b)) +ENGINE=ROCKSDB; + +SELECT @@rocksdb_select_bypass_fail_unsupported; +SELECT @@rocksdb_select_bypass_fail_unsupported into @save_fail_unsupported; +set global rocksdb_select_bypass_fail_unsupported=true; +SELECT @@rocksdb_select_bypass_fail_unsupported; + +# Interesting SELECT patterns that are not supported +# Use https://dev.mysql.com/doc/refman/5.7/en/select.html as reference + +# Unsupported having +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ pk from t1 WHERE pk=1 having pk=1; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +# Unsupported group by +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ pk from t1 WHERE pk=1 group by pk; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +# * is supported in 8.0 through PT_query_specification::contextualize +SELECT /*+ bypass */ * from t1 WHERE pk=1; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ 1 from t1 WHERE pk=1; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ 1+2 from t1 WHERE pk=1; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ COUNT(*) from t1 WHERE pk=1; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ COUNT(pk) from t1 WHERE pk=1; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ pk+1 from t1 WHERE pk=1; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +# Unsupported index +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ pk from t1 USE INDEX (PRIMARY) WHERE pk=1; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +# Unsupported WHERE +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ pk from t1; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ pk from t1 WHERE pk=1 or pk=2; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ pk from t1 WHERE pk<=>1; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +--error ER_OPERAND_COLUMNS +SELECT /*+ bypass */ pk from t1 WHERE pk=(1,2,3); +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +# DATE/TIME/TIMESTAMP are constant functions +#--error ER_OPERAND_COLUMNS +SELECT /*+ bypass */ pk from t1 WHERE pk=DATE '2019-03-25'; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +#--error ER_OPERAND_COLUMNS +SELECT /*+ bypass */ pk from t1 WHERE pk=TIME '18:01:00'; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +#--error ER_OPERAND_COLUMNS +SELECT /*+ bypass */ pk from t1 WHERE pk=TIMESTAMP '2019-03-25 18:01:00'; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ pk from t1 WHERE pk>ALL (SELECT pk FROM t1); +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +# Select modifiers +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ DISTINCT a from t1; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ ALL a, b from t1; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +# Joins +SELECT /*+ bypass */ t1.pk, t2.pk from t1, t2; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +SELECT /*+ bypass */ t1.pk FROM t1 LEFT JOIN t2 using (pk) +WHERE t1.pk=1; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +# Subselect +SELECT /*+ bypass */ pk, a from (SELECT pk, a FROM t1) AS t1_temp; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +# Union +SELECT /*+ bypass */ pk FROM t1 WHERE pk=3 UNION DISTINCT +SELECT pk FROM t2 WHERE pk=3; +SELECT /*+ bypass */ pk FROM t1 WHERE pk=3 UNION ALL +SELECT pk FROM t2 WHERE pk=3; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +# Index order +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ a, b, c FROM t1 WHERE a=1 ORDER BY a; + +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ a, b, c FROM t1 FORCE INDEX(`a`) WHERE a=1 ORDER BY b, a; + +--error ER_BAD_FIELD_ERROR +SELECT /*+ bypass */ a, b, c FROM t1 FORCE INDEX(`a`) WHERE a=1 +ORDER BY a, b, c, c, c, a, b, c, d; + +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ a, b, c FROM t1 FORCE INDEX(`a`) WHERE a=1 ORDER BY c, a; + +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ a, b, c FROM t1 FORCE INDEX(`a`) WHERE a=1 ORDER BY a, a; + +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ a, b, c FROM t1 FORCE INDEX(`a`) WHERE a=1 +ORDER BY a, a, a, a, a, a, a, a; + +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ a, b, c FROM t1 FORCE INDEX(`a`) WHERE a=1 ORDER BY b, b; + +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ a, b, c FROM t3 FORCE INDEX(`a`) WHERE a=1 ORDER BY b, b; + +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +# Unrecognized index +--error ER_KEY_DOES_NOT_EXITS +SELECT /*+ bypass */ a, b, c FROM t1 FORCE INDEX(`abc`) WHERE a=1 ORDER BY b, a; + +# INTO @var +# SELECT /*+ bypass */ pk into @a FROM t1 +# WHERE pk=1; +# SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +# INTO OUTFILE +let $datadir = `SELECT @@datadir`; +--replace_result $datadir + +--replace_result $datadir datadir +--error ER_NOT_SUPPORTED_YET +eval SELECT /*+ bypass */ a from t1 WHERE a=1 INTO OUTFILE '$datadir/select.out'; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +--replace_result $datadir datadir +--error ER_NOT_SUPPORTED_YET +eval SELECT /*+ bypass */ a from t1 WHERE a=1 INTO DUMPFILE '$datadir/select.dump'; +SHOW STATUS LIKE 'rocksdb_select_bypass%'; + +# FOR UPDATE +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ a, b, c FROM t3 WHERE pk=1 FOR UPDATE; +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ a, b, c FROM t3 WHERE pk=1 FOR UPDATE SKIP LOCKED; +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ a, b, c FROM t3 WHERE pk=1 FOR UPDATE NOWAIT; +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ a, b, c FROM t3 WHERE pk=1 LOCK IN SHARE MODE; + +# HIGH PRIORITY +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ HIGH_PRIORITY a, b, c FROM t3 WHERE pk=1; + +# Too many SELECT expressions +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ a,a,a,a,a, a,a,a,a,a, a,a,a,a,a, a,a FROM t3 WHERE pk=1; + +# Too many WHERE expressions +--error ER_NOT_SUPPORTED_YET +SELECT /*+ bypass */ a FROM t3 WHERE a=1 AND a=1 AND a=1 AND a=1 AND a=1 AND + a=1 AND a=1 AND a=1 AND a=1 AND a=1 AND + a=1 AND a=1 AND a=1 AND a=1 AND a=1 AND + a=1 AND a=1; + +# Restore rocksdb_select_bypass_policy +SELECT @@rocksdb_select_bypass_policy; +set global rocksdb_select_bypass_policy=@save_rocksdb_select_bypass_policy; +SELECT @@rocksdb_select_bypass_policy; + +# Fallback +SELECT @@rocksdb_select_bypass_fail_unsupported; +set global rocksdb_select_bypass_fail_unsupported=false; +SELECT @@rocksdb_select_bypass_fail_unsupported; + +SELECT /*+ bypass */ * from t1; + +SELECT @@rocksdb_select_bypass_fail_unsupported; +set global rocksdb_select_bypass_fail_unsupported=@save_fail_unsupported; +SELECT @@rocksdb_select_bypass_fail_unsupported; + +drop table t1; +drop table t2; +drop table t3; + diff --git a/mysql-test/suite/rocksdb_sys_vars/r/rocksdb_select_bypass_fail_unsupported_basic.result b/mysql-test/suite/rocksdb_sys_vars/r/rocksdb_select_bypass_fail_unsupported_basic.result new file mode 100644 index 000000000000..dc43ee9b0982 --- /dev/null +++ b/mysql-test/suite/rocksdb_sys_vars/r/rocksdb_select_bypass_fail_unsupported_basic.result @@ -0,0 +1,68 @@ +CREATE TABLE valid_values (value varchar(255)) ENGINE=myisam; +INSERT INTO valid_values VALUES(1); +INSERT INTO valid_values VALUES(0); +INSERT INTO valid_values VALUES('on'); +INSERT INTO valid_values VALUES('off'); +CREATE TABLE invalid_values (value varchar(255)) ENGINE=myisam; +INSERT INTO invalid_values VALUES('\'aaa\''); +SET @start_global_value = @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED; +SELECT @start_global_value; +@start_global_value +1 +'# Setting to valid values in global scope#' +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED to 1" +SET @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED = 1; +SELECT @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED; +@@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED +1 +"Setting the global scope variable back to default" +SET @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED = DEFAULT; +SELECT @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED; +@@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED +1 +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED to 0" +SET @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED = 0; +SELECT @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED; +@@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED +0 +"Setting the global scope variable back to default" +SET @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED = DEFAULT; +SELECT @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED; +@@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED +1 +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED to on" +SET @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED = on; +SELECT @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED; +@@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED +1 +"Setting the global scope variable back to default" +SET @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED = DEFAULT; +SELECT @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED; +@@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED +1 +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED to off" +SET @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED = off; +SELECT @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED; +@@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED +0 +"Setting the global scope variable back to default" +SET @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED = DEFAULT; +SELECT @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED; +@@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED +1 +"Trying to set variable @@session.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED to 444. It should fail because it is not session." +SET @@session.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED = 444; +ERROR HY000: Variable 'rocksdb_select_bypass_fail_unsupported' is a GLOBAL variable and should be set with SET GLOBAL +'# Testing with invalid values in global scope #' +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED to 'aaa'" +SET @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED = 'aaa'; +Got one of the listed errors +SELECT @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED; +@@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED +1 +SET @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED = @start_global_value; +SELECT @@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED; +@@global.ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED +1 +DROP TABLE valid_values; +DROP TABLE invalid_values; diff --git a/mysql-test/suite/rocksdb_sys_vars/r/rocksdb_select_bypass_log_failed_basic.result b/mysql-test/suite/rocksdb_sys_vars/r/rocksdb_select_bypass_log_failed_basic.result new file mode 100644 index 000000000000..ff7218699477 --- /dev/null +++ b/mysql-test/suite/rocksdb_sys_vars/r/rocksdb_select_bypass_log_failed_basic.result @@ -0,0 +1,68 @@ +CREATE TABLE valid_values (value varchar(255)) ENGINE=myisam; +INSERT INTO valid_values VALUES(1); +INSERT INTO valid_values VALUES(0); +INSERT INTO valid_values VALUES('on'); +INSERT INTO valid_values VALUES('off'); +CREATE TABLE invalid_values (value varchar(255)) ENGINE=myisam; +INSERT INTO invalid_values VALUES('\'aaa\''); +SET @start_global_value = @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED; +SELECT @start_global_value; +@start_global_value +0 +'# Setting to valid values in global scope#' +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED to 1" +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED = 1; +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED +1 +"Setting the global scope variable back to default" +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED = DEFAULT; +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED +0 +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED to 0" +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED = 0; +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED +0 +"Setting the global scope variable back to default" +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED = DEFAULT; +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED +0 +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED to on" +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED = on; +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED +1 +"Setting the global scope variable back to default" +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED = DEFAULT; +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED +0 +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED to off" +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED = off; +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED +0 +"Setting the global scope variable back to default" +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED = DEFAULT; +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED +0 +"Trying to set variable @@session.ROCKSDB_SELECT_BYPASS_LOG_FAILED to 444. It should fail because it is not session." +SET @@session.ROCKSDB_SELECT_BYPASS_LOG_FAILED = 444; +ERROR HY000: Variable 'rocksdb_select_bypass_log_failed' is a GLOBAL variable and should be set with SET GLOBAL +'# Testing with invalid values in global scope #' +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED to 'aaa'" +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED = 'aaa'; +Got one of the listed errors +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED +0 +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED = @start_global_value; +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_FAILED +0 +DROP TABLE valid_values; +DROP TABLE invalid_values; diff --git a/mysql-test/suite/rocksdb_sys_vars/r/rocksdb_select_bypass_log_rejected_basic.result b/mysql-test/suite/rocksdb_sys_vars/r/rocksdb_select_bypass_log_rejected_basic.result new file mode 100644 index 000000000000..274e118d63d8 --- /dev/null +++ b/mysql-test/suite/rocksdb_sys_vars/r/rocksdb_select_bypass_log_rejected_basic.result @@ -0,0 +1,68 @@ +CREATE TABLE valid_values (value varchar(255)) ENGINE=myisam; +INSERT INTO valid_values VALUES(1); +INSERT INTO valid_values VALUES(0); +INSERT INTO valid_values VALUES('on'); +INSERT INTO valid_values VALUES('off'); +CREATE TABLE invalid_values (value varchar(255)) ENGINE=myisam; +INSERT INTO invalid_values VALUES('\'aaa\''); +SET @start_global_value = @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED; +SELECT @start_global_value; +@start_global_value +1 +'# Setting to valid values in global scope#' +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED to 1" +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED = 1; +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED +1 +"Setting the global scope variable back to default" +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED = DEFAULT; +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED +1 +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED to 0" +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED = 0; +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED +0 +"Setting the global scope variable back to default" +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED = DEFAULT; +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED +1 +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED to on" +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED = on; +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED +1 +"Setting the global scope variable back to default" +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED = DEFAULT; +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED +1 +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED to off" +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED = off; +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED +0 +"Setting the global scope variable back to default" +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED = DEFAULT; +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED +1 +"Trying to set variable @@session.ROCKSDB_SELECT_BYPASS_LOG_REJECTED to 444. It should fail because it is not session." +SET @@session.ROCKSDB_SELECT_BYPASS_LOG_REJECTED = 444; +ERROR HY000: Variable 'rocksdb_select_bypass_log_rejected' is a GLOBAL variable and should be set with SET GLOBAL +'# Testing with invalid values in global scope #' +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED to 'aaa'" +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED = 'aaa'; +Got one of the listed errors +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED +1 +SET @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED = @start_global_value; +SELECT @@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED; +@@global.ROCKSDB_SELECT_BYPASS_LOG_REJECTED +1 +DROP TABLE valid_values; +DROP TABLE invalid_values; diff --git a/mysql-test/suite/rocksdb_sys_vars/r/rocksdb_select_bypass_policy_basic.result b/mysql-test/suite/rocksdb_sys_vars/r/rocksdb_select_bypass_policy_basic.result new file mode 100644 index 000000000000..a148a009e06c --- /dev/null +++ b/mysql-test/suite/rocksdb_sys_vars/r/rocksdb_select_bypass_policy_basic.result @@ -0,0 +1,68 @@ +CREATE TABLE valid_values (value varchar(255)) ENGINE=myisam; +INSERT INTO valid_values VALUES(0); +INSERT INTO valid_values VALUES(1); +INSERT INTO valid_values VALUES(2); +INSERT INTO valid_values VALUES(3); +CREATE TABLE invalid_values (value varchar(255)) ENGINE=myisam; +INSERT INTO invalid_values VALUES('\'aaa\''); +SET @start_global_value = @@global.ROCKSDB_SELECT_BYPASS_POLICY; +SELECT @start_global_value; +@start_global_value +0 +'# Setting to valid values in global scope#' +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_POLICY to 0" +SET @@global.ROCKSDB_SELECT_BYPASS_POLICY = 0; +SELECT @@global.ROCKSDB_SELECT_BYPASS_POLICY; +@@global.ROCKSDB_SELECT_BYPASS_POLICY +0 +"Setting the global scope variable back to default" +SET @@global.ROCKSDB_SELECT_BYPASS_POLICY = DEFAULT; +SELECT @@global.ROCKSDB_SELECT_BYPASS_POLICY; +@@global.ROCKSDB_SELECT_BYPASS_POLICY +0 +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_POLICY to 1" +SET @@global.ROCKSDB_SELECT_BYPASS_POLICY = 1; +SELECT @@global.ROCKSDB_SELECT_BYPASS_POLICY; +@@global.ROCKSDB_SELECT_BYPASS_POLICY +1 +"Setting the global scope variable back to default" +SET @@global.ROCKSDB_SELECT_BYPASS_POLICY = DEFAULT; +SELECT @@global.ROCKSDB_SELECT_BYPASS_POLICY; +@@global.ROCKSDB_SELECT_BYPASS_POLICY +0 +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_POLICY to 2" +SET @@global.ROCKSDB_SELECT_BYPASS_POLICY = 2; +SELECT @@global.ROCKSDB_SELECT_BYPASS_POLICY; +@@global.ROCKSDB_SELECT_BYPASS_POLICY +2 +"Setting the global scope variable back to default" +SET @@global.ROCKSDB_SELECT_BYPASS_POLICY = DEFAULT; +SELECT @@global.ROCKSDB_SELECT_BYPASS_POLICY; +@@global.ROCKSDB_SELECT_BYPASS_POLICY +0 +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_POLICY to 3" +SET @@global.ROCKSDB_SELECT_BYPASS_POLICY = 3; +SELECT @@global.ROCKSDB_SELECT_BYPASS_POLICY; +@@global.ROCKSDB_SELECT_BYPASS_POLICY +3 +"Setting the global scope variable back to default" +SET @@global.ROCKSDB_SELECT_BYPASS_POLICY = DEFAULT; +SELECT @@global.ROCKSDB_SELECT_BYPASS_POLICY; +@@global.ROCKSDB_SELECT_BYPASS_POLICY +0 +"Trying to set variable @@session.ROCKSDB_SELECT_BYPASS_POLICY to 444. It should fail because it is not session." +SET @@session.ROCKSDB_SELECT_BYPASS_POLICY = 444; +ERROR HY000: Variable 'rocksdb_select_bypass_policy' is a GLOBAL variable and should be set with SET GLOBAL +'# Testing with invalid values in global scope #' +"Trying to set variable @@global.ROCKSDB_SELECT_BYPASS_POLICY to 'aaa'" +SET @@global.ROCKSDB_SELECT_BYPASS_POLICY = 'aaa'; +Got one of the listed errors +SELECT @@global.ROCKSDB_SELECT_BYPASS_POLICY; +@@global.ROCKSDB_SELECT_BYPASS_POLICY +0 +SET @@global.ROCKSDB_SELECT_BYPASS_POLICY = @start_global_value; +SELECT @@global.ROCKSDB_SELECT_BYPASS_POLICY; +@@global.ROCKSDB_SELECT_BYPASS_POLICY +0 +DROP TABLE valid_values; +DROP TABLE invalid_values; diff --git a/mysql-test/suite/rocksdb_sys_vars/t/rocksdb_select_bypass_fail_unsupported_basic.test b/mysql-test/suite/rocksdb_sys_vars/t/rocksdb_select_bypass_fail_unsupported_basic.test new file mode 100644 index 000000000000..72a48d2ae21b --- /dev/null +++ b/mysql-test/suite/rocksdb_sys_vars/t/rocksdb_select_bypass_fail_unsupported_basic.test @@ -0,0 +1,18 @@ +--source include/have_rocksdb.inc + +CREATE TABLE valid_values (value varchar(255)) ENGINE=myisam; +INSERT INTO valid_values VALUES(1); +INSERT INTO valid_values VALUES(0); +INSERT INTO valid_values VALUES('on'); +INSERT INTO valid_values VALUES('off'); + +CREATE TABLE invalid_values (value varchar(255)) ENGINE=myisam; +INSERT INTO invalid_values VALUES('\'aaa\''); + +--let $sys_var=ROCKSDB_SELECT_BYPASS_FAIL_UNSUPPORTED +--let $read_only=0 +--let $session=0 +--source ../include/rocksdb_sys_var.inc + +DROP TABLE valid_values; +DROP TABLE invalid_values; diff --git a/mysql-test/suite/rocksdb_sys_vars/t/rocksdb_select_bypass_log_failed_basic.test b/mysql-test/suite/rocksdb_sys_vars/t/rocksdb_select_bypass_log_failed_basic.test new file mode 100644 index 000000000000..86b85d55b65e --- /dev/null +++ b/mysql-test/suite/rocksdb_sys_vars/t/rocksdb_select_bypass_log_failed_basic.test @@ -0,0 +1,18 @@ +--source include/have_rocksdb.inc + +CREATE TABLE valid_values (value varchar(255)) ENGINE=myisam; +INSERT INTO valid_values VALUES(1); +INSERT INTO valid_values VALUES(0); +INSERT INTO valid_values VALUES('on'); +INSERT INTO valid_values VALUES('off'); + +CREATE TABLE invalid_values (value varchar(255)) ENGINE=myisam; +INSERT INTO invalid_values VALUES('\'aaa\''); + +--let $sys_var=ROCKSDB_SELECT_BYPASS_LOG_FAILED +--let $read_only=0 +--let $session=0 +--source ../include/rocksdb_sys_var.inc + +DROP TABLE valid_values; +DROP TABLE invalid_values; diff --git a/mysql-test/suite/rocksdb_sys_vars/t/rocksdb_select_bypass_log_rejected_basic.test b/mysql-test/suite/rocksdb_sys_vars/t/rocksdb_select_bypass_log_rejected_basic.test new file mode 100644 index 000000000000..bbe9c9371611 --- /dev/null +++ b/mysql-test/suite/rocksdb_sys_vars/t/rocksdb_select_bypass_log_rejected_basic.test @@ -0,0 +1,18 @@ +--source include/have_rocksdb.inc + +CREATE TABLE valid_values (value varchar(255)) ENGINE=myisam; +INSERT INTO valid_values VALUES(1); +INSERT INTO valid_values VALUES(0); +INSERT INTO valid_values VALUES('on'); +INSERT INTO valid_values VALUES('off'); + +CREATE TABLE invalid_values (value varchar(255)) ENGINE=myisam; +INSERT INTO invalid_values VALUES('\'aaa\''); + +--let $sys_var=ROCKSDB_SELECT_BYPASS_LOG_REJECTED +--let $read_only=0 +--let $session=0 +--source ../include/rocksdb_sys_var.inc + +DROP TABLE valid_values; +DROP TABLE invalid_values; diff --git a/mysql-test/suite/rocksdb_sys_vars/t/rocksdb_select_bypass_policy_basic.test b/mysql-test/suite/rocksdb_sys_vars/t/rocksdb_select_bypass_policy_basic.test new file mode 100644 index 000000000000..00db262f342a --- /dev/null +++ b/mysql-test/suite/rocksdb_sys_vars/t/rocksdb_select_bypass_policy_basic.test @@ -0,0 +1,18 @@ +--source include/have_rocksdb.inc + +CREATE TABLE valid_values (value varchar(255)) ENGINE=myisam; +INSERT INTO valid_values VALUES(0); +INSERT INTO valid_values VALUES(1); +INSERT INTO valid_values VALUES(2); +INSERT INTO valid_values VALUES(3); + +CREATE TABLE invalid_values (value varchar(255)) ENGINE=myisam; +INSERT INTO invalid_values VALUES('\'aaa\''); + +--let $sys_var=ROCKSDB_SELECT_BYPASS_POLICY +--let $read_only=0 +--let $session=0 +--source ../include/rocksdb_sys_var.inc + +DROP TABLE valid_values; +DROP TABLE invalid_values; diff --git a/sql/item.h b/sql/item.h index 26fdde30d306..e8070215b4cb 100644 --- a/sql/item.h +++ b/sql/item.h @@ -3900,8 +3900,10 @@ class Item_equal; class Item_field : public Item_ident { typedef Item_ident super; - protected: + public: void set_field(Field *field); + + protected: type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index afc5d7da5990..412bb9600c40 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -800,12 +800,18 @@ static bool optimize_secondary_engine(THD *thd) { /* Call out to handler to handle this select command */ bool ha_handle_single_table_select(THD *thd, SELECT_LEX_UNIT *unit) { - /* Simple non-UNION non-NESTED single-table query only */ + /* Simple non-UNION non-NESTED query only */ if (!unit->is_simple()) { return false; } SELECT_LEX *select_lex = unit->first_select(); + + /* Single table query only */ + if (select_lex->table_list.elements != 1) { + return false; + } + TABLE_LIST *table_list = select_lex->table_list.first; if (!table_list) { return false; @@ -833,7 +839,10 @@ bool ha_handle_single_table_select(THD *thd, SELECT_LEX_UNIT *unit) { bool Sql_cmd_dml::execute_inner(THD *thd) { SELECT_LEX_UNIT *unit = lex->unit; - if (ha_handle_single_table_select(thd, unit)) return false; + if (ha_handle_single_table_select(thd, unit)) { + // We've handled the query + return thd->is_error(); + } if (unit->optimize(thd, /*materialize_destination=*/nullptr, /*create_iterators=*/true)) diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc index 2e72377bcb96..8ff113705d2c 100644 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@ -719,6 +719,10 @@ static bool rocksdb_enable_insert_with_update_caching = true; /* Use unsigned long long instead of uint64_t because of MySQL compatibility */ static unsigned long long // NOLINT(runtime/int) rocksdb_max_compaction_history = 0; +static uint32_t rocksdb_select_bypass_policy = SELECT_BYPASS_POLICY_DEFAULT; +static bool rocksdb_select_bypass_fail_unsupported = true; +static bool rocksdb_select_bypass_log_rejected = true; +static bool rocksdb_select_bypass_log_failed = false; std::atomic rocksdb_row_lock_deadlocks(0); std::atomic rocksdb_row_lock_wait_timeouts(0); @@ -729,6 +733,9 @@ std::atomic rocksdb_manual_compactions_running(0); #ifndef DBUG_OFF std::atomic rocksdb_num_get_for_update_calls(0); #endif +std::atomic rocksdb_select_bypass_executed(0); +std::atomic rocksdb_select_bypass_rejected(0); +std::atomic rocksdb_select_bypass_failed(0); static int rocksdb_trace_block_cache_access( THD *const thd MY_ATTRIBUTE((__unused__)), @@ -2189,6 +2196,30 @@ static MYSQL_THDVAR_BOOL(disable_file_deletions, PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_RQCMDARG, "Prevent file deletions", nullptr, rocksdb_disable_file_deletions_update, false); +static MYSQL_SYSVAR_UINT( + select_bypass_policy, rocksdb_select_bypass_policy, PLUGIN_VAR_RQCMDARG, + "Change bypass SELECT related policy and allow directly talk to RocksDB", + nullptr, nullptr, + /* default */ SELECT_BYPASS_POLICY_DEFAULT, + /* min */ SELECT_BYPASS_POLICY_ALWAYS_OFF, + /* max */ SELECT_BYPASS_POLICY_OPT_OUT, 0); + +static MYSQL_SYSVAR_BOOL( + select_bypass_fail_unsupported, rocksdb_select_bypass_fail_unsupported, + PLUGIN_VAR_RQCMDARG, + "Select bypass would fail for unsupported SELECT commands", nullptr, + nullptr, true); + +static MYSQL_SYSVAR_BOOL(select_bypass_log_rejected, + rocksdb_select_bypass_log_rejected, + PLUGIN_VAR_RQCMDARG, + "Log rejected SELECT bypass queries", nullptr, nullptr, + true); + +static MYSQL_SYSVAR_BOOL(select_bypass_log_failed, + rocksdb_select_bypass_log_failed, PLUGIN_VAR_RQCMDARG, + "Log failed SELECT bypass queries", nullptr, nullptr, + false); static const int ROCKSDB_ASSUMED_KEY_VALUE_DISK_SIZE = 100; @@ -2363,6 +2394,10 @@ static struct SYS_VAR *rocksdb_system_variables[] = { MYSQL_SYSVAR(enable_insert_with_update_caching), MYSQL_SYSVAR(trace_block_cache_access), MYSQL_SYSVAR(max_compaction_history), + MYSQL_SYSVAR(select_bypass_policy), + MYSQL_SYSVAR(select_bypass_fail_unsupported), + MYSQL_SYSVAR(select_bypass_log_failed), + MYSQL_SYSVAR(select_bypass_log_rejected), nullptr}; static int rocksdb_compact_column_family( @@ -14221,6 +14256,12 @@ static SHOW_VAR rocksdb_status_vars[] = { DEF_STATUS_VAR_PTR("num_get_for_update_calls", &rocksdb_num_get_for_update_calls, SHOW_LONGLONG), #endif + DEF_STATUS_VAR_PTR("select_bypass_executed", + &rocksdb_select_bypass_executed, SHOW_LONGLONG), + DEF_STATUS_VAR_PTR("select_bypass_rejected", + &rocksdb_select_bypass_rejected, SHOW_LONGLONG), + DEF_STATUS_VAR_PTR("select_bypass_failed", &rocksdb_select_bypass_failed, + SHOW_LONGLONG), // the variables generated by SHOW_FUNC are sorted only by prefix (first // arg in the tuple below), so make sure it is unique to make sorting // deterministic as quick sort is not stable @@ -15714,6 +15755,20 @@ void Rdb_compaction_stats::record_end(rocksdb::CompactionJobInfo info) { m_history.emplace_back(std::move(record)); } +uint32_t get_select_bypass_policy() { return rocksdb_select_bypass_policy; } + +bool should_fail_unsupported_select_bypass() { + return rocksdb_select_bypass_fail_unsupported; +} + +bool should_log_rejected_select_bypass() { + return rocksdb_select_bypass_log_rejected; +} + +bool should_log_failed_select_bypass() { + return rocksdb_select_bypass_log_failed; +} + } // namespace myrocks /* diff --git a/storage/rocksdb/ha_rocksdb.h b/storage/rocksdb/ha_rocksdb.h index a86ac82fa4ef..05b30a5156d4 100644 --- a/storage/rocksdb/ha_rocksdb.h +++ b/storage/rocksdb/ha_rocksdb.h @@ -1111,4 +1111,20 @@ class Rdb_compaction_stats { extern Rdb_compaction_stats compaction_stats; +/* Whether ROCKSDB_ENABLE_SELECT_BYPASS is enabled */ +uint32_t get_select_bypass_policy(); + +/* Whether we should log unsupported SELECT bypass */ +bool should_fail_unsupported_select_bypass(); + +/* Whether we should log rejected unsupported SELECT bypass */ +bool should_log_rejected_select_bypass(); + +/* Whether we should log failed unsupported SELECT bypass */ +bool should_log_failed_select_bypass(); + +extern std::atomic rocksdb_select_bypass_executed; +extern std::atomic rocksdb_select_bypass_rejected; +extern std::atomic rocksdb_select_bypass_failed; + } // namespace myrocks diff --git a/storage/rocksdb/nosql_access.cc b/storage/rocksdb/nosql_access.cc index 2aa9f2134b44..5a92cff4a3f4 100644 --- a/storage/rocksdb/nosql_access.cc +++ b/storage/rocksdb/nosql_access.cc @@ -31,21 +31,721 @@ #include /* MySQL header files */ -#include "../../sql/item.h" -#include "../../sql/sql_base.h" -#include "../../sql/strfunc.h" +#include "./sql/item.h" +#include "./sql/item_func.h" +#include "./sql/query_result.h" +#include "./sql/sql_base.h" +#include "./sql/sql_select.h" +#include "./sql/strfunc.h" +#include "mysql/services.h" +#include "sql/sql_lex.h" /* MyRocks header files */ #include "./ha_rocksdb.h" #include "./ha_rocksdb_proto.h" #include "./rdb_buff.h" +#include "./rdb_converter.h" #include "./rdb_datadic.h" +static const size_t MAX_NOSQL_FIELD_COUNT = 16; +static const size_t MAX_NOSQL_COND_COUNT = 16; + +// A soft max for key writers used for initial vector allocation and +// for stack allocation +__attribute__((unused)) static const size_t KEY_WRITER_DEFAULT_SIZE = 16; + namespace myrocks { -bool rocksdb_handle_single_table_select(THD * /* unused */, - SELECT_LEX * /* unused */) { - return false; +/* We only support simple equal / comparison functions */ +bool inline is_supported_item_func(Item_func::Functype type) { + // TODO(yzha) - Support EQUAL_FUNC <=> + // TODO(yzha) - Convert into a lookup table + if (type != Item_func::EQ_FUNC && type != Item_func::IN_FUNC && + type != Item_func::LT_FUNC && type != Item_func::LE_FUNC && + type != Item_func::GE_FUNC && type != Item_func::GT_FUNC) { + return false; + } + + return true; +} + +namespace { + +/* + Represents single conditional expression in SELECT WHERE + Example: id1 > 100 + */ +struct sql_cond { + Item_func::Functype op_type; // the operator, such as > + Field *field; // field + Item *cond_item; // item + Item *val_item; // item containing the value + + sql_cond(Item_func::Functype _op_type, Field *_field, Item *_cond_item, + Item *_val_item) + : op_type(_op_type), + field(_field), + cond_item(_cond_item), + val_item(_val_item) {} + sql_cond() = default; +}; + +/* + Extract necessary information from SELECT statements + */ +class select_parser { + public: + select_parser(THD *thd, SELECT_LEX *select_lex) + : m_thd(thd), m_select_lex(select_lex) { + // Single table only + DBUG_ASSERT(select_lex->table_list.elements == 1); + m_table_list = select_lex->table_list.first; + m_table = m_table_list->table; + DBUG_ASSERT(ha_legacy_type(m_table->s->db_type()) == DB_TYPE_ROCKSDB); + m_error_msg = "UNKNOWN"; + m_use_unoptimized_field_type = false; + } + + bool INLINE_ATTR parse() { + // No HAVING clause + if (m_table_list->lock_descriptor().type > TL_READ) { + m_error_msg = "Only SELECT with default READ lock is supported"; + return true; + } + + // No HAVING clause + if (m_select_lex->having_cond() != nullptr) { + m_error_msg = "HAVING not supported"; + return true; + } + + // No GROUP BY clauses + if (m_select_lex->group_list.elements > 0) { + m_error_msg = "GROUP BY not supported"; + return true; + } + + // No SELECT options such as SELECT_DISTINCT except for comments + // See sql_priv.h for a list + if (m_select_lex->active_options() & SELECT_DISTINCT) { + m_error_msg = "SELECT options not supported (such as SELECT DISTINCT)"; + return true; + } + + // INTO OUTFILE + // DUMP OUTFILE + if (m_thd->lex->result && m_thd->lex->result->needs_file_privilege()) { + m_error_msg = "SELECT INTO/DUMP not supported"; + return true; + } + + // @TODO - PROCEDURE + // NOTE: These have side effects and their orders are important + if (parse_index() || parse_fields() || parse_order_by() || parse_where() || + parse_limit()) { + return true; + } + + return false; + } + + /* + Dump out the parsed contents of the SELECT statement + Typically used in debug only + */ + std::string dump() { + std::string str; + str += "Index=" + std::to_string(m_index); + str += ", "; + str += "Order="; + str += (m_is_order_desc ? "DESC" : "ASC"); + str += ", "; + str += "Fields={ "; + + for (uint i = 0; i < m_field_count; ++i) { + auto field = m_field_list[i]; + if (i) { + str += ", "; + } + str += "(Name="; + str += field->field_name; + str += ", Index="; + str += std::to_string(field->field_index()); + str += ")"; + } + + str += " }, Cond={ "; + + for (uint i = 0; i < m_cond_count; ++i) { + auto &cond = m_cond_list[i]; + if (i) { + str += ", "; + } + str += "("; + str += cond.field->field_name; + str += " "; + switch (cond.op_type) { + case Item_func::EQ_FUNC: { + str += "=="; + break; + } + case Item_func::LT_FUNC: { + str += "<"; + break; + } + case Item_func::GT_FUNC: { + str += ">"; + break; + } + case Item_func::LE_FUNC: { + str += "<="; + break; + } + case Item_func::GE_FUNC: { + str += ">="; + break; + } + case Item_func::IN_FUNC: { + str += "IN"; + break; + } + default: + str += "?"; + } + str += " "; + if (cond.op_type == Item_func::IN_FUNC) { + str += "("; + auto in_func = static_cast(cond.cond_item); + auto args = in_func->arguments(); + for (uint j = 1; j < in_func->argument_count(); ++j) { + if (j > 1) { + str += ","; + } + String storage; + String *ret = args[j]->val_str(&storage); + if (ret == nullptr) { + str += "NULL"; + } else { + str += ret->c_ptr_safe(); + } + } + str += ")"; + } else { + String storage; + String *ret = cond.val_item->val_str(&storage); + if (ret == nullptr) { + str += "NULL"; + } else { + str += ret->c_ptr_safe(); + } + } + str += ")"; + } + str += " }"; + + return str; + } + + __attribute__((unused)) THD *get_thd() const { return m_thd; } + __attribute__((unused)) TABLE *get_table() const { return m_table; } + __attribute__((unused)) SELECT_LEX *get_select_lex() const { + return m_select_lex; + } + __attribute__((unused)) uint get_index() const { return m_index; } + __attribute__((unused)) bool is_order_desc() const { return m_is_order_desc; } + __attribute__((unused)) Field *const *get_field_list() const { + return m_field_list; + } + __attribute__((unused)) const sql_cond *get_cond_list() const { + return m_cond_list; + } + __attribute__((unused)) uint get_field_count() const { return m_field_count; } + __attribute__((unused)) uint get_cond_count() const { return m_cond_count; } + __attribute__((unused)) uint64_t get_select_limit() const { + return m_select_limit; + } + __attribute__((unused)) uint64_t get_offset_limit() const { + return m_offset_limit; + } + __attribute__((unused)) const char *get_error_msg() const { + return m_error_msg; + } + __attribute__((unused)) bool use_unoptimized_field_type() const { + return m_use_unoptimized_field_type; + } + + private: + THD *m_thd; + TABLE *m_table; + TABLE_LIST *m_table_list; + SELECT_LEX *m_select_lex; + + uint m_index; + bool m_is_order_desc; + Field *m_field_list[MAX_NOSQL_FIELD_COUNT]; + uint m_field_count = 0; + sql_cond m_cond_list[MAX_NOSQL_COND_COUNT]; + uint m_cond_count = 0; + uint64_t m_select_limit; + uint64_t m_offset_limit; + bool m_use_unoptimized_field_type; + const char *m_error_msg; + + // Buffer to store snprintf-ed error messages + char m_error_msg_buf[FN_REFLEN]; + + private: + bool parse_index() { + if (m_table_list->index_hints != nullptr) { + if (m_table_list->index_hints->elements == 1) { + // Must be a FORCE INDEX + Index_hint *hint = m_table_list->index_hints->head(); + if (hint->type != INDEX_HINT_FORCE) { + m_error_msg = "Index hint must be FORCE INDEX"; + return true; + } + uint pos = find_type(&m_table->s->keynames, hint->key_name.str, + hint->key_name.length, true); + if (!pos) { + // Unrecognized index + snprintf(m_error_msg_buf, sizeof(m_error_msg_buf) / sizeof(char), + "Unrecognized index: '%s'", hint->key_name.str); + m_error_msg = m_error_msg_buf; + return true; + } + m_index = pos - 1; + } else { + // Have to be at most 1 index hints + m_error_msg = "More than 1 index hints unsupported"; + return true; + } + + } else { + // Default to PRIMARY + m_index = m_table->s->primary_key; + } + + return false; + } + + bool parse_fields() { + // All item must be fields + for (Item *item : m_select_lex->visible_fields()) { + auto type = item->type(); + if (type != Item::FIELD_ITEM) { + m_error_msg = "SELECT expressions can only be field"; + return true; + } + + Item_field *field_item = static_cast(item); + auto name = field_item->field_name; + + // At this point we only know field name and need to resolve the + // field ourselves (under normal circumstances MySQL does it for us) + uint field_index = field_item->field_index; + + Field *field = + find_field_in_table(m_table, name, strlen(name), false, &field_index); + if (!field) { + snprintf(m_error_msg_buf, sizeof(m_error_msg_buf) / sizeof(char), + "Unrecognized field name: '%s'", name); + m_error_msg = m_error_msg_buf; + return true; + } + + auto field_type = field->real_type(); + if (field_type == MYSQL_TYPE_VARCHAR && + field->charset() != &my_charset_utf8_bin && + field->charset() != &my_charset_latin1_bin) { + m_error_msg = + "only utf8_bin, latin1_bin is supported for varchar field"; + return true; + } + + if (!m_use_unoptimized_field_type) { + switch (field_type) { + case MYSQL_TYPE_LONGLONG: + case MYSQL_TYPE_LONG: + case MYSQL_TYPE_INT24: + case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_TINY: + case MYSQL_TYPE_VARCHAR: + case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_STRING: + break; + default: { + m_use_unoptimized_field_type = true; + } + } + } + + // This is needed so that we can use protocol->send_items and + // item->send + field_item->set_field(field); + + if (m_field_count >= MAX_NOSQL_FIELD_COUNT) { + m_error_msg = "Too many SELECT expressions"; + return true; + } + + m_field_list[m_field_count++] = field; + } + + return false; + } + + bool check_field_name_match(Field *field, const char *field_name) { + return (field->field_name && + !my_strcasecmp(system_charset_info, field->field_name, field_name)); + } + + bool parse_order_by() { + // Extract order ascending vs descending from the order by list + if (m_select_lex->order_list.elements == 0) { + m_is_order_desc = false; + return false; + } + + auto order = m_select_lex->order_list.first; + bool is_first = true; + KEY *key = &m_table->key_info[m_index]; + uint cur_index = key->actual_key_parts; + for (uint i = 0; i < m_select_lex->order_list.elements; ++i) { + Item *item = *(order->item); + if (item->type() != Item::FIELD_ITEM) { + m_error_msg = "ORDER BY should be only using field"; + return true; + } + auto field_item = static_cast(item); + if (is_first) { + m_is_order_desc = (order->direction == ORDER_DESC); + is_first = false; + + // Find the first index + for (uint j = 0; j < key->actual_key_parts; ++j) { + if (check_field_name_match(key->key_part[j].field, + field_item->field_name)) { + cur_index = j; + break; + } + } + + if (cur_index >= key->actual_key_parts) { + m_error_msg = "ORDER BY field doesn't belong to the index"; + return true; + } + } else { + if (m_is_order_desc != (order->direction == ORDER_DESC)) { + // Found a different order + m_error_msg = "ORDER BY should be either ascending or descending"; + return true; + } + + cur_index++; + if (cur_index >= key->actual_key_parts) { + m_error_msg = "ORDER BY field is not in index order"; + return true; + } + + if (!check_field_name_match(key->key_part[cur_index].field, + field_item->field_name)) { + m_error_msg = "ORDER BY is not in index order"; + return true; + } + } + order = order->next; + } + + return false; + } + + bool inline is_constant_bool(Item *op_arg, Item::Type type) { + if (type == Item::FUNC_ITEM) { + auto func_item = static_cast(op_arg); + if (func_item->basic_const_item()) { + // Must be Item_func_true / Item_func_false + return true; + } + } + return false; + } + + bool inline is_supported_op_arg(Item *op_arg) { + auto type = op_arg->type(); + return (type == Item::STRING_ITEM || type == Item::INT_ITEM || + type == Item::REAL_ITEM || type == Item::NULL_ITEM || + type == Item::VARBIN_ITEM || is_constant_bool(op_arg, type)); + } + + bool inline parse_cond(Item_func *func) { + auto type = func->functype(); + if (!is_supported_item_func(type)) { + m_error_msg = "Unsupported WHERE - needs to be >, >=, <, <=, =, IN"; + return true; + } + + const auto args = func->arguments(); + Item_field *field_arg = nullptr; + Item *op_arg = nullptr; + + if (type == Item_func::IN_FUNC) { + // arg0 is always the field + field_arg = static_cast(args[0]); + auto in_func = static_cast(func); + for (uint i = 1; i < in_func->argument_count(); ++i) { + if (!is_supported_op_arg(args[i])) { + // Make sure the field has supported type + // Where as for values we convert them to the correct type just + // like MySQL + m_error_msg = + "Unsupported WHERE - operand should be " + "int/string/real/varbinary"; + return true; + } + } + } else { + // Extract the field and operand, such as A > 0 + if (args[0]->type() == Item::FIELD_ITEM) { + field_arg = static_cast(args[0]); + op_arg = args[1]; + } else if (args[1]->type() == Item::FIELD_ITEM) { + field_arg = static_cast(args[1]); + op_arg = args[0]; + } else { + m_error_msg = "Unsupported WHERE - should only reference field"; + return true; + } + + if (!is_supported_op_arg(op_arg)) { + m_error_msg = + "Unsupported WHERE - operand should be " + "int/string/real/varbinary"; + return true; + } + } + + // Locate the field + auto field_name = field_arg->field_name; + uint field_index = field_arg->field_index; + Field *found = find_field_in_table(m_table, field_name, strlen(field_name), + false, &field_index); + if (!found) { + snprintf(m_error_msg_buf, sizeof(m_error_msg_buf) / sizeof(char), + "Unrecognized field name: '%s'", field_name); + m_error_msg = m_error_msg_buf; + return true; + } + + // TAO-specific optimizations to remove redundant time >= 0 and time <= + // UINT32_MAX. Once TAO removes those unnecessary WHERE we can take + // these out + if (found->is_flag_set(UNSIGNED_FLAG) && found->type() == MYSQL_TYPE_LONG) { + DBUG_ASSERT(op_arg != nullptr); + if (type == Item_func::GE_FUNC && op_arg->val_int() == 0) { + // unsigned A >= 0 - we can skip this one + return false; + } + + if (type == Item_func::LE_FUNC && + op_arg->val_uint() == std::numeric_limits::max()) { + // unsigned A <= UINT32_MAX - we can skip this one + return false; + } + } + + // Let MySQL know about the field so that we can evaluate the conditional + // expression later + field_arg->set_field(found); + + if (m_cond_count >= MAX_NOSQL_COND_COUNT) { + m_error_msg = "Too many WHERE expressions"; + return true; + } + + if (type == Item_func::IN_FUNC) { + // In the case of IN func, we use the actual Item_func_in as it contain + // the list of items + m_cond_list[m_cond_count++] = {type, found, func, nullptr}; + } else { + DBUG_ASSERT(op_arg != nullptr); + m_cond_list[m_cond_count++] = {type, found, func, op_arg}; + } + + return false; + } + + const char *where_err_msg = + "Unsupported WHERE: should be expr [(AND expr)*] where expr only " + "contains >, >=, <, <=, =, IN"; + + bool parse_where() { + auto where = m_select_lex->where_cond(); + if (where == nullptr) { + m_error_msg = where_err_msg; + return true; + } + + // We only allow pure conjunctive where clauses such as A=1 AND B=2 + auto where_type = where->type(); + if (where_type == Item::COND_ITEM) { + Item_cond *where_cond = static_cast(where); + if (where_cond->functype() != Item_func::COND_AND_FUNC) { + m_error_msg = where_err_msg; + return true; + } + + Item_cond_and *and_cond = static_cast(where); + List *and_list = and_cond->argument_list(); + Item *item; + List_iterator_fast li(*and_list); + while ((item = li++)) { + if (item->type() != Item::FUNC_ITEM) { + m_error_msg = where_err_msg; + return true; + } + if (parse_cond(static_cast(item))) { + return true; + } + } + } else if (where_type == Item::FUNC_ITEM) { + if (parse_cond(static_cast(where))) { + return true; + } + } else { + m_error_msg = where_err_msg; + return true; + } + + return false; + } + + bool parse_limit() { + // NOTE: We can't rely on explicit_limit as execute_sqlcom_select may + // assign one using the global parameters + if (m_select_lex->select_limit) { + if (m_select_lex->select_limit->type() != Item::INT_ITEM || + !m_select_lex->select_limit->unsigned_flag) { + m_error_msg = "Unexpected LIMIT - must be unsigned integer"; + return true; + } + + m_select_limit = m_select_lex->select_limit->val_uint(); + } else { + m_select_limit = std::numeric_limits::max(); + } + + if (m_select_lex->offset_limit) { + if (m_select_lex->offset_limit->type() != Item::INT_ITEM || + !m_select_lex->offset_limit->unsigned_flag) { + m_error_msg = "Unexpected LIMIT offset - must be unsigned integer"; + return true; + } + + m_offset_limit = m_select_lex->offset_limit->val_uint(); + } else { + m_offset_limit = 0; + } + + return false; + } +}; + +} // namespace + +bool inline is_bypass_on(SELECT_LEX *select_lex) { + uint32_t policy = get_select_bypass_policy(); + + if ((policy & SELECT_BYPASS_POLICY_DEFAULT_MASK) == 0) { + // Force on/off ignoring statement level hint + return (policy & SELECT_BYPASS_POLICY_ON_MASK); + } + + if (select_lex->select_bypass_hint == + SELECT_LEX::SELECT_BYPASS_HINT_DEFAULT) { + // Whether it is FORCE / DEFAULT mode, ON/OFF MASK gives the right answer + // if no hint is given + return (policy & SELECT_BYPASS_POLICY_ON_MASK); + } + + return (select_lex->select_bypass_hint == SELECT_LEX::SELECT_BYPASS_HINT_ON); +} + +bool rocksdb_handle_single_table_select(THD *thd, SELECT_LEX *select_lex) { + // Checks for hint and policy + if (!is_bypass_on(select_lex)) { + // Fallback to MySQL + return false; + } + + // Parse the SELECT statement + select_parser select_stmt(thd, select_lex); + if (select_stmt.parse()) { + rocksdb_select_bypass_rejected++; + + if (should_log_rejected_select_bypass()) { + // NO_LINT_DEBUG + sql_print_information("[REJECTED_BYPASS_QUERY] Query='%s', Reason='%s'\n", + thd->query().str, select_stmt.get_error_msg()); + } + + // During parse you can just let unsupported scenario fallback to MySQL + // implementation - but keep in mind it may regress performance + // Default is TRUE - let unsupported SELECT scenario just fail + if (should_fail_unsupported_select_bypass()) { + const char *error_msg = select_stmt.get_error_msg(); + my_printf_error(ER_NOT_SUPPORTED_YET, + "SELECT statement pattern not supported: %s", MYF(0), + error_msg); + return true; + } else { + return false; + } + } + + if (!thd->lex->is_query_tables_locked()) { + /* + If tables are not locked at this point, it means that we have delayed + this step until after prepare stage (i.e. this moment). This allows to + do better partition pruning and avoid locking unused partitions. + As a consequence, in such a case, prepare stage can rely only on + metadata about tables used and not data from them. + We need to lock tables now in order to proceed with the remaning + stages of query optimization and execution. + */ + if (lock_tables(thd, thd->lex->query_tables, thd->lex->table_count, 0)) { + DBUG_ASSERT(thd->is_error()); + return true; + } + } + + // Temporary code that dumps out everything before actual execution code + // is fully ported + // This generates a table with a single column "DUMP" + auto protocol = thd->get_protocol(); + + // Dump out the extracted string for diagnostic purpose + mem_root_deque field_list(thd->mem_root); + field_list.push_back(new Item_empty_string("Dump", 65535)); + if (thd->send_result_metadata(field_list, + Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) { + return true; + } + + protocol->start_row(); + std::string str = select_stmt.dump(); + if (protocol->store_string(str.c_str(), str.length(), system_charset_info)) { + return true; + } + + if (protocol->end_row()) { + return true; + } + + my_eof(thd); + + rocksdb_select_bypass_executed++; + + return true; } } // namespace myrocks diff --git a/storage/rocksdb/rdb_global.h b/storage/rocksdb/rdb_global.h index d73c806ba6c8..22d0b304b8ba 100644 --- a/storage/rocksdb/rdb_global.h +++ b/storage/rocksdb/rdb_global.h @@ -30,6 +30,13 @@ /* MyRocks headers */ #include "./ut0counter.h" +/* + When taking measurements, replace this with __attribute__ ((noinline)) + This is used in performance critical functions to make doing CPU + profiling easier + */ +#define INLINE_ATTR + namespace myrocks { /* * class for exporting transaction information for @@ -203,6 +210,28 @@ const char *const RDB_TTL_COL_QUALIFIER = "ttl_col"; */ #define DEFAULT_SST_MGR_RATE_BYTES_PER_SEC 0 +/* + SELECT BYPASS related policy: + 0x1 = ON/OFF MASK - whether bypass is on or off + 0x2 = FORCED/DEFAULT MASK, whether the ON/OFF bit is being FORCED (0x0) + or simply inteneded as DEFAULT (0x1). + + This effectively means: + + ALWAYS_OFF = 0x0, always off regardless of hint. This is the default + ALWAYS_ON = 0x1, always on regardless of hint + OPT_IN = 0x2, default off, turn on with +bypass hint + OPT_OUT = 0x3, default on, turn off with +no_bypass hint + */ +#define SELECT_BYPASS_POLICY_ON_MASK 0x1 +#define SELECT_BYPASS_POLICY_DEFAULT_MASK 0x2 +#define SELECT_BYPASS_POLICY_ALWAYS_OFF 0x0 +#define SELECT_BYPASS_POLICY_OPT_IN SELECT_BYPASS_POLICY_DEFAULT_MASK +#define SELECT_BYPASS_POLICY_OPT_OUT \ + (SELECT_BYPASS_POLICY_DEFAULT_MASK | SELECT_BYPASS_POLICY_ON_MASK) +#define SELECT_BYPASS_POLICY_ALWAYS_ON SELECT_BYPASS_POLICY_ON_MASK +#define SELECT_BYPASS_POLICY_DEFAULT SELECT_BYPASS_POLICY_ALWAYS_OFF + /* Defines the field sizes for serializing XID object to a string representation. string byte format: [field_size: field_value, ...]