Commit 96fbab5f authored by Rich Prohaska's avatar Rich Prohaska

DB-500 allow simple deletes to use bulk fetch

parent 9e079da4
set default_storage_engine='tokudb';
drop table if exists t;
CREATE TABLE `t` (id bigint not null auto_increment primary key, val bigint not null default 0);
INSERT INTO t (id) values (null);
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
SELECT count(*) FROM t;
count(*)
8388608
set tokudb_bulk_fetch = ON;
delete from t where val > 0;
delete from t where val > 0;
delete from t where val > 0;
delete from t where val > 0;
delete from t where val > 0;
delete from t where val > 0;
delete from t where val > 0;
delete from t where val > 0;
delete from t where val > 0;
delete from t where val > 0;
set tokudb_bulk_fetch = OFF;
delete from t where val > 0;
delete from t where val > 0;
delete from t where val > 0;
delete from t where val > 0;
delete from t where val > 0;
delete from t where val > 0;
delete from t where val > 0;
delete from t where val > 0;
delete from t where val > 0;
delete from t where val > 0;
1
drop table t;
set default_storage_engine='tokudb';
drop table if exists t;
create table t (id bigint not null primary key, x bigint not null);
insert into t values (1,0),(2,0),(3,0),(4,0);
create trigger t_delete before delete on t for each row insert into t values (1000000,0);
begin;
delete from t where x=0;
ERROR HY000: Can't update table 't' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
rollback;
drop trigger t_delete;
create trigger t_delete after delete on t for each row insert into t values (1000000,0);
begin;
delete from t where x=0;
ERROR HY000: Can't update table 't' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
rollback;
drop trigger t_delete;
create trigger t_delete before delete on t for each row delete from t where id=1000000;
begin;
delete from t where x=0;
ERROR HY000: Can't update table 't' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
rollback;
drop trigger t_delete;
create trigger t_delete after delete on t for each row delete from t where id=1000000;
begin;
delete from t where x=0;
ERROR HY000: Can't update table 't' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
rollback;
drop trigger t_delete;
create trigger t_delete before delete on t for each row update t set x=x+1 where id=1000000;
begin;
delete from t where x=0;
ERROR HY000: Can't update table 't' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
rollback;
drop trigger t_delete;
create trigger t_delete after delete on t for each row update t set x=x+1 where id=10000000;
begin;
delete from t where x=0;
ERROR HY000: Can't update table 't' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
rollback;
drop trigger t_delete;
create table count (count bigint not null);
create trigger t_delete before delete on t for each row insert into count select count(*) from t;
begin;
delete from t where x=0;
select * from count;
count
4
3
2
1
rollback;
drop trigger t_delete;
drop table count;
drop table t;
# Verify that index scans for delete statements use bulk fetch and are
# at least twice as fast
source include/have_tokudb.inc;
set default_storage_engine='tokudb';
disable_warnings;
drop table if exists t;
enable_warnings;
CREATE TABLE `t` (id bigint not null auto_increment primary key, val bigint not null default 0);
# put 8M rows into t
INSERT INTO t (id) values (null);
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
INSERT INTO t SELECT null,val FROM t;
SELECT count(*) FROM t;
# run $maxq measurements
let $maxq = 10;
# measure the time to do $maxq deletes from t that affect no rows with bulk fetch ON
set tokudb_bulk_fetch = ON;
let $s = `select to_seconds(now())`;
let $i = 0;
while ($i < $maxq) {
delete from t where val > 0;
inc $i;
}
let $time_elapsed_bf_on = `select to_seconds(now()) - $s`;
# measure the time to do $maxq deletes from t that affect no rows with bulk fetch OFF
set tokudb_bulk_fetch = OFF;
let $s = `select to_seconds(now())`;
let $i = 0;
while ($i < $maxq) {
delete from t where val > 0;
inc $i;
}
let $time_elapsed_bf_off = `select to_seconds(now()) - $s`;
# verify that a delete scan with bulk fetch ON is at least 2 times faster than with bulk fetch OFF
let $verdict = `select $time_elapsed_bf_off > $time_elapsed_bf_on && ($time_elapsed_bf_off - $time_elapsed_bf_on) / $time_elapsed_bf_on >= 2`;
echo $verdict;
if (!$verdict) { echo $time_elapsed_bf_on $time_elapsed_bf_off; }
drop table t;
# verify that delete triggers can not insert, delete, or update rows in the target table
source include/have_tokudb.inc;
set default_storage_engine='tokudb';
disable_warnings;
drop table if exists t;
enable_warnings;
create table t (id bigint not null primary key, x bigint not null);
insert into t values (1,0),(2,0),(3,0),(4,0);
# verify that a before delete trigger can not insert into the target table
create trigger t_delete before delete on t for each row insert into t values (1000000,0);
begin;
error 1442;
delete from t where x=0;
rollback;
drop trigger t_delete;
# verify that an after delete trigger can not insert into the target table
create trigger t_delete after delete on t for each row insert into t values (1000000,0);
begin;
error 1442;
delete from t where x=0;
rollback;
drop trigger t_delete;
# verify that a before delete trigger can not delete from the target table
create trigger t_delete before delete on t for each row delete from t where id=1000000;
begin;
error 1442;
delete from t where x=0;
rollback;
drop trigger t_delete;
# verify that an after delete trigger can not delete from the target table
create trigger t_delete after delete on t for each row delete from t where id=1000000;
begin;
error 1442;
delete from t where x=0;
rollback;
drop trigger t_delete;
# verify that a before delete trigger can not update the target table
create trigger t_delete before delete on t for each row update t set x=x+1 where id=1000000;
begin;
error 1442;
delete from t where x=0;
rollback;
drop trigger t_delete;
# verify that an after delete trigger can not update the target table
create trigger t_delete after delete on t for each row update t set x=x+1 where id=10000000;
begin;
error 1442;
delete from t where x=0;
rollback;
drop trigger t_delete;
# can execute select on the target table in a delete trigger. it better use a different handler.
create table count (count bigint not null);
create trigger t_delete before delete on t for each row insert into count select count(*) from t;
begin;
delete from t where x=0;
select * from count;
rollback;
drop trigger t_delete;
drop table count;
drop table t;
\ No newline at end of file
......@@ -4370,6 +4370,7 @@ static bool tokudb_do_bulk_fetch(THD *thd) {
case SQLCOM_CREATE_TABLE:
case SQLCOM_INSERT_SELECT:
case SQLCOM_REPLACE_SELECT:
case SQLCOM_DELETE:
return THDVAR(thd, bulk_fetch) != 0;
default:
return false;
......
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