diff options
author | Monty <monty@mariadb.org> | 2020-03-05 14:10:03 +0200 |
---|---|---|
committer | Monty <monty@mariadb.org> | 2020-03-09 13:53:34 +0200 |
commit | c037cdadf47fc6dd0546ddade9f9168bed8a3690 (patch) | |
tree | af0703eb5fcba6fdd521950a0767e1274c57d7e3 | |
parent | a24d0926b9459d715709d86a84a172cdce3b1bec (diff) | |
download | mariadb-git-c037cdadf47fc6dd0546ddade9f9168bed8a3690.tar.gz |
Added keyread_time() to HEAP
The default keyread_time() was optimized for blocks and not suitable for
HEAP. The effect was the HEAP prefered table scans over ranges for btree
indexes.
Fixed also get_sweep_read_cost() for HEAP tables.
-rw-r--r-- | mysql-test/main/endspace.result | 2 | ||||
-rw-r--r-- | mysql-test/suite/heap/heap_btree.result | 2 | ||||
-rw-r--r-- | mysql-test/suite/heap/heap_hash.result | 8 | ||||
-rw-r--r-- | sql/handler.cc | 6 | ||||
-rw-r--r-- | sql/opt_range.cc | 3 | ||||
-rw-r--r-- | storage/heap/ha_heap.h | 5 |
6 files changed, 15 insertions, 11 deletions
diff --git a/mysql-test/main/endspace.result b/mysql-test/main/endspace.result index a0f53167148..f9619db7e64 100644 --- a/mysql-test/main/endspace.result +++ b/mysql-test/main/endspace.result @@ -145,8 +145,8 @@ teststring teststring select * from t1 where text1='teststring' or text1 >= 'teststring\t'; text1 -teststring teststring +teststring select * from t1 order by text1; text1 nothing diff --git a/mysql-test/suite/heap/heap_btree.result b/mysql-test/suite/heap/heap_btree.result index 5985350a213..0f749386756 100644 --- a/mysql-test/suite/heap/heap_btree.result +++ b/mysql-test/suite/heap/heap_btree.result @@ -178,7 +178,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range btn btn 10 NULL 1 Using where explain select * from t1 where btn like "h%"; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL btn NULL NULL NULL # Using where +1 SIMPLE t1 range btn btn 10 NULL # Using where explain select * from t1 where btn like "a%"; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range btn btn 10 NULL 1 Using where diff --git a/mysql-test/suite/heap/heap_hash.result b/mysql-test/suite/heap/heap_hash.result index 1fbfa99c61f..df1acdae506 100644 --- a/mysql-test/suite/heap/heap_hash.result +++ b/mysql-test/suite/heap/heap_hash.result @@ -428,14 +428,14 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range uniq_id uniq_id 8 NULL 2 Using where select 0+a from t1 where a in (869751,736494,226312,802616,728912); 0+a -869751 -736494 226312 -802616 728912 +736494 +802616 +869751 explain select 0+a from t1 where a in (869751,736494,226312,802616,728912); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL uniq_id NULL NULL NULL 5 Using where +1 SIMPLE t1 range uniq_id uniq_id 8 NULL 5 Using where drop table t1; End of 5.3 tests # diff --git a/sql/handler.cc b/sql/handler.cc index 77b7f490590..5f69a70d5e2 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -2675,11 +2675,13 @@ double handler::keyread_time(uint index, uint ranges, ha_rows rows) size_t len= table->key_info[index].key_length + ref_length; if (index == table->s->primary_key && table->file->primary_key_is_clustered()) len= table->s->stored_rec_length; - uint keys_per_block= (uint) (stats.block_size/2.0/len+1); - ulonglong blocks= !rows ? 0 : (rows-1) / keys_per_block + 1; double cost= (double)rows*len/(stats.block_size+1)*IDX_BLOCK_COPY_COST; if (ranges) + { + uint keys_per_block= (uint) (stats.block_size/2.0/len+1); + ulonglong blocks= !rows ? 0 : (rows-1) / keys_per_block + 1; cost+= blocks; + } return cost; } diff --git a/sql/opt_range.cc b/sql/opt_range.cc index a1982e246a7..4a7bbd9770b 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -4897,7 +4897,8 @@ double get_sweep_read_cost(const PARAM *param, ha_rows records) { double result; DBUG_ENTER("get_sweep_read_cost"); - if (param->table->file->primary_key_is_clustered()) + if (param->table->file->primary_key_is_clustered() || + param->table->file->stats.block_size == 0 /* HEAP */) { /* We are using the primary key to find the rows. diff --git a/storage/heap/ha_heap.h b/storage/heap/ha_heap.h index 3440c8fd205..370906bd1f6 100644 --- a/storage/heap/ha_heap.h +++ b/storage/heap/ha_heap.h @@ -65,8 +65,9 @@ public: double scan_time() { return (double) (stats.records+stats.deleted) / 20.0+10; } double read_time(uint index, uint ranges, ha_rows rows) - { return (double) rows / 20.0+1; } - + { return (double) rows / 20.0+1; } + double keyread_time(uint index, uint ranges, ha_rows rows) + { return (double) rows / 20.0+1; } int open(const char *name, int mode, uint test_if_locked); int close(void); void set_keys_for_scanning(void); |