mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 03:52:35 +01:00
eb483c5181
- multi_range_read_info_const now uses the new records_in_range interface - Added handler::avg_io_cost() - Don't calculate avg_io_cost() in get_sweep_read_cost if avg_io_cost is not 1.0. In this case we trust the avg_io_cost() from the handler. - Changed test_quick_select to use TIME_FOR_COMPARE instead of TIME_FOR_COMPARE_IDX to align this with the rest of the code. - Fixed bug when using test_if_cheaper_ordering where we didn't use keyread if index was changed - Fixed a bug where we didn't use index only read when using order-by-index - 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 get_sweep_read_cost() for HEAP tables - Ensure that range and ref have same cost for simple ranges Added a small cost (MULTI_RANGE_READ_SETUP_COST) to ranges to ensure we favior ref for range for simple queries. - Fixed that matching_candidates_in_table() uses same number of records as the rest of the optimizer - Added avg_io_cost() to JT_EQ_REF cost. This helps calculate the cost for HEAP and temporary tables better. A few tests changed because of this. - heap::read_time() and heap::keyread_time() adjusted to not add +1. This was to ensure that handler::keyread_time() doesn't give higher cost for heap tables than for normal tables. One effect of this is that heap and derived tables stored in heap will prefer key access as this is now regarded as cheap. - Changed cost for index read in sql_select.cc to match multi_range_read_info_const(). All index cost calculation is now done trough one function. - 'ref' will now use quick_cost for keys if it exists. This is done so that for '=' ranges, 'ref' is prefered over 'range'. - scan_time() now takes avg_io_costs() into account - get_delayed_table_estimates() uses block_size and avg_io_cost() - Removed default argument to test_if_order_by_key(); simplifies code
71 lines
4 KiB
Text
71 lines
4 KiB
Text
set @save_userstat=@@global.userstat;
|
|
set global userstat=1;
|
|
create table just_a_test(id int,first_name varchar(10),last_name varchar(10),address varchar(100),phone bigint,email varchar(30), state varchar(30));
|
|
insert into just_a_test values(1,'fa','la','china_a',11111111,'fa_la@163.com','California'),
|
|
(2,'fb','lb','china_b',22222222,'fb_lb@163.com','Arizona'),
|
|
(3,'fc','lc','china_c',33333333,'fc_lc@163.com','California'),
|
|
(4,'fd','ld','china_d',44444444,'fd_ld@163.com','Utah'),
|
|
(5,'fe','le','china_e',55555555,'fe_le@163.com','Arizona');
|
|
alter table just_a_test add primary key (id);
|
|
alter table just_a_test add key IND_just_a_test_first_name_last_name(first_name,last_name);
|
|
alter table just_a_test add key IND_just_a_test_state(state);
|
|
select count(*) from just_a_test where first_name='fc' and last_name='lc';
|
|
count(*)
|
|
1
|
|
select count(*) from just_a_test where state = 'California';
|
|
count(*)
|
|
2
|
|
select * from information_schema.index_statistics where table_schema='test' and table_name='just_a_test';
|
|
TABLE_SCHEMA TABLE_NAME INDEX_NAME ROWS_READ
|
|
test just_a_test IND_just_a_test_first_name_last_name 1
|
|
test just_a_test IND_just_a_test_state 2
|
|
select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
|
|
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES
|
|
test just_a_test 18 5 5
|
|
alter table just_a_test drop key IND_just_a_test_first_name_last_name;
|
|
select * from information_schema.index_statistics where table_schema='test' and table_name='just_a_test';
|
|
TABLE_SCHEMA TABLE_NAME INDEX_NAME ROWS_READ
|
|
test just_a_test IND_just_a_test_state 2
|
|
select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
|
|
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES
|
|
test just_a_test 23 5 5
|
|
alter table just_a_test drop column state;
|
|
select * from information_schema.index_statistics where table_schema='test' and table_name='just_a_test';
|
|
TABLE_SCHEMA TABLE_NAME INDEX_NAME ROWS_READ
|
|
select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
|
|
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES
|
|
test just_a_test 28 5 5
|
|
drop table just_a_test;
|
|
select * from information_schema.index_statistics where table_schema='test' and table_name='just_a_test';
|
|
TABLE_SCHEMA TABLE_NAME INDEX_NAME ROWS_READ
|
|
select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
|
|
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES
|
|
create table just_a_test(id int not null primary key,first_name varchar(10),last_name varchar(10),address varchar(100),phone bigint,email varchar(30), state varchar(30),key(first_name,last_name),key(state));
|
|
insert into just_a_test values(1,'fa','la','china_a',11111111,'fa_la@163.com','California'),
|
|
(2,'fb','lb','china_b',22222222,'fb_lb@163.com','Arizona'),
|
|
(3,'fc','lc','china_c',33333333,'fc_lc@163.com','California'),
|
|
(4,'fd','ld','china_d',44444444,'fd_ld@163.com','Utah'),
|
|
(5,'fe','le','china_e',55555555,'fe_le@163.com','Arizona');
|
|
select count(*) from just_a_test where first_name='fc' and last_name='lc';
|
|
count(*)
|
|
1
|
|
select count(*) from just_a_test where state = 'California';
|
|
count(*)
|
|
2
|
|
select count(*) from just_a_test where id between 2 and 4;
|
|
count(*)
|
|
3
|
|
select * from information_schema.index_statistics where table_schema='test' and table_name='just_a_test';
|
|
TABLE_SCHEMA TABLE_NAME INDEX_NAME ROWS_READ
|
|
test just_a_test PRIMARY 4
|
|
test just_a_test first_name 1
|
|
test just_a_test state 2
|
|
select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
|
|
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES
|
|
test just_a_test 7 5 15
|
|
drop table just_a_test;
|
|
select * from information_schema.index_statistics where table_schema='test' and table_name='just_a_test';
|
|
TABLE_SCHEMA TABLE_NAME INDEX_NAME ROWS_READ
|
|
select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
|
|
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES
|
|
set global userstat=@save_userstat;
|