Commit c037cdad authored by Monty's avatar Monty

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.
parent a24d0926
...@@ -145,8 +145,8 @@ teststring ...@@ -145,8 +145,8 @@ teststring
teststring teststring
select * from t1 where text1='teststring' or text1 >= 'teststring\t'; select * from t1 where text1='teststring' or text1 >= 'teststring\t';
text1 text1
teststring
teststring teststring
teststring
select * from t1 order by text1; select * from t1 order by text1;
text1 text1
nothing nothing
......
...@@ -178,7 +178,7 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -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 1 SIMPLE t1 range btn btn 10 NULL 1 Using where
explain select * from t1 where btn like "h%"; explain select * from t1 where btn like "h%";
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 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%"; explain select * from t1 where btn like "a%";
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 range btn btn 10 NULL 1 Using where 1 SIMPLE t1 range btn btn 10 NULL 1 Using where
......
...@@ -428,14 +428,14 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -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 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); select 0+a from t1 where a in (869751,736494,226312,802616,728912);
0+a 0+a
869751
736494
226312 226312
802616
728912 728912
736494
802616
869751
explain select 0+a from t1 where a in (869751,736494,226312,802616,728912); 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 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; drop table t1;
End of 5.3 tests End of 5.3 tests
# #
......
...@@ -2675,11 +2675,13 @@ double handler::keyread_time(uint index, uint ranges, ha_rows rows) ...@@ -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; size_t len= table->key_info[index].key_length + ref_length;
if (index == table->s->primary_key && table->file->primary_key_is_clustered()) if (index == table->s->primary_key && table->file->primary_key_is_clustered())
len= table->s->stored_rec_length; 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; double cost= (double)rows*len/(stats.block_size+1)*IDX_BLOCK_COPY_COST;
if (ranges) 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; cost+= blocks;
}
return cost; return cost;
} }
......
...@@ -4897,7 +4897,8 @@ double get_sweep_read_cost(const PARAM *param, ha_rows records) ...@@ -4897,7 +4897,8 @@ double get_sweep_read_cost(const PARAM *param, ha_rows records)
{ {
double result; double result;
DBUG_ENTER("get_sweep_read_cost"); 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. We are using the primary key to find the rows.
......
...@@ -65,8 +65,9 @@ class ha_heap: public handler ...@@ -65,8 +65,9 @@ class ha_heap: public handler
double scan_time() double scan_time()
{ return (double) (stats.records+stats.deleted) / 20.0+10; } { return (double) (stats.records+stats.deleted) / 20.0+10; }
double read_time(uint index, uint ranges, ha_rows rows) 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 open(const char *name, int mode, uint test_if_locked);
int close(void); int close(void);
void set_keys_for_scanning(void); void set_keys_for_scanning(void);
......
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