mariadb/mysql-test/t/subselect_mat_cost.test
unknown 759d71eba1 MWL#89
Split the tests for MWL#89 into two parts - one for bugs
(currently active), and one for functionality tets
(currently in progress, and thus disabled).

Disable the test for LP BUG#718593.
2011-02-22 12:44:58 +02:00

204 lines
7.2 KiB
Text

#
# Tets of cost-based choice between the materialization and in-to-exists
# subquery execution strategies (MWL#89)
#
--disable_warnings
drop table if exists t1, t2, t1_1024, t2_1024;
drop procedure if exists make_t1_indexes;
drop procedure if exists make_t2_indexes;
drop procedure if exists remove_t1_indexes;
drop procedure if exists remove_t2_indexes;
drop procedure if exists add_materialization_data;
drop procedure if exists delete_materialization_data;
drop procedure if exists set_all_columns_not_null;
drop procedure if exists set_all_columns_nullable;
--enable_warnings
create table t1 (a1 char(8), a2 char(8), a3 char(8), a4 int);
insert into t1 values ('1 - 00', '2 - 00', '3 - 00', 0);
insert into t1 values ('1 - 01', '2 - 01', '3 - 01', 1);
create table t2 (b1 char(8), b2 char(8), b3 char(8), b4 int);
insert into t2 values ('1 - 01', '2 - 01', '3 - 01', 1);
insert into t2 values ('1 - 01', '2 - 01', '3 - 02', 2);
insert into t2 values ('1 - 02', '2 - 02', '3 - 03', 3);
insert into t2 values ('1 - 02', '2 - 02', '3 - 04', 4);
insert into t2 values ('1 - 03', '2 - 03', '3 - 05', 5);
create table t1_1024 (a1 blob(1024), a2 blob(1024));
insert into t1_1024 values (concat('1 - 00', repeat('x', 1018)), concat('2 - 00', repeat('x', 1018)));
insert into t1_1024 values (concat('1 - 01', repeat('x', 1018)), concat('2 - 01', repeat('x', 1018)));
create table t2_1024 (b1 blob(1024), b2 blob(1024));
insert into t2_1024 values (concat('1 - 01', repeat('x', 1018)), concat('2 - 01', repeat('x', 1018)));
insert into t2_1024 values (concat('1 - 02', repeat('x', 1018)), concat('2 - 02', repeat('x', 1018)));
insert into t2_1024 values (concat('1 - 03', repeat('x', 1018)), concat('2 - 03', repeat('x', 1018)));
insert into t2_1024 values (concat('1 - 04', repeat('x', 1018)), concat('2 - 04', repeat('x', 1018)));
delimiter |;
create procedure make_t1_indexes()
begin
create index it1i1 on t1 (a1);
create index it1i2 on t1 (a2);
create index it1i3 on t1 (a1, a2);
create index it1_1024i1 on t1_1024 (a1(6));
create index it1_1024i2 on t1_1024 (a2(6));
create index it1_1024i3 on t1_1024 (a1(6), a2(6));
end|
create procedure make_t2_indexes()
begin
create index it2i1 on t2 (b1);
create index it2i2 on t2 (b2);
create index it2i3 on t2 (b1, b2);
create unique index it2i4 on t2 (b1, b2, b3);
create index it2_1024i1 on t2_1024 (b1(6));
create index it2_1024i2 on t2_1024 (b2(6));
create index it2_1024i3 on t2_1024 (b1(6), b2(6));
end|
create procedure remove_t1_indexes()
begin
drop index it1i1 on t1;
drop index it1i2 on t1;
drop index it1i3 on t1;
drop index it1_1024i1 on t1_1024;
drop index it1_1024i2 on t1_1024;
drop index it1_1024i3 on t1_1024;
end|
create procedure remove_t2_indexes()
begin
drop index it2i1 on t2;
drop index it2i2 on t2;
drop index it2i3 on t2;
drop index it2i4 on t2;
drop index it2_1024i1 on t2_1024;
drop index it2_1024i2 on t2_1024;
drop index it2_1024i3 on t2_1024;
end|
create procedure add_materialization_data()
begin
insert into t1 values ('1 - 03', '2 - 03', '3 - 03', 3);
insert into t1 values ('1 - 04', '2 - 04', '3 - 04', 4);
insert into t1 values ('1 - 05', '2 - 05', '3 - 05', 5);
insert into t1 values ('1 - 06', '2 - 06', '3 - 06', 6);
insert into t1 values ('1 - 07', '2 - 07', '3 - 07', 7);
insert into t1_1024 values (concat('1 - 03', repeat('x', 1018)), concat('2 - 03', repeat('x', 1018)));
end|
create procedure delete_materialization_data()
begin
delete from t1 where a1 >= '1 - 03';
delete from t1_1024 where a1 >= '1 - 03';
end|
create procedure set_all_columns_not_null()
begin
alter table t1 modify a1 char(8) not null, modify a2 char(8) not null, modify a3 char(8) not null;
alter table t2 modify b1 char(8) not null, modify b2 char(8) not null, modify b3 char(8) not null;
end|
create procedure set_all_columns_nullable()
begin
alter table t1 modify a1 char(8) null, modify a2 char(8) null, modify a3 char(8) null;
alter table t2 modify b1 char(8) null, modify b2 char(8) null, modify b3 char(8) null;
end|
delimiter ;|
-- echo
-- echo /******************************************************************************
-- echo 1. Both materialization and in-to-exists are ON, make a cost-based choice.
-- echo ******************************************************************************/
set @@optimizer_switch='materialization=on,in_to_exists=on';
-- echo
-- echo /* 1.1 In-to-exists is cheaper */
call make_t1_indexes();
-- echo /* 1.1.1 non-indexed table access */
-- source include/subselect_mat_cost.inc
-- echo /* 1.1.2 indexed table access, nullabale columns. */
call make_t2_indexes();
-- source include/subselect_mat_cost.inc
-- echo /* 1.1.3 indexed table access, non-nullabale columns. */
call set_all_columns_not_null();
-- source include/subselect_mat_cost.inc
call set_all_columns_nullable();
-- echo
-- echo /* 1.2 Materialization is cheaper */
# make materialization cheaper
call add_materialization_data();
call remove_t1_indexes();
-- echo /* 1.2.1 non-indexed table access */
call remove_t2_indexes();
-- source include/subselect_mat_cost.inc
-- echo /* 1.2.2 indexed table access, nullabale columns. */
call make_t2_indexes();
-- source include/subselect_mat_cost.inc
-- echo /* 1.2.3 indexed table access, non-nullabale columns. */
call set_all_columns_not_null();
-- source include/subselect_mat_cost.inc
call set_all_columns_nullable();
insert into t1 values ('1 - 02', '2 - 02', '3 - 02', 2);
-- echo /******************************************************************************
-- echo 2. Materialization is OFF, in-to-exists is ON, materialization is cheaper.
-- echo ******************************************************************************/
set @@optimizer_switch='materialization=off,in_to_exists=on';
-- echo /* 2.1 non-indexed table access */
call remove_t2_indexes();
-- source include/subselect_mat_cost.inc
-- echo /* 2.2 indexed table access, nullabale columns. */
call make_t2_indexes();
-- source include/subselect_mat_cost.inc
-- echo /* 2.3 indexed table access, non-nullabale columns. */
call set_all_columns_not_null();
-- source include/subselect_mat_cost.inc
call set_all_columns_nullable();
-- echo /******************************************************************************
-- echo 3. Materialization is ON, in-to-exists is OFF, in-to-exists is cheaper.
-- echo ******************************************************************************/
set @@optimizer_switch='materialization=on,in_to_exists=off';
# make IN-TO-EXISTS cheaper
call delete_materialization_data();
call make_t1_indexes();
-- echo /* 3.1 non-indexed table access */
call remove_t2_indexes();
-- source include/subselect_mat_cost.inc
-- echo /* 3.2 indexed table access, nullabale columns. */
call make_t2_indexes();
-- source include/subselect_mat_cost.inc
-- echo /* 3.3 indexed table access, non-nullabale columns. */
call set_all_columns_not_null();
-- source include/subselect_mat_cost.inc
call set_all_columns_nullable();
drop procedure make_t1_indexes;
drop procedure make_t2_indexes;
drop procedure remove_t1_indexes;
drop procedure remove_t2_indexes;
drop procedure add_materialization_data;
drop procedure delete_materialization_data;
drop procedure set_all_columns_not_null;
drop procedure set_all_columns_nullable;
drop table t1, t2, t1_1024, t2_1024;