Commit 63f78fa8 authored by Igor Babaev's avatar Igor Babaev

Merge

parents 511b53ab 6f2db629
...@@ -30,7 +30,17 @@ extern "C" { ...@@ -30,7 +30,17 @@ extern "C" {
#define tree_set_pointer(element,ptr) *((uchar **) (element+1))=((uchar*) (ptr)) #define tree_set_pointer(element,ptr) *((uchar **) (element+1))=((uchar*) (ptr))
/*
A tree with its flag set to TREE_ONLY_DUPS behaves differently on inserting
an element that is not in the tree:
the element is not added at all, but instead tree_insert() returns a special
address TREE_ELEMENT_UNIQUE as an indication that the function has not failed
due to lack of memory.
*/
#define TREE_ELEMENT_UNIQUE ((TREE_ELEMENT *) 1)
#define TREE_NO_DUPS 1 #define TREE_NO_DUPS 1
#define TREE_ONLY_DUPS 2
typedef enum { left_root_right, right_root_left } TREE_WALK; typedef enum { left_root_right, right_root_left } TREE_WALK;
typedef uint32 element_count; typedef uint32 element_count;
......
...@@ -539,7 +539,7 @@ INSERT INTO t1 SELECT * FROM t1; ...@@ -539,7 +539,7 @@ INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1; INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1; INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1; INSERT INTO t1 SELECT * FROM t1;
SET SESSION sort_buffer_size=1; SET SESSION sort_buffer_size=1024*8;
EXPLAIN EXPLAIN
SELECT * FROM t1 FORCE INDEX(a,b) WHERE a LIKE 'a%' OR b LIKE 'b%' SELECT * FROM t1 FORCE INDEX(a,b) WHERE a LIKE 'a%' OR b LIKE 'b%'
ORDER BY a,b; ORDER BY a,b;
......
This diff is collapsed.
This diff is collapsed.
set @optimizer_switch_save= @@optimizer_switch;
set optimizer_switch='index_merge_sort_intersection=off';
#---------------- Index merge test 2 ------------------------------------------- #---------------- Index merge test 2 -------------------------------------------
SET SESSION STORAGE_ENGINE = InnoDB; SET SESSION STORAGE_ENGINE = InnoDB;
drop table if exists t1,t2; drop table if exists t1,t2;
...@@ -709,3 +711,4 @@ WHERE a BETWEEN 2 AND 7 OR pk=1000000) AS t; ...@@ -709,3 +711,4 @@ WHERE a BETWEEN 2 AND 7 OR pk=1000000) AS t;
COUNT(*) COUNT(*)
6145 6145
DROP TABLE t1; DROP TABLE t1;
set optimizer_switch= @optimizer_switch_save;
set @optimizer_switch_save= @@optimizer_switch;
set optimizer_switch='index_merge_sort_intersection=off';
#---------------- Index merge test 1 ------------------------------------------- #---------------- Index merge test 1 -------------------------------------------
SET SESSION STORAGE_ENGINE = MyISAM; SET SESSION STORAGE_ENGINE = MyISAM;
drop table if exists t0, t1, t2, t3, t4; drop table if exists t0, t1, t2, t3, t4;
...@@ -569,9 +571,7 @@ INSERT INTO t1 SELECT * FROM t1; ...@@ -569,9 +571,7 @@ INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1; INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1; INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1; INSERT INTO t1 SELECT * FROM t1;
SET SESSION sort_buffer_size=1; SET SESSION sort_buffer_size=1024*8;
Warnings:
Warning 1292 Truncated incorrect sort_buffer_size value: '1'
EXPLAIN EXPLAIN
SELECT * FROM t1 FORCE INDEX(a,b) WHERE a LIKE 'a%' OR b LIKE 'b%' SELECT * FROM t1 FORCE INDEX(a,b) WHERE a LIKE 'a%' OR b LIKE 'b%'
ORDER BY a,b; ORDER BY a,b;
...@@ -1494,19 +1494,19 @@ DROP TABLE t1,t2; ...@@ -1494,19 +1494,19 @@ DROP TABLE t1,t2;
# #
select @@optimizer_switch; select @@optimizer_switch;
@@optimizer_switch @@optimizer_switch
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off
set optimizer_switch='index_merge=off,index_merge_union=off'; set optimizer_switch='index_merge=off,index_merge_union=off';
select @@optimizer_switch; select @@optimizer_switch;
@@optimizer_switch @@optimizer_switch
index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=on index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off
set optimizer_switch='index_merge_union=on'; set optimizer_switch='index_merge_union=on';
select @@optimizer_switch; select @@optimizer_switch;
@@optimizer_switch @@optimizer_switch
index_merge=off,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on index_merge=off,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off
set optimizer_switch='default,index_merge_sort_union=off'; set optimizer_switch='default,index_merge_sort_union=off';
select @@optimizer_switch; select @@optimizer_switch;
@@optimizer_switch @@optimizer_switch
index_merge=on,index_merge_union=on,index_merge_sort_union=off,index_merge_intersection=on index_merge=on,index_merge_union=on,index_merge_sort_union=off,index_merge_intersection=on,index_merge_sort_intersection=off
set optimizer_switch=4; set optimizer_switch=4;
ERROR 42000: Variable 'optimizer_switch' can't be set to the value of '4' ERROR 42000: Variable 'optimizer_switch' can't be set to the value of '4'
set optimizer_switch=NULL; set optimizer_switch=NULL;
...@@ -1533,21 +1533,21 @@ set optimizer_switch=default; ...@@ -1533,21 +1533,21 @@ set optimizer_switch=default;
set optimizer_switch='index_merge=off,index_merge_union=off,default'; set optimizer_switch='index_merge=off,index_merge_union=off,default';
select @@optimizer_switch; select @@optimizer_switch;
@@optimizer_switch @@optimizer_switch
index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=on index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off
set optimizer_switch=default; set optimizer_switch=default;
select @@global.optimizer_switch; select @@global.optimizer_switch;
@@global.optimizer_switch @@global.optimizer_switch
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off
set @@global.optimizer_switch=default; set @@global.optimizer_switch=default;
select @@global.optimizer_switch; select @@global.optimizer_switch;
@@global.optimizer_switch @@global.optimizer_switch
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off
# #
# Check index_merge's @@optimizer_switch flags # Check index_merge's @@optimizer_switch flags
# #
select @@optimizer_switch; select @@optimizer_switch;
@@optimizer_switch @@optimizer_switch
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off
create table t0 (a int); create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 (a int, b int, c int, filler char(100), create table t1 (a int, b int, c int, filler char(100),
...@@ -1624,7 +1624,7 @@ explain select * from t1 where a=10 and b=10; ...@@ -1624,7 +1624,7 @@ explain select * from t1 where a=10 and b=10;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref a,b a 5 const 49 Using where 1 SIMPLE t1 ref a,b a 5 const 49 Using where
No intersect if it is disabled: No intersect if it is disabled:
set optimizer_switch='default,index_merge_intersection=off'; set optimizer_switch='default,index_merge_sort_intersection=off,index_merge_intersection=off';
explain select * from t1 where a=10 and b=10; explain select * from t1 where a=10 and b=10;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref a,b a 5 const 49 Using where 1 SIMPLE t1 ref a,b a 5 const 49 Using where
...@@ -1657,5 +1657,6 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -1657,5 +1657,6 @@ id select_type table type possible_keys key key_len ref rows Extra
set optimizer_switch=default; set optimizer_switch=default;
show variables like 'optimizer_switch'; show variables like 'optimizer_switch';
Variable_name Value Variable_name Value
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off
drop table t0, t1; drop table t0, t1;
set optimizer_switch= @optimizer_switch_save;
...@@ -1421,9 +1421,9 @@ DROP TABLE t1; ...@@ -1421,9 +1421,9 @@ DROP TABLE t1;
# #
create table t1(a int, b tinytext); create table t1(a int, b tinytext);
insert into t1 values (1,2),(3,2); insert into t1 values (1,2),(3,2);
set session sort_buffer_size= 30000; set session sort_buffer_size= 1000;
Warnings: Warnings:
Warning 1292 Truncated incorrect sort_buffer_size value: '30000' Warning 1292 Truncated incorrect sort_buffer_size value: '1000'
set session max_sort_length= 2180; set session max_sort_length= 2180;
select * from t1 order by b; select * from t1 order by b;
ERROR HY001: Out of sort memory; increase server sort buffer size ERROR HY001: Out of sort memory; increase server sort buffer size
......
...@@ -38,6 +38,7 @@ SELECT COUNT(*) FROM CountryLanguage; ...@@ -38,6 +38,7 @@ SELECT COUNT(*) FROM CountryLanguage;
COUNT(*) COUNT(*)
984 984
CREATE INDEX Name ON City(Name); CREATE INDEX Name ON City(Name);
set session optimizer_switch='index_merge_sort_intersection=off';
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE (Population >= 100000 OR Name LIKE 'P%' OR Population < 100000); WHERE (Population >= 100000 OR Name LIKE 'P%' OR Population < 100000);
...@@ -1366,3 +1367,4 @@ f1 f2 f3 f4 ...@@ -1366,3 +1367,4 @@ f1 f2 f3 f4
9 0 2 6 9 0 2 6
SET SESSION optimizer_switch=DEFAULT; SET SESSION optimizer_switch=DEFAULT;
DROP TABLE t1; DROP TABLE t1;
set session optimizer_switch='index_merge_sort_intersection=default';
...@@ -39,6 +39,7 @@ SELECT COUNT(*) FROM CountryLanguage; ...@@ -39,6 +39,7 @@ SELECT COUNT(*) FROM CountryLanguage;
COUNT(*) COUNT(*)
984 984
CREATE INDEX Name ON City(Name); CREATE INDEX Name ON City(Name);
set session optimizer_switch='index_merge_sort_intersection=off';
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE (Population >= 100000 OR Name LIKE 'P%' OR Population < 100000); WHERE (Population >= 100000 OR Name LIKE 'P%' OR Population < 100000);
...@@ -1367,4 +1368,5 @@ f1 f2 f3 f4 ...@@ -1367,4 +1368,5 @@ f1 f2 f3 f4
9 0 2 6 9 0 2 6
SET SESSION optimizer_switch=DEFAULT; SET SESSION optimizer_switch=DEFAULT;
DROP TABLE t1; DROP TABLE t1;
set session optimizer_switch='index_merge_sort_intersection=default';
SET SESSION STORAGE_ENGINE=DEFAULT; SET SESSION STORAGE_ENGINE=DEFAULT;
...@@ -3667,8 +3667,6 @@ CREATE TABLE t1 (a int, b int auto_increment, PRIMARY KEY (b)); ...@@ -3667,8 +3667,6 @@ CREATE TABLE t1 (a int, b int auto_increment, PRIMARY KEY (b));
CREATE TABLE t2 (x int auto_increment, y int, z int, CREATE TABLE t2 (x int auto_increment, y int, z int,
PRIMARY KEY (x), FOREIGN KEY (y) REFERENCES t1 (b)); PRIMARY KEY (x), FOREIGN KEY (y) REFERENCES t1 (b));
SET SESSION sort_buffer_size = 32 * 1024; SET SESSION sort_buffer_size = 32 * 1024;
Warnings:
Warning 1292 Truncated incorrect sort_buffer_size value: '32768'
SELECT SQL_NO_CACHE COUNT(*) SELECT SQL_NO_CACHE COUNT(*)
FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c
FROM t1) t; FROM t1) t;
...@@ -4104,8 +4102,6 @@ INSERT INTO `t1` VALUES ('asdf','2007-02-08 01:11:26'); ...@@ -4104,8 +4102,6 @@ INSERT INTO `t1` VALUES ('asdf','2007-02-08 01:11:26');
INSERT INTO `t2` VALUES ('abcdefghijk'); INSERT INTO `t2` VALUES ('abcdefghijk');
INSERT INTO `t2` VALUES ('asdf'); INSERT INTO `t2` VALUES ('asdf');
SET session sort_buffer_size=8192; SET session sort_buffer_size=8192;
Warnings:
Warning 1292 Truncated incorrect sort_buffer_size value: '8192'
SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.a ORDER BY t1.b LIMIT 1) AS d1 FROM t2; SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.a ORDER BY t1.b LIMIT 1) AS d1 FROM t2;
d1 d1
1 1
......
...@@ -971,6 +971,7 @@ tmpdir # ...@@ -971,6 +971,7 @@ tmpdir #
select * from information_schema.session_variables where variable_name like 'tmpdir'; select * from information_schema.session_variables where variable_name like 'tmpdir';
VARIABLE_NAME VARIABLE_VALUE VARIABLE_NAME VARIABLE_VALUE
TMPDIR # TMPDIR #
set sort_buffer_size=1024*8;
select @@ssl_ca, @@ssl_capath, @@ssl_cert, @@ssl_cipher, @@ssl_key; select @@ssl_ca, @@ssl_capath, @@ssl_cert, @@ssl_cipher, @@ssl_key;
@@ssl_ca @@ssl_capath @@ssl_cert @@ssl_cipher @@ssl_key @@ssl_ca @@ssl_capath @@ssl_cert @@ssl_cipher @@ssl_key
# # # # # # # # # #
......
...@@ -679,8 +679,6 @@ INSERT INTO t1(b,c) SELECT b,c FROM t2; ...@@ -679,8 +679,6 @@ INSERT INTO t1(b,c) SELECT b,c FROM t2;
UPDATE t2 SET c='2007-01-03'; UPDATE t2 SET c='2007-01-03';
INSERT INTO t1(b,c) SELECT b,c FROM t2; INSERT INTO t1(b,c) SELECT b,c FROM t2;
set @@sort_buffer_size=8192; set @@sort_buffer_size=8192;
Warnings:
Warning 1292 Truncated incorrect sort_buffer_size value: '8192'
SELECT COUNT(*) FROM t1; SELECT COUNT(*) FROM t1;
COUNT(*) COUNT(*)
3072 3072
......
...@@ -679,8 +679,6 @@ INSERT INTO t1(b,c) SELECT b,c FROM t2; ...@@ -679,8 +679,6 @@ INSERT INTO t1(b,c) SELECT b,c FROM t2;
UPDATE t2 SET c='2007-01-03'; UPDATE t2 SET c='2007-01-03';
INSERT INTO t1(b,c) SELECT b,c FROM t2; INSERT INTO t1(b,c) SELECT b,c FROM t2;
set @@sort_buffer_size=8192; set @@sort_buffer_size=8192;
Warnings:
Warning 1292 Truncated incorrect sort_buffer_size value: '8192'
SELECT COUNT(*) FROM t1; SELECT COUNT(*) FROM t1;
COUNT(*) COUNT(*)
3072 3072
......
...@@ -3667,8 +3667,6 @@ CREATE TABLE t1 (a int, b int auto_increment, PRIMARY KEY (b)); ...@@ -3667,8 +3667,6 @@ CREATE TABLE t1 (a int, b int auto_increment, PRIMARY KEY (b));
CREATE TABLE t2 (x int auto_increment, y int, z int, CREATE TABLE t2 (x int auto_increment, y int, z int,
PRIMARY KEY (x), FOREIGN KEY (y) REFERENCES t1 (b)); PRIMARY KEY (x), FOREIGN KEY (y) REFERENCES t1 (b));
SET SESSION sort_buffer_size = 32 * 1024; SET SESSION sort_buffer_size = 32 * 1024;
Warnings:
Warning 1292 Truncated incorrect sort_buffer_size value: '32768'
SELECT SQL_NO_CACHE COUNT(*) SELECT SQL_NO_CACHE COUNT(*)
FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c
FROM t1) t; FROM t1) t;
...@@ -4104,8 +4102,6 @@ INSERT INTO `t1` VALUES ('asdf','2007-02-08 01:11:26'); ...@@ -4104,8 +4102,6 @@ INSERT INTO `t1` VALUES ('asdf','2007-02-08 01:11:26');
INSERT INTO `t2` VALUES ('abcdefghijk'); INSERT INTO `t2` VALUES ('abcdefghijk');
INSERT INTO `t2` VALUES ('asdf'); INSERT INTO `t2` VALUES ('asdf');
SET session sort_buffer_size=8192; SET session sort_buffer_size=8192;
Warnings:
Warning 1292 Truncated incorrect sort_buffer_size value: '8192'
SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.a ORDER BY t1.b LIMIT 1) AS d1 FROM t2; SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.a ORDER BY t1.b LIMIT 1) AS d1 FROM t2;
d1 d1
1 1
......
This diff is collapsed.
--source include/have_innodb.inc
SET SESSION STORAGE_ENGINE='InnoDB';
--source t/index_intersect.test
SET SESSION STORAGE_ENGINE=DEFAULT;
...@@ -18,6 +18,11 @@ let $engine_type= InnoDB; ...@@ -18,6 +18,11 @@ let $engine_type= InnoDB;
# InnoDB does not support Merge tables (affects include/index_merge1.inc) # InnoDB does not support Merge tables (affects include/index_merge1.inc)
let $merge_table_support= 0; let $merge_table_support= 0;
set @optimizer_switch_save= @@optimizer_switch;
set optimizer_switch='index_merge_sort_intersection=off';
# The first two tests are disabled because of non deterministic explain output. # The first two tests are disabled because of non deterministic explain output.
# If include/index_merge1.inc can be enabled for InnoDB and all other # If include/index_merge1.inc can be enabled for InnoDB and all other
# storage engines, please remove the subtest for Bug#21277 from # storage engines, please remove the subtest for Bug#21277 from
...@@ -84,3 +89,5 @@ SELECT COUNT(*) FROM ...@@ -84,3 +89,5 @@ SELECT COUNT(*) FROM
WHERE a BETWEEN 2 AND 7 OR pk=1000000) AS t; WHERE a BETWEEN 2 AND 7 OR pk=1000000) AS t;
DROP TABLE t1; DROP TABLE t1;
set optimizer_switch= @optimizer_switch_save;
...@@ -14,6 +14,10 @@ let $engine_type= MyISAM; ...@@ -14,6 +14,10 @@ let $engine_type= MyISAM;
# MyISAM supports Merge tables # MyISAM supports Merge tables
let $merge_table_support= 1; let $merge_table_support= 1;
set @optimizer_switch_save= @@optimizer_switch;
set optimizer_switch='index_merge_sort_intersection=off';
--source include/index_merge1.inc --source include/index_merge1.inc
--source include/index_merge_ror.inc --source include/index_merge_ror.inc
--source include/index_merge2.inc --source include/index_merge2.inc
...@@ -164,7 +168,7 @@ set optimizer_switch='default,index_merge=off'; ...@@ -164,7 +168,7 @@ set optimizer_switch='default,index_merge=off';
explain select * from t1 where a=10 and b=10; explain select * from t1 where a=10 and b=10;
--echo No intersect if it is disabled: --echo No intersect if it is disabled:
set optimizer_switch='default,index_merge_intersection=off'; set optimizer_switch='default,index_merge_sort_intersection=off,index_merge_intersection=off';
explain select * from t1 where a=10 and b=10; explain select * from t1 where a=10 and b=10;
--echo Do intersect when union was disabled --echo Do intersect when union was disabled
...@@ -195,3 +199,5 @@ show variables like 'optimizer_switch'; ...@@ -195,3 +199,5 @@ show variables like 'optimizer_switch';
drop table t0, t1; drop table t0, t1;
set optimizer_switch= @optimizer_switch_save;
...@@ -843,7 +843,7 @@ DROP TABLE t1; ...@@ -843,7 +843,7 @@ DROP TABLE t1;
--echo # --echo #
create table t1(a int, b tinytext); create table t1(a int, b tinytext);
insert into t1 values (1,2),(3,2); insert into t1 values (1,2),(3,2);
set session sort_buffer_size= 30000; set session sort_buffer_size= 1000;
set session max_sort_length= 2180; set session max_sort_length= 2180;
--error 1038 --error 1038
select * from t1 order by b; select * from t1 order by b;
......
...@@ -33,6 +33,8 @@ ANALYZE TABLE City; ...@@ -33,6 +33,8 @@ ANALYZE TABLE City;
--enable_result_log --enable_result_log
--enable_query_log --enable_query_log
set session optimizer_switch='index_merge_sort_intersection=off';
# The following 4 queries are added for code coverage # The following 4 queries are added for code coverage
#the exptected # of rows differ on 32-bit and 64-bit platforms for innodb #the exptected # of rows differ on 32-bit and 64-bit platforms for innodb
...@@ -1007,3 +1009,6 @@ SELECT * FROM t1 FORCE KEY (PRIMARY,f3,f4) ...@@ -1007,3 +1009,6 @@ SELECT * FROM t1 FORCE KEY (PRIMARY,f3,f4)
SET SESSION optimizer_switch=DEFAULT; SET SESSION optimizer_switch=DEFAULT;
DROP TABLE t1; DROP TABLE t1;
#the following command must be the last one in the file
set session optimizer_switch='index_merge_sort_intersection=default';
...@@ -736,6 +736,7 @@ select * from information_schema.session_variables where variable_name like 'tmp ...@@ -736,6 +736,7 @@ select * from information_schema.session_variables where variable_name like 'tmp
# Bug #19606: make ssl settings available via SHOW VARIABLES and @@variables # Bug #19606: make ssl settings available via SHOW VARIABLES and @@variables
# #
# Don't actually output, since it depends on the system # Don't actually output, since it depends on the system
set sort_buffer_size=1024*8;
--replace_column 1 # 2 # 3 # 4 # 5 # --replace_column 1 # 2 # 3 # 4 # 5 #
select @@ssl_ca, @@ssl_capath, @@ssl_cert, @@ssl_cipher, @@ssl_key; select @@ssl_ca, @@ssl_capath, @@ssl_cert, @@ssl_cipher, @@ssl_key;
--replace_column 2 # --replace_column 2 #
......
...@@ -221,6 +221,8 @@ TREE_ELEMENT *tree_insert(TREE *tree, void *key, uint key_size, ...@@ -221,6 +221,8 @@ TREE_ELEMENT *tree_insert(TREE *tree, void *key, uint key_size,
} }
if (element == &tree->null_element) if (element == &tree->null_element)
{ {
if (tree->flag & TREE_ONLY_DUPS)
return((TREE_ELEMENT *) 1);
uint alloc_size=sizeof(TREE_ELEMENT)+key_size+tree->size_of_element; uint alloc_size=sizeof(TREE_ELEMENT)+key_size+tree->size_of_element;
tree->allocated+=alloc_size; tree->allocated+=alloc_size;
......
...@@ -50,10 +50,6 @@ static int write_keys(SORTPARAM *param,uchar * *sort_keys, ...@@ -50,10 +50,6 @@ static int write_keys(SORTPARAM *param,uchar * *sort_keys,
uint count, IO_CACHE *buffer_file, IO_CACHE *tempfile); uint count, IO_CACHE *buffer_file, IO_CACHE *tempfile);
static void make_sortkey(SORTPARAM *param,uchar *to, uchar *ref_pos); static void make_sortkey(SORTPARAM *param,uchar *to, uchar *ref_pos);
static void register_used_fields(SORTPARAM *param); static void register_used_fields(SORTPARAM *param);
static int merge_index(SORTPARAM *param,uchar *sort_buffer,
BUFFPEK *buffpek,
uint maxbuffer,IO_CACHE *tempfile,
IO_CACHE *outfile);
static bool save_index(SORTPARAM *param,uchar **sort_keys, uint count, static bool save_index(SORTPARAM *param,uchar **sort_keys, uint count,
FILESORT_INFO *table_sort); FILESORT_INFO *table_sort);
static uint suffix_length(ulong string_length); static uint suffix_length(ulong string_length);
...@@ -145,8 +141,6 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length, ...@@ -145,8 +141,6 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
/* filesort cannot handle zero-length records. */ /* filesort cannot handle zero-length records. */
DBUG_ASSERT(param.sort_length); DBUG_ASSERT(param.sort_length);
param.ref_length= table->file->ref_length; param.ref_length= table->file->ref_length;
param.addon_field= 0;
param.addon_length= 0;
if (!(table->file->ha_table_flags() & HA_FAST_KEY_READ) && if (!(table->file->ha_table_flags() & HA_FAST_KEY_READ) &&
!table->fulltext_searched && !sort_positions) !table->fulltext_searched && !sort_positions)
{ {
...@@ -1200,8 +1194,11 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file, ...@@ -1200,8 +1194,11 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file,
QUEUE queue; QUEUE queue;
qsort2_cmp cmp; qsort2_cmp cmp;
void *first_cmp_arg; void *first_cmp_arg;
volatile THD::killed_state *killed= &current_thd->killed; element_count dupl_count;
uchar *src;
THD::killed_state not_killable; THD::killed_state not_killable;
uchar *unique_buff= param->unique_buff;
volatile THD::killed_state *killed= &current_thd->killed;
DBUG_ENTER("merge_buffers"); DBUG_ENTER("merge_buffers");
status_var_increment(current_thd->status_var.filesort_merge_passes); status_var_increment(current_thd->status_var.filesort_merge_passes);
...@@ -1216,7 +1213,13 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file, ...@@ -1216,7 +1213,13 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file,
rec_length= param->rec_length; rec_length= param->rec_length;
res_length= param->res_length; res_length= param->res_length;
sort_length= param->sort_length; sort_length= param->sort_length;
offset= rec_length-res_length; uint dupl_count_ofs= rec_length-sizeof(element_count);
uint min_dupl_count= param->min_dupl_count;
bool check_dupl_count= flag && min_dupl_count;
offset= (rec_length-
(flag && min_dupl_count ? sizeof(dupl_count) : 0)-res_length);
uint wr_len= flag ? res_length : rec_length;
uint wr_offset= flag ? offset : 0;
maxcount= (ulong) (param->keys/((uint) (Tb-Fb) +1)); maxcount= (ulong) (param->keys/((uint) (Tb-Fb) +1));
to_start_filepos= my_b_tell(to_file); to_start_filepos= my_b_tell(to_file);
strpos= sort_buffer; strpos= sort_buffer;
...@@ -1225,7 +1228,7 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file, ...@@ -1225,7 +1228,7 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file,
/* The following will fire if there is not enough space in sort_buffer */ /* The following will fire if there is not enough space in sort_buffer */
DBUG_ASSERT(maxcount!=0); DBUG_ASSERT(maxcount!=0);
if (param->unique_buff) if (unique_buff)
{ {
cmp= param->compare; cmp= param->compare;
first_cmp_arg= (void *) &param->cmp_context; first_cmp_arg= (void *) &param->cmp_context;
...@@ -1250,28 +1253,29 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file, ...@@ -1250,28 +1253,29 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file,
queue_insert(&queue, (uchar*) buffpek); queue_insert(&queue, (uchar*) buffpek);
} }
if (param->unique_buff) if (unique_buff)
{ {
/* /*
Called by Unique::get() Called by Unique::get()
Copy the first argument to param->unique_buff for unique removal. Copy the first argument to unique_buff for unique removal.
Store it also in 'to_file'. Store it also in 'to_file'.
This is safe as we know that there is always more than one element
in each block to merge (This is guaranteed by the Unique:: algorithm
*/ */
buffpek= (BUFFPEK*) queue_top(&queue); buffpek= (BUFFPEK*) queue_top(&queue);
memcpy(param->unique_buff, buffpek->key, rec_length); memcpy(unique_buff, buffpek->key, rec_length);
if (my_b_write(to_file, (uchar*) buffpek->key, rec_length)) if (min_dupl_count)
{ memcpy(&dupl_count, unique_buff+dupl_count_ofs,
error=1; goto err; /* purecov: inspected */ sizeof(dupl_count));
}
buffpek->key+= rec_length; buffpek->key+= rec_length;
buffpek->mem_count--; if (! --buffpek->mem_count)
if (!--max_rows)
{ {
error= 0; /* purecov: inspected */ if (!(error= (int) read_to_buffer(from_file, buffpek,
goto end; /* purecov: inspected */ rec_length)))
{
VOID(queue_remove(&queue,0));
reuse_freed_buff(&queue, buffpek, rec_length);
}
else if (error == -1)
goto err; /* purecov: inspected */
} }
queue_replaced(&queue); // Top element has been used queue_replaced(&queue); // Top element has been used
} }
...@@ -1287,27 +1291,50 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file, ...@@ -1287,27 +1291,50 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file,
for (;;) for (;;)
{ {
buffpek= (BUFFPEK*) queue_top(&queue); buffpek= (BUFFPEK*) queue_top(&queue);
src= buffpek->key;
if (cmp) // Remove duplicates if (cmp) // Remove duplicates
{ {
if (!(*cmp)(first_cmp_arg, &(param->unique_buff), if (!(*cmp)(first_cmp_arg, &unique_buff,
(uchar**) &buffpek->key)) (uchar**) &buffpek->key))
{
if (min_dupl_count)
{
element_count cnt;
memcpy(&cnt, (uchar *) buffpek->key+dupl_count_ofs, sizeof(cnt));
dupl_count+= cnt;
}
goto skip_duplicate; goto skip_duplicate;
memcpy(param->unique_buff, (uchar*) buffpek->key, rec_length);
} }
if (flag == 0) if (min_dupl_count)
{ {
if (my_b_write(to_file,(uchar*) buffpek->key, rec_length)) memcpy(unique_buff+dupl_count_ofs, &dupl_count,
{ sizeof(dupl_count));
error=1; goto err; /* purecov: inspected */
} }
src= unique_buff;
} }
else
/*
Do not write into the output file if this is the final merge called
for a Unique object used for intersection and dupl_count is less
than min_dupl_count.
If the Unique object is used to intersect N sets of unique elements
then for any element:
dupl_count >= N <=> the element is occurred in each of these N sets.
*/
if (!check_dupl_count || dupl_count >= min_dupl_count)
{ {
if (my_b_write(to_file, (uchar*) buffpek->key+offset, res_length)) if (my_b_write(to_file, src+wr_offset, wr_len))
{ {
error=1; goto err; /* purecov: inspected */ error=1; goto err; /* purecov: inspected */
} }
} }
if (cmp)
{
memcpy(unique_buff, (uchar*) buffpek->key, rec_length);
if (min_dupl_count)
memcpy(&dupl_count, unique_buff+dupl_count_ofs,
sizeof(dupl_count));
}
if (!--max_rows) if (!--max_rows)
{ {
error= 0; /* purecov: inspected */ error= 0; /* purecov: inspected */
...@@ -1318,7 +1345,7 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file, ...@@ -1318,7 +1345,7 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file,
buffpek->key+= rec_length; buffpek->key+= rec_length;
if (! --buffpek->mem_count) if (! --buffpek->mem_count)
{ {
if (!(error= (int) read_to_buffer(from_file,buffpek, if (!(error= (int) read_to_buffer(from_file, buffpek,
rec_length))) rec_length)))
{ {
VOID(queue_remove(&queue,0)); VOID(queue_remove(&queue,0));
...@@ -1341,11 +1368,35 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file, ...@@ -1341,11 +1368,35 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file,
*/ */
if (cmp) if (cmp)
{ {
if (!(*cmp)(first_cmp_arg, &(param->unique_buff), (uchar**) &buffpek->key)) if (!(*cmp)(first_cmp_arg, &unique_buff, (uchar**) &buffpek->key))
{ {
buffpek->key+= rec_length; // Remove duplicate if (min_dupl_count)
{
element_count cnt;
memcpy(&cnt, (uchar *) buffpek->key+dupl_count_ofs, sizeof(cnt));
dupl_count+= cnt;
}
buffpek->key+= rec_length;
--buffpek->mem_count; --buffpek->mem_count;
} }
if (min_dupl_count)
memcpy(unique_buff+dupl_count_ofs, &dupl_count,
sizeof(dupl_count));
if (!check_dupl_count || dupl_count >= min_dupl_count)
{
src= unique_buff;
if (my_b_write(to_file, src+wr_offset, wr_len))
{
error=1; goto err; /* purecov: inspected */
}
if (!--max_rows)
{
error= 0;
goto end;
}
}
} }
do do
...@@ -1358,7 +1409,7 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file, ...@@ -1358,7 +1409,7 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file,
max_rows-= buffpek->mem_count; max_rows-= buffpek->mem_count;
if (flag == 0) if (flag == 0)
{ {
if (my_b_write(to_file,(uchar*) buffpek->key, if (my_b_write(to_file, (uchar*) buffpek->key,
(rec_length*buffpek->mem_count))) (rec_length*buffpek->mem_count)))
{ {
error= 1; goto err; /* purecov: inspected */ error= 1; goto err; /* purecov: inspected */
...@@ -1367,19 +1418,25 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file, ...@@ -1367,19 +1418,25 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file,
else else
{ {
register uchar *end; register uchar *end;
strpos= buffpek->key+offset; src= buffpek->key+offset;
for (end= strpos+buffpek->mem_count*rec_length ; for (end= src+buffpek->mem_count*rec_length ;
strpos != end ; src != end ;
strpos+= rec_length) src+= rec_length)
{ {
if (my_b_write(to_file, strpos, res_length)) if (check_dupl_count)
{
memcpy((uchar *) &dupl_count, src+dupl_count_ofs, sizeof(dupl_count));
if (dupl_count < min_dupl_count)
continue;
}
if (my_b_write(to_file, src, wr_len))
{ {
error=1; goto err; error=1; goto err;
} }
} }
} }
} }
while ((error=(int) read_to_buffer(from_file,buffpek, rec_length)) while ((error=(int) read_to_buffer(from_file, buffpek, rec_length))
!= -1 && error != 0); != -1 && error != 0);
end: end:
...@@ -1393,7 +1450,7 @@ err: ...@@ -1393,7 +1450,7 @@ err:
/* Do a merge to output-file (save only positions) */ /* Do a merge to output-file (save only positions) */
static int merge_index(SORTPARAM *param, uchar *sort_buffer, int merge_index(SORTPARAM *param, uchar *sort_buffer,
BUFFPEK *buffpek, uint maxbuffer, BUFFPEK *buffpek, uint maxbuffer,
IO_CACHE *tempfile, IO_CACHE *outfile) IO_CACHE *tempfile, IO_CACHE *outfile)
{ {
...@@ -1699,3 +1756,4 @@ void change_double_for_sort(double nr,uchar *to) ...@@ -1699,3 +1756,4 @@ void change_double_for_sort(double nr,uchar *to)
} }
} }
} }
...@@ -340,6 +340,9 @@ protected: ...@@ -340,6 +340,9 @@ protected:
*/ */
#define TIME_FOR_COMPARE_ROWID (TIME_FOR_COMPARE*100) #define TIME_FOR_COMPARE_ROWID (TIME_FOR_COMPARE*100)
/* cost1 is better that cost2 only if cost1 + COST_EPS < cost2 */
#define COST_EPS 0.001
/* /*
For sequential disk seeks the cost formula is: For sequential disk seeks the cost formula is:
DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST * #blocks_to_skip DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST * #blocks_to_skip
...@@ -542,12 +545,13 @@ protected: ...@@ -542,12 +545,13 @@ protected:
#define OPTIMIZER_SWITCH_INDEX_MERGE_UNION 2 #define OPTIMIZER_SWITCH_INDEX_MERGE_UNION 2
#define OPTIMIZER_SWITCH_INDEX_MERGE_SORT_UNION 4 #define OPTIMIZER_SWITCH_INDEX_MERGE_SORT_UNION 4
#define OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT 8 #define OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT 8
#define OPTIMIZER_SWITCH_INDEX_MERGE_SORT_INTERSECT 16
#ifdef DBUG_OFF #ifdef DBUG_OFF
# define OPTIMIZER_SWITCH_LAST 16
#else
# define OPTIMIZER_SWITCH_TABLE_ELIMINATION 16
# define OPTIMIZER_SWITCH_LAST 32 # define OPTIMIZER_SWITCH_LAST 32
#else
# define OPTIMIZER_SWITCH_TABLE_ELIMINATION 32
# define OPTIMIZER_SWITCH_LAST 64
#endif #endif
#ifdef DBUG_OFF #ifdef DBUG_OFF
...@@ -2233,6 +2237,8 @@ ha_rows filesort(THD *thd, TABLE *form,struct st_sort_field *sortorder, ...@@ -2233,6 +2237,8 @@ ha_rows filesort(THD *thd, TABLE *form,struct st_sort_field *sortorder,
ha_rows max_rows, bool sort_positions, ha_rows max_rows, bool sort_positions,
ha_rows *examined_rows); ha_rows *examined_rows);
void filesort_free_buffers(TABLE *table, bool full); void filesort_free_buffers(TABLE *table, bool full);
double get_merge_many_buffs_cost(uint *buffer, uint last_n_elems,
int elem_size);
void change_double_for_sort(double nr,uchar *to); void change_double_for_sort(double nr,uchar *to);
double my_double_round(double value, longlong dec, bool dec_unsigned, double my_double_round(double value, longlong dec, bool dec_unsigned,
bool truncate); bool truncate);
......
...@@ -338,7 +338,7 @@ TYPELIB sql_mode_typelib= { array_elements(sql_mode_names)-1,"", ...@@ -338,7 +338,7 @@ TYPELIB sql_mode_typelib= { array_elements(sql_mode_names)-1,"",
static const char *optimizer_switch_names[]= static const char *optimizer_switch_names[]=
{ {
"index_merge","index_merge_union","index_merge_sort_union", "index_merge","index_merge_union","index_merge_sort_union",
"index_merge_intersection", "index_merge_intersection","index_merge_sort_intersection",
#ifndef DBUG_OFF #ifndef DBUG_OFF
"table_elimination", "table_elimination",
#endif #endif
...@@ -352,6 +352,7 @@ static const unsigned int optimizer_switch_names_len[]= ...@@ -352,6 +352,7 @@ static const unsigned int optimizer_switch_names_len[]=
sizeof("index_merge_union") - 1, sizeof("index_merge_union") - 1,
sizeof("index_merge_sort_union") - 1, sizeof("index_merge_sort_union") - 1,
sizeof("index_merge_intersection") - 1, sizeof("index_merge_intersection") - 1,
sizeof("index_merge_sort_intersection") - 1,
#ifndef DBUG_OFF #ifndef DBUG_OFF
sizeof("table_elimination") - 1, sizeof("table_elimination") - 1,
#endif #endif
...@@ -431,7 +432,8 @@ static const char *sql_mode_str= "OFF"; ...@@ -431,7 +432,8 @@ static const char *sql_mode_str= "OFF";
/* Text representation for OPTIMIZER_SWITCH_DEFAULT */ /* Text representation for OPTIMIZER_SWITCH_DEFAULT */
static const char *optimizer_switch_str="index_merge=on,index_merge_union=on," static const char *optimizer_switch_str="index_merge=on,index_merge_union=on,"
"index_merge_sort_union=on," "index_merge_sort_union=on,"
"index_merge_intersection=on" "index_merge_intersection=on,"
"index_merge_sort_intersection=off"
#ifndef DBUG_OFF #ifndef DBUG_OFF
",table_elimination=on"; ",table_elimination=on";
#else #else
...@@ -7297,7 +7299,8 @@ thread is in the relay logs.", ...@@ -7297,7 +7299,8 @@ thread is in the relay logs.",
0, GET_ULONG, OPT_ARG, MAX_TABLES+1, 0, MAX_TABLES+2, 0, 1, 0}, 0, GET_ULONG, OPT_ARG, MAX_TABLES+1, 0, MAX_TABLES+2, 0, 1, 0},
{"optimizer_switch", OPT_OPTIMIZER_SWITCH, {"optimizer_switch", OPT_OPTIMIZER_SWITCH,
"optimizer_switch=option=val[,option=val...], where option={index_merge, " "optimizer_switch=option=val[,option=val...], where option={index_merge, "
"index_merge_union, index_merge_sort_union, index_merge_intersection" "index_merge_union, index_merge_sort_union, index_merge_intersection, "
"index_merge_sort_intersection"
#ifndef DBUG_OFF #ifndef DBUG_OFF
", table_elimination" ", table_elimination"
#endif #endif
......
This diff is collapsed.
...@@ -274,12 +274,13 @@ public: ...@@ -274,12 +274,13 @@ public:
enum { enum {
QS_TYPE_RANGE = 0, QS_TYPE_RANGE = 0,
QS_TYPE_INDEX_MERGE = 1, QS_TYPE_INDEX_INTERSECT = 1,
QS_TYPE_RANGE_DESC = 2, QS_TYPE_INDEX_MERGE = 2,
QS_TYPE_FULLTEXT = 3, QS_TYPE_RANGE_DESC = 3,
QS_TYPE_ROR_INTERSECT = 4, QS_TYPE_FULLTEXT = 4,
QS_TYPE_ROR_UNION = 5, QS_TYPE_ROR_INTERSECT = 5,
QS_TYPE_GROUP_MIN_MAX = 6 QS_TYPE_ROR_UNION = 6,
QS_TYPE_GROUP_MIN_MAX = 7
}; };
/* Get type of this quick select - one of the QS_TYPE_* values */ /* Get type of this quick select - one of the QS_TYPE_* values */
...@@ -306,6 +307,10 @@ public: ...@@ -306,6 +307,10 @@ public:
*/ */
virtual void save_last_pos(){}; virtual void save_last_pos(){};
void add_key_and_length(String *key_names,
String *used_lengths,
bool *first);
/* /*
Append comma-separated list of keys this quick select uses to key_names; Append comma-separated list of keys this quick select uses to key_names;
append comma-separated list of corresponding used lengths to used_lengths. append comma-separated list of corresponding used lengths to used_lengths.
...@@ -314,13 +319,16 @@ public: ...@@ -314,13 +319,16 @@ public:
virtual void add_keys_and_lengths(String *key_names, virtual void add_keys_and_lengths(String *key_names,
String *used_lengths)=0; String *used_lengths)=0;
void add_key_name(String *str, bool *first);
/* /*
Append text representation of quick select structure (what and how is Append text representation of quick select structure (what and how is
merged) to str. The result is added to "Extra" field in EXPLAIN output. merged) to str. The result is added to "Extra" field in EXPLAIN output.
This function is implemented only by quick selects that merge other quick This function is implemented only by quick selects that merge other quick
selects output and/or can produce output suitable for merging. selects output and/or can produce output suitable for merging.
*/ */
virtual void add_info_string(String *str) {}; virtual void add_info_string(String *str) {}
/* /*
Return 1 if any index used by this quick select Return 1 if any index used by this quick select
uses field which is marked in passed bitmap. uses field which is marked in passed bitmap.
...@@ -393,8 +401,19 @@ protected: ...@@ -393,8 +401,19 @@ protected:
friend QUICK_RANGE_SELECT *get_quick_select(PARAM*,uint idx, friend QUICK_RANGE_SELECT *get_quick_select(PARAM*,uint idx,
SEL_ARG *key_tree, SEL_ARG *key_tree,
MEM_ROOT *alloc); MEM_ROOT *alloc);
friend
int read_keys_and_merge_scans(THD *thd, TABLE *head,
List<QUICK_RANGE_SELECT> quick_selects,
QUICK_RANGE_SELECT *pk_quick_select,
READ_RECORD *read_record,
bool intersection,
key_map *filtered_scans,
Unique **unique_ptr);
friend class QUICK_SELECT_DESC; friend class QUICK_SELECT_DESC;
friend class QUICK_INDEX_SORT_SELECT;
friend class QUICK_INDEX_MERGE_SELECT; friend class QUICK_INDEX_MERGE_SELECT;
friend class QUICK_INDEX_INTERSECT_SELECT;
friend class QUICK_ROR_INTERSECT_SELECT; friend class QUICK_ROR_INTERSECT_SELECT;
friend class QUICK_GROUP_MIN_MAX_SELECT; friend class QUICK_GROUP_MIN_MAX_SELECT;
...@@ -448,37 +467,43 @@ public: ...@@ -448,37 +467,43 @@ public:
/* /*
QUICK_INDEX_MERGE_SELECT - index_merge access method quick select. QUICK_INDEX_SORT_SELECT is the base class for the common functionality of:
- QUICK_INDEX_MERGE_SELECT, access based on multi-index merge/union
- QUICK_INDEX_INTERSECT_SELECT, access based on multi-index intersection
QUICK_INDEX_MERGE_SELECT uses QUICK_INDEX_SORT_SELECT uses
* QUICK_RANGE_SELECTs to get rows * QUICK_RANGE_SELECTs to get rows
* Unique class to remove duplicate rows * Unique class
- to remove duplicate rows for QUICK_INDEX_MERGE_SELECT
- to intersect rows for QUICK_INDEX_INTERSECT_SELECT
INDEX MERGE OPTIMIZER INDEX MERGE OPTIMIZER
Current implementation doesn't detect all cases where index_merge could Current implementation doesn't detect all cases where index merge could
be used, in particular: be used, in particular:
* index_merge+'using index' is not supported * index_merge+'using index' is not supported
* If WHERE part contains complex nested AND and OR conditions, some ways * If WHERE part contains complex nested AND and OR conditions, some ways
to retrieve rows using index_merge will not be considered. The choice to retrieve rows using index merge will not be considered. The choice
of read plan may depend on the order of conjuncts/disjuncts in WHERE of read plan may depend on the order of conjuncts/disjuncts in WHERE
part of the query, see comments near imerge_list_or_list and part of the query, see comments near imerge_list_or_list and
SEL_IMERGE::or_sel_tree_with_checks functions for details. SEL_IMERGE::or_sel_tree_with_checks functions for details.
* There is no "index_merge_ref" method (but index_merge on non-first * There is no "index_merge_ref" method (but index merge on non-first
table in join is possible with 'range checked for each record'). table in join is possible with 'range checked for each record').
See comments around SEL_IMERGE class and test_quick_select for more
details.
ROW RETRIEVAL ALGORITHM ROW RETRIEVAL ALGORITHM
index_merge uses Unique class for duplicates removal. index_merge takes index merge/intersection uses Unique class for duplicates removal.
advantage of Clustered Primary Key (CPK) if the table has one. index merge/intersection takes advantage of Clustered Primary Key (CPK)
The index_merge algorithm consists of two phases: if the table has one.
The index merge/intersection algorithm consists of two phases:
Phase 1
(implemented by a QUICK_INDEX_MERGE_SELECT::read_keys_and_merge call):
Phase 1 (implemented in QUICK_INDEX_MERGE_SELECT::prepare_unique):
prepare() prepare()
{ {
activate 'index only'; activate 'index only';
...@@ -492,32 +517,31 @@ public: ...@@ -492,32 +517,31 @@ public:
deactivate 'index only'; deactivate 'index only';
} }
Phase 2 (implemented as sequence of QUICK_INDEX_MERGE_SELECT::get_next Phase 2
calls): (implemented as sequence of QUICK_INDEX_MERGE_SELECT::get_next calls):
fetch() fetch()
{ {
retrieve all rows from row pointers stored in Unique; retrieve all rows from row pointers stored in Unique
(merging/intersecting them);
free Unique; free Unique;
if (! intersection)
retrieve all rows for CPK scan; retrieve all rows for CPK scan;
} }
*/ */
class QUICK_INDEX_MERGE_SELECT : public QUICK_SELECT_I class QUICK_INDEX_SORT_SELECT : public QUICK_SELECT_I
{ {
protected:
Unique *unique; Unique *unique;
public: public:
QUICK_INDEX_MERGE_SELECT(THD *thd, TABLE *table); QUICK_INDEX_SORT_SELECT(THD *thd, TABLE *table);
~QUICK_INDEX_MERGE_SELECT(); ~QUICK_INDEX_SORT_SELECT();
int init(); int init();
int reset(void); int reset(void);
int get_next();
bool reverse_sorted() { return false; } bool reverse_sorted() { return false; }
bool unique_key_range() { return false; } bool unique_key_range() { return false; }
int get_type() { return QS_TYPE_INDEX_MERGE; }
void add_keys_and_lengths(String *key_names, String *used_lengths);
void add_info_string(String *str);
bool is_keys_used(const MY_BITMAP *fields); bool is_keys_used(const MY_BITMAP *fields);
#ifndef DBUG_OFF #ifndef DBUG_OFF
void dbug_dump(int indent, bool verbose); void dbug_dump(int indent, bool verbose);
...@@ -525,24 +549,57 @@ public: ...@@ -525,24 +549,57 @@ public:
bool push_quick_back(QUICK_RANGE_SELECT *quick_sel_range); bool push_quick_back(QUICK_RANGE_SELECT *quick_sel_range);
/* range quick selects this index_merge read consists of */ /* range quick selects this index merge/intersect consists of */
List<QUICK_RANGE_SELECT> quick_selects; List<QUICK_RANGE_SELECT> quick_selects;
/* quick select that uses clustered primary key (NULL if none) */ /* quick select that uses clustered primary key (NULL if none) */
QUICK_RANGE_SELECT* pk_quick_select; QUICK_RANGE_SELECT* pk_quick_select;
/* true if this select is currently doing a clustered PK scan */
bool doing_pk_scan;
MEM_ROOT alloc; MEM_ROOT alloc;
THD *thd; THD *thd;
int read_keys_and_merge(); virtual int read_keys_and_merge()= 0;
/* used to get rows collected in Unique */ /* used to get rows collected in Unique */
READ_RECORD read_record; READ_RECORD read_record;
}; };
class QUICK_INDEX_MERGE_SELECT : public QUICK_INDEX_SORT_SELECT
{
private:
/* true if this select is currently doing a clustered PK scan */
bool doing_pk_scan;
protected:
int read_keys_and_merge();
public:
QUICK_INDEX_MERGE_SELECT(THD *thd, TABLE *table)
:QUICK_INDEX_SORT_SELECT(thd, table) {}
int get_next();
int get_type() { return QS_TYPE_INDEX_MERGE; }
void add_keys_and_lengths(String *key_names, String *used_lengths);
void add_info_string(String *str);
};
class QUICK_INDEX_INTERSECT_SELECT : public QUICK_INDEX_SORT_SELECT
{
protected:
int read_keys_and_merge();
public:
QUICK_INDEX_INTERSECT_SELECT(THD *thd, TABLE *table)
:QUICK_INDEX_SORT_SELECT(thd, table) {}
key_map filtered_scans;
int get_next();
int get_type() { return QS_TYPE_INDEX_INTERSECT; }
void add_keys_and_lengths(String *key_names, String *used_lengths);
void add_info_string(String *str);
};
/* /*
Rowid-Ordered Retrieval (ROR) index intersection quick select. Rowid-Ordered Retrieval (ROR) index intersection quick select.
This quick select produces intersection of row sequences returned This quick select produces intersection of row sequences returned
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -683,7 +683,7 @@ struct st_table { ...@@ -683,7 +683,7 @@ struct st_table {
needed by the query without reading the row. needed by the query without reading the row.
*/ */
key_map covering_keys; key_map covering_keys;
key_map quick_keys, merge_keys; key_map quick_keys, merge_keys,intersect_keys;
/* /*
A set of keys that can be used in the query that references this A set of keys that can be used in the query that references this
table. table.
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment