Commit 607aab9c authored by unknown's avatar unknown

Counters for Index Condition Pushdown added (MDEV-130).

parent 764eeeee
......@@ -852,3 +852,25 @@ SET optimizer_switch=@save_optimizer_switch;
DROP TABLE t1,t2;
--echo # check "Handler_pushed" status varuiables
CREATE TABLE t1 (
c1 CHAR(1),
c2 CHAR(1),
KEY (c1)
);
INSERT INTO t1 VALUES ('3', '3'),('4','4'),('5','5');
flush status;
show status like "Handler_pushed%";
SELECT * FROM t1 FORCE INDEX(c1) WHERE (c1='3' or c1='4') and c1 % 2 = 0 ;
show status like "Handler_pushed%";
SELECT * FROM t1 WHERE (c2='3' or c2='4') and c2 % 2 = 0 ;
show status like "Handler_pushed%";
DROP TABLE t1;
......@@ -808,5 +808,32 @@ COUNT(*)
1478
SET optimizer_switch=@save_optimizer_switch;
DROP TABLE t1,t2;
# check "Handler_pushed" status varuiables
CREATE TABLE t1 (
c1 CHAR(1),
c2 CHAR(1),
KEY (c1)
);
INSERT INTO t1 VALUES ('3', '3'),('4','4'),('5','5');
flush status;
show status like "Handler_pushed%";
Variable_name Value
Handler_pushed_index_cond_checks 0
Handler_pushed_index_cond_filtered 0
SELECT * FROM t1 FORCE INDEX(c1) WHERE (c1='3' or c1='4') and c1 % 2 = 0 ;
c1 c2
4 4
show status like "Handler_pushed%";
Variable_name Value
Handler_pushed_index_cond_checks 2
Handler_pushed_index_cond_filtered 1
SELECT * FROM t1 WHERE (c2='3' or c2='4') and c2 % 2 = 0 ;
c1 c2
4 4
show status like "Handler_pushed%";
Variable_name Value
Handler_pushed_index_cond_checks 2
Handler_pushed_index_cond_filtered 1
DROP TABLE t1;
set optimizer_switch=@innodb_icp_tmp;
set storage_engine= @save_storage_engine;
......@@ -3506,6 +3506,7 @@ insert into t2 values (2,1, 'qwerty'),(2,2, 'qwerty'),(2,3, 'qwerty'),
insert into t2 values (3,1, 'qwerty'),(3,4, 'qwerty');
insert into t2 values (4,1, 'qwerty'),(4,2, 'qwerty'),(4,3, 'qwerty'),
(4,4, 'qwerty');
flush status;
set join_cache_level=5;
select t2.f1, t2.f2, t2.f3 from t1,t2
where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1;
......@@ -3519,6 +3520,10 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where
1 SIMPLE t2 ref f1 f1 4 test.t1.f1 3 Using index condition(BKA); Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
show status like "Handler_pushed%";
Variable_name Value
Handler_pushed_index_cond_checks 20
Handler_pushed_index_cond_filtered 16
set join_cache_level=6;
select t2.f1, t2.f2, t2.f3 from t1,t2
where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1;
......@@ -3532,6 +3537,10 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where
1 SIMPLE t2 ref f1 f1 4 test.t1.f1 3 Using index condition(BKA); Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
show status like "Handler_pushed%";
Variable_name Value
Handler_pushed_index_cond_checks 40
Handler_pushed_index_cond_filtered 32
set join_cache_level=7;
select t2.f1, t2.f2, t2.f3 from t1,t2
where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1;
......@@ -3545,6 +3554,10 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where
1 SIMPLE t2 ref f1 f1 4 test.t1.f1 3 Using index condition(BKA); Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
show status like "Handler_pushed%";
Variable_name Value
Handler_pushed_index_cond_checks 60
Handler_pushed_index_cond_filtered 48
set join_cache_level=8;
select t2.f1, t2.f2, t2.f3 from t1,t2
where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1;
......@@ -3558,6 +3571,10 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where
1 SIMPLE t2 ref f1 f1 4 test.t1.f1 3 Using index condition(BKA); Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
show status like "Handler_pushed%";
Variable_name Value
Handler_pushed_index_cond_checks 80
Handler_pushed_index_cond_filtered 64
drop table t1,t2;
set join_cache_level=default;
#
......
......@@ -814,5 +814,32 @@ COUNT(*)
1478
SET optimizer_switch=@save_optimizer_switch;
DROP TABLE t1,t2;
# check "Handler_pushed" status varuiables
CREATE TABLE t1 (
c1 CHAR(1),
c2 CHAR(1),
KEY (c1)
);
INSERT INTO t1 VALUES ('3', '3'),('4','4'),('5','5');
flush status;
show status like "Handler_pushed%";
Variable_name Value
Handler_pushed_index_cond_checks 0
Handler_pushed_index_cond_filtered 0
SELECT * FROM t1 FORCE INDEX(c1) WHERE (c1='3' or c1='4') and c1 % 2 = 0 ;
c1 c2
4 4
show status like "Handler_pushed%";
Variable_name Value
Handler_pushed_index_cond_checks 2
Handler_pushed_index_cond_filtered 1
SELECT * FROM t1 WHERE (c2='3' or c2='4') and c2 % 2 = 0 ;
c1 c2
4 4
show status like "Handler_pushed%";
Variable_name Value
Handler_pushed_index_cond_checks 2
Handler_pushed_index_cond_filtered 1
DROP TABLE t1;
set storage_engine= @save_storage_engine;
set optimizer_switch=@maria_icp_tmp;
......@@ -812,6 +812,33 @@ COUNT(*)
1478
SET optimizer_switch=@save_optimizer_switch;
DROP TABLE t1,t2;
# check "Handler_pushed" status varuiables
CREATE TABLE t1 (
c1 CHAR(1),
c2 CHAR(1),
KEY (c1)
);
INSERT INTO t1 VALUES ('3', '3'),('4','4'),('5','5');
flush status;
show status like "Handler_pushed%";
Variable_name Value
Handler_pushed_index_cond_checks 0
Handler_pushed_index_cond_filtered 0
SELECT * FROM t1 FORCE INDEX(c1) WHERE (c1='3' or c1='4') and c1 % 2 = 0 ;
c1 c2
4 4
show status like "Handler_pushed%";
Variable_name Value
Handler_pushed_index_cond_checks 2
Handler_pushed_index_cond_filtered 1
SELECT * FROM t1 WHERE (c2='3' or c2='4') and c2 % 2 = 0 ;
c1 c2
4 4
show status like "Handler_pushed%";
Variable_name Value
Handler_pushed_index_cond_checks 2
Handler_pushed_index_cond_filtered 1
DROP TABLE t1;
drop table if exists t0, t1, t1i, t1m;
#
# BUG#826935 Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index))' failed
......
......@@ -276,6 +276,8 @@ Handler_commit 0
Handler_delete 0
Handler_discover 0
Handler_prepare 0
Handler_pushed_index_cond_checks 0
Handler_pushed_index_cond_filtered 0
Handler_read_first 0
Handler_read_key 4
Handler_read_next 0
......@@ -297,7 +299,7 @@ Created_tmp_files 0
Created_tmp_tables 2
Handler_tmp_update 2
Handler_tmp_write 7
Rows_tmp_read 35
Rows_tmp_read 37
drop table t1;
CREATE TABLE t1 (i int(11) DEFAULT NULL, KEY i (i) ) ENGINE=MyISAM;
insert into t1 values (1),(2),(3),(4),(5);
......@@ -311,6 +313,8 @@ Handler_commit 0
Handler_delete 0
Handler_discover 0
Handler_prepare 0
Handler_pushed_index_cond_checks 0
Handler_pushed_index_cond_filtered 0
Handler_read_first 0
Handler_read_key 2
Handler_read_next 2
......
......@@ -101,6 +101,8 @@ Handler_commit 19
Handler_delete 1
Handler_discover 0
Handler_prepare 18
Handler_pushed_index_cond_checks 0
Handler_pushed_index_cond_filtered 0
Handler_read_first 0
Handler_read_key 3
Handler_read_next 0
......
......@@ -1526,12 +1526,14 @@ insert into t2 values (3,1, 'qwerty'),(3,4, 'qwerty');
insert into t2 values (4,1, 'qwerty'),(4,2, 'qwerty'),(4,3, 'qwerty'),
(4,4, 'qwerty');
flush status;
set join_cache_level=5;
select t2.f1, t2.f2, t2.f3 from t1,t2
where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1;
explain select t2.f1, t2.f2, t2.f3 from t1,t2
where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2;
show status like "Handler_pushed%";
set join_cache_level=6;
select t2.f1, t2.f2, t2.f3 from t1,t2
......@@ -1539,6 +1541,7 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1;
explain select t2.f1, t2.f2, t2.f3 from t1,t2
where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2;
show status like "Handler_pushed%";
set join_cache_level=7;
select t2.f1, t2.f2, t2.f3 from t1,t2
......@@ -1546,6 +1549,7 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1;
explain select t2.f1, t2.f2, t2.f3 from t1,t2
where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2;
show status like "Handler_pushed%";
set join_cache_level=8;
select t2.f1, t2.f2, t2.f3 from t1,t2
......@@ -1553,6 +1557,7 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1;
explain select t2.f1, t2.f2, t2.f3 from t1,t2
where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2;
show status like "Handler_pushed%";
drop table t1,t2;
set join_cache_level=default;
......
......@@ -8291,6 +8291,8 @@ SHOW_VAR status_vars[]= {
{"Handler_mrr_init", (char*) offsetof(STATUS_VAR, ha_multi_range_read_init_count), SHOW_LONG_STATUS},
#endif
{"Handler_prepare", (char*) offsetof(STATUS_VAR, ha_prepare_count), SHOW_LONG_STATUS},
{"Handler_pushed_index_cond_checks",(char*) offsetof(STATUS_VAR, ha_pushed_index_cond_checks), SHOW_LONG_STATUS},
{"Handler_pushed_index_cond_filtered",(char*) offsetof(STATUS_VAR, ha_pushed_index_cond_filtered), SHOW_LONG_STATUS},
{"Handler_read_first", (char*) offsetof(STATUS_VAR, ha_read_first_count), SHOW_LONG_STATUS},
{"Handler_read_key", (char*) offsetof(STATUS_VAR, ha_read_key_count), SHOW_LONG_STATUS},
{"Handler_read_next", (char*) offsetof(STATUS_VAR, ha_read_next_count), SHOW_LONG_STATUS},
......
......@@ -588,6 +588,8 @@ typedef struct system_status_var
ulong ha_tmp_update_count;
ulong ha_tmp_write_count;
ulong ha_prepare_count;
ulong ha_pushed_index_cond_checks;
ulong ha_pushed_index_cond_filtered;
ulong ha_discover_count;
ulong ha_savepoint_count;
ulong ha_savepoint_rollback_count;
......
......@@ -2576,6 +2576,15 @@ void JOIN_CACHE::print_explain_comment(String *str)
str->append(STRING_WITH_LEN(")"));
}
/**
get thread handle.
*/
THD *JOIN_CACHE::thd()
{
return join->thd;
}
static void add_mrr_explain_info(String *str, uint mrr_mode, handler *file)
{
......@@ -4015,7 +4024,11 @@ bool bka_skip_index_tuple(range_seq_t rseq, range_id_t range_info)
{
DBUG_ENTER("bka_skip_index_tuple");
JOIN_CACHE_BKA *cache= (JOIN_CACHE_BKA *) rseq;
bool res= cache->skip_index_tuple(range_info);
THD *thd= cache->thd();
bool res;
status_var_increment(thd->status_var.ha_pushed_index_cond_checks);
if ((res= cache->skip_index_tuple(range_info)))
status_var_increment(thd->status_var.ha_pushed_index_cond_filtered);
DBUG_RETURN(res);
}
......@@ -4490,7 +4503,12 @@ bool bkah_skip_index_tuple(range_seq_t rseq, range_id_t range_info)
{
DBUG_ENTER("bka_unique_skip_index_tuple");
JOIN_CACHE_BKAH *cache= (JOIN_CACHE_BKAH *) rseq;
DBUG_RETURN(cache->skip_index_tuple(range_info));
THD *thd= cache->thd();
bool res;
status_var_increment(thd->status_var.ha_pushed_index_cond_checks);
if ((res= cache->skip_index_tuple(range_info)))
status_var_increment(thd->status_var.ha_pushed_index_cond_filtered);
DBUG_RETURN(res);
}
......
......@@ -643,6 +643,8 @@ public:
/* Add a comment on the join algorithm employed by the join cache */
virtual void print_explain_comment(String *str);
THD *thd();
virtual ~JOIN_CACHE() {}
void reset_join(JOIN *j) { join= j; }
void free()
......
......@@ -2248,12 +2248,18 @@ C_MODE_START
ICP_RESULT index_cond_func_maria(void *arg)
{
ha_maria *h= (ha_maria*)arg;
THD *thd= ((TABLE*) h->file->external_ref)->in_use;
ICP_RESULT res;
if (h->end_range)
{
if (h->compare_key2(h->end_range) > 0)
return ICP_OUT_OF_RANGE; /* caller should return HA_ERR_END_OF_FILE already */
}
return h->pushed_idx_cond->val_int() ? ICP_MATCH : ICP_NO_MATCH;
status_var_increment(thd->status_var.ha_pushed_index_cond_checks);
if ((res= h->pushed_idx_cond->val_int() ? ICP_MATCH : ICP_NO_MATCH) ==
ICP_NO_MATCH)
status_var_increment(thd->status_var.ha_pushed_index_cond_filtered);
return res;
}
C_MODE_END
......
......@@ -1770,12 +1770,18 @@ C_MODE_START
ICP_RESULT index_cond_func_myisam(void *arg)
{
ha_myisam *h= (ha_myisam*)arg;
THD *thd= ((TABLE*) h->file->external_ref)->in_use;
ICP_RESULT res;
if (h->end_range)
{
if (h->compare_key2(h->end_range) > 0)
return ICP_OUT_OF_RANGE; /* caller should return HA_ERR_END_OF_FILE already */
}
return (ICP_RESULT) test(h->pushed_idx_cond->val_int());
status_var_increment(thd->status_var.ha_pushed_index_cond_checks);
if ((res= (ICP_RESULT) test(h->pushed_idx_cond->val_int())) ==
ICP_NO_MATCH)
status_var_increment(thd->status_var.ha_pushed_index_cond_filtered);
return res;
}
C_MODE_END
......
......@@ -12583,6 +12583,8 @@ innobase_index_cond(
void* file) /*!< in/out: pointer to ha_innobase */
{
ha_innobase *h= (ha_innobase*) file;
THD *thd= h->thd();
enum icp_result res;
if (h->is_thd_killed())
return ICP_ABORTED_BY_USER;
......@@ -12592,7 +12594,11 @@ innobase_index_cond(
if (h->compare_key2(h->end_range) > 0)
return ICP_OUT_OF_RANGE; /* caller should return HA_ERR_END_OF_FILE already */
}
return h->pushed_idx_cond->val_int()? ICP_MATCH : ICP_NO_MATCH;
status_var_increment(thd->status_var.ha_pushed_index_cond_checks);
if ((res= h->pushed_idx_cond->val_int()? ICP_MATCH : ICP_NO_MATCH) ==
ICP_NO_MATCH)
status_var_increment(thd->status_var.ha_pushed_index_cond_filtered);
return res;
}
/** Attempt to push down an index condition.
......
......@@ -223,6 +223,8 @@ class ha_innobase: public handler
bool check_if_incompatible_data(HA_CREATE_INFO *info,
uint table_changes);
bool check_if_supported_virtual_columns(void) { return TRUE; }
THD *thd() { return user_thd; }
private:
/** Builds a 'template' to the prebuilt struct.
......
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