mirror of
https://github.com/MariaDB/server.git
synced 2025-01-19 13:32:33 +01:00
3600d09ab4
The main idea is to exploit the fact that key scans for "key=const" return ordered sequences of rowids. include/my_base.h: Added HA_EXTRA_KEYREAD_PRESERVE_FIELDS flag include/my_bitmap.h: Added a couple of utility functions include/my_sys.h: Added my_conunt_bits_ushort function innobase/include/row0mysql.h: Added support for HA_EXTRA_KEYREAD_PRESERVE_FIELDS innobase/row/row0sel.c: Added support for HA_EXTRA_KEYREAD_PRESERVE_FIELDS mysys/my_bit.c: Added my_count_bits_ushort function mysys/my_bitmap.c: Added a couple of utility functions sql/ha_berkeley.cc: Added cmp_ref rowid comparison function. sql/ha_berkeley.h: Added cmp_ref rowid comparison function. sql/ha_heap.h: Added cmp_ref rowid comparison function. sql/ha_innodb.cc: Added cmp_ref rowid comparison function and support from HA_EXTRA_KEYREAD_PRESERVE_FIELDS sql/ha_innodb.h: Added cmp_ref rowid comparison function. sql/handler.h: Added cmp_ref rowid comparison function. sql/opt_range.cc: Added QUICK_ROR_{INTERSECT,UNION}_SELECT classes and related optimizer code sql/opt_range.h: Added QUICK_ROR_{INTERSECT,UNION}_SELECT classes sql/sql_delete.cc: Changed to use new ROWID comparison function also always call quick->reset() for quick selects sql/sql_select.cc: Account for new quick select types sql/sql_select.h: New, proper rowid ordering/comparison function to be used with Unique class etc. sql/sql_test.cc: Account for new quick select types sql/sql_update.cc: Account for new quick select types
168 lines
10 KiB
Text
168 lines
10 KiB
Text
drop table if exists t1,t0;
|
|
select count(*) from t1;
|
|
count(*)
|
|
64801
|
|
explain select key1,key2 from t1 where key1=100 and key2=100;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge key1,key2 key1,key2 5,5 NULL 3 Using where; Using index
|
|
select key1,key2 from t1 where key1=100 and key2=100;
|
|
key1 key2
|
|
100 100
|
|
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge key1,key2,key3,key4 key1,key2,key3,key4 5,5,5,5 NULL 8 Using where
|
|
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
|
|
key1 key2 key3 key4 filler1
|
|
100 100 100 100 key1-key2-key3-key4
|
|
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, -1, -1, 'key1-key2');
|
|
insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, 100, 100, 'key4-key3');
|
|
explain select key1,key2,filler1 from t1 where key1=100 and key2=100;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge key1,key2 key1,key2 5,5 NULL 3 Using where
|
|
select key1,key2,filler1 from t1 where key1=100 and key2=100;
|
|
key1 key2 filler1
|
|
100 100 key1-key2-key3-key4
|
|
100 100 key1-key2
|
|
explain select key1,key2 from t1 where key1=100 and key2=100;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge key1,key2 key1,key2 5,5 NULL 3 Using where; Using index
|
|
select key1,key2 from t1 where key1=100 and key2=100;
|
|
key1 key2
|
|
100 100
|
|
100 100
|
|
explain select key1,key2,key3,key4 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge key1,key2,key3,key4 key1,key2,key3,key4 5,5,5,5 NULL 8 Using where
|
|
select key1,key2,key3,key4 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
|
|
key1 key2 key3 key4
|
|
100 100 100 100
|
|
100 100 -1 -1
|
|
-1 -1 100 100
|
|
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge key1,key2,key3,key4 key1,key2,key3,key4 5,5,5,5 NULL 8 Using where
|
|
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
|
|
key1 key2 key3 key4 filler1
|
|
100 100 100 100 key1-key2-key3-key4
|
|
100 100 -1 -1 key1-key2
|
|
-1 -1 100 100 key4-key3
|
|
explain select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge key1,key2,key3 key1,key2,key3 5,5,5 NULL 1 Using where; Using index
|
|
select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100;
|
|
key1 key2 key3
|
|
100 100 100
|
|
insert into t1 (key1,key2,key3,key4,filler1) values (101,101,101,101, 'key1234-101');
|
|
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=101;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge key1,key2,key3 key1,key2,key3 5,5,5 NULL 5 Using where
|
|
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=101;
|
|
key1 key2 key3 key4 filler1
|
|
100 100 100 100 key1-key2-key3-key4
|
|
100 100 -1 -1 key1-key2
|
|
101 101 101 101 key1234-101
|
|
select key1,key2, filler1 from t1 where key1=100 and key2=100;
|
|
key1 key2 filler1
|
|
100 100 key1-key2-key3-key4
|
|
100 100 key1-key2
|
|
update t1 set filler1='to be deleted' where key1=100 and key2=100;
|
|
update t1 set key1=200,key2=200 where key1=100 and key2=100;
|
|
delete from t1 where key1=200 and key2=200;
|
|
select key1,key2,filler1 from t1 where key2=100 and key2=200;
|
|
key1 key2 filler1
|
|
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge key1,key2,key3,key4 key1,key2,key3,key4 5,5,5,5 NULL 8 Using where
|
|
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
|
|
key1 key2 key3 key4 filler1
|
|
-1 -1 100 100 key4-key3
|
|
delete from t1 where key3=100 and key4=100;
|
|
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge key1,key2,key3,key4 key1,key2,key3,key4 5,5,5,5 NULL 8 Using where
|
|
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
|
|
key1 key2 key3 key4 filler1
|
|
explain select key1,key2 from t1 where key1=100 and key2=100;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge key1,key2 key1,key2 5,5 NULL 3 Using where; Using index
|
|
select key1,key2 from t1 where key1=100 and key2=100;
|
|
key1 key2
|
|
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 200, 200,'key1-key2-key3-key4-1');
|
|
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 200, 200,'key1-key2-key3-key4-2');
|
|
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 200, 200,'key1-key2-key3-key4-3');
|
|
explain select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge key1,key2,key3,key4 key3,key1,key2,key4 5,5,5,5 NULL 16 Using where
|
|
select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
|
|
key1 key2 key3 key4 filler1
|
|
100 100 200 200 key1-key2-key3-key4-3
|
|
100 100 200 200 key1-key2-key3-key4-2
|
|
100 100 200 200 key1-key2-key3-key4-1
|
|
insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, -1, 200,'key4');
|
|
explain select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge key1,key2,key3,key4 key3,key1,key2,key4 5,5,5,5 NULL 18 Using where
|
|
select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
|
|
key1 key2 key3 key4 filler1
|
|
100 100 200 200 key1-key2-key3-key4-3
|
|
100 100 200 200 key1-key2-key3-key4-2
|
|
100 100 200 200 key1-key2-key3-key4-1
|
|
-1 -1 -1 200 key4
|
|
insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, 200, -1,'key3');
|
|
explain select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge key1,key2,key3,key4 key3,key1,key2,key4 5,5,5,5 NULL 20 Using where
|
|
select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
|
|
key1 key2 key3 key4 filler1
|
|
100 100 200 200 key1-key2-key3-key4-3
|
|
100 100 200 200 key1-key2-key3-key4-2
|
|
100 100 200 200 key1-key2-key3-key4-1
|
|
-1 -1 -1 200 key4
|
|
-1 -1 200 -1 key3
|
|
explain select * from t1 where st_a=1 and st_b=1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,st_a,stb_swt1a_2b,stb_swt1b,st_b st_a,st_b 4,4 NULL 2508 Using where
|
|
explain select st_a,st_b from t1 where st_a=1 and st_b=1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,st_a,stb_swt1a_2b,stb_swt1b,st_b st_a,st_b 4,4 NULL 2508 Using where; Using index
|
|
explain select st_a from t1 ignore index (st_a) where st_a=1 and st_b=1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 ref sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,stb_swt1a_2b,stb_swt1b,st_b st_b 4 const 14720 Using where
|
|
explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 ref sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,st_a sta_swt12a 12 const,const,const 958 Using where
|
|
explain select * from t1 where st_b=1 and swt1b=1 and swt2b=1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 ref stb_swt1a_2b,stb_swt1b,st_b stb_swt1b 8 const,const 3757 Using where
|
|
explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,st_a,stb_swt1a_2b,stb_swt1b,st_b sta_swt12a,stb_swt1a_2b 12,12 NULL 42 Using where
|
|
explain select * from t1 ignore index (sta_swt21a, stb_swt1a_2b)
|
|
where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge sta_swt12a,sta_swt1a,sta_swt2a,st_a,stb_swt1b,st_b sta_swt12a,stb_swt1b 12,8 NULL 42 Using where
|
|
explain select * from t1 ignore index (sta_swt21a, sta_swt12a, stb_swt1a_2b)
|
|
where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge sta_swt1a,sta_swt2a,st_a,stb_swt1b,st_b sta_swt1a,stb_swt1b 8,8 NULL 163 Using where
|
|
explain select * from t1 ignore index (sta_swt21a, sta_swt12a, stb_swt1a_2b, stb_swt1b)
|
|
where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge sta_swt1a,sta_swt2a,st_a,st_b sta_swt1a,st_b 8,4 NULL 640 Using where
|
|
explain select * from t1
|
|
where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,st_a,stb_swt1a_2b,stb_swt1b,st_b sta_swt12a,stb_swt1a_2b 12,12 NULL 42 Using where
|
|
explain select * from t1
|
|
where st_a=1 and swt1a=1 and st_b=1 and swt1b=1 and swt1b=1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,st_a,stb_swt1a_2b,stb_swt1b,st_b sta_swt1a,stb_swt1b 8,8 NULL 163 Using where
|
|
explain select st_a from t1
|
|
where st_a=1 and swt1a=1 and st_b=1 and swt1b=1 and swt1b=1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,st_a,stb_swt1a_2b,stb_swt1b,st_b sta_swt1a,stb_swt1b 8,8 NULL 163 Using where; Using index
|
|
explain select st_a from t1
|
|
where st_a=1 and swt1a=1 and st_b=1 and swt1b=1 and swt1b=1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index_merge sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,st_a,stb_swt1a_2b,stb_swt1b,st_b sta_swt1a,stb_swt1b 8,8 NULL 163 Using where; Using index
|
|
drop table t0,t1;
|