mirror of
https://github.com/MariaDB/server.git
synced 2025-04-25 08:29:58 +02:00

Before this patch, when calculating the cost of fetching and using a row/key from the engine, we took into account the cost of finding a row or key from the engine, but did not consistently take into account index only accessed, clustered key or covered keys for all access paths. The cost of the WHERE clause (TIME_FOR_COMPARE) was not consistently considered in best_access_path(). TIME_FOR_COMPARE was used in calculation in other places, like greedy_search(), but was in some cases (like scans) done an a different number of rows than was accessed. The cost calculation of row and index scans didn't take into account the number of rows that where accessed, only the number of accepted rows. When using a filter, the cost of index_only_reads and cost of accessing and disregarding 'filtered rows' where not taken into account, which made filters cost less than there actually where. To remedy the above, the following key & row fetch related costs has been added: - The cost of fetching and using a row is now split into different costs: - key + Row fetch cost (as before) but multiplied with the variable 'optimizer_cache_cost' (default to 0.5). This allows the user to tell the optimizer the likehood of finding the key and row in the engine cache. - ROW_COPY_COST, The cost copying a row from the engine to the sql layer or creating a row from the join_cache to the record buffer. Mostly affects table scan costs. - ROW_LOOKUP_COST, the cost of fetching a row by rowid. - KEY_COPY_COST the cost of finding the next key and copying it from the engine to the SQL layer. This is used when we calculate the cost index only reads. It makes index scans more expensive than before if they cover a lot of rows. (main.index_merge_myisam) - KEY_LOOKUP_COST, the cost of finding the first key in a range. This replaces the old define IDX_LOOKUP_COST, but with a higher cost. - KEY_NEXT_FIND_COST, the cost of finding the next key (and rowid). when doing a index scan and comparing the rowid to the filter. Before this cost was assumed to be 0. All of the above constants/variables are now tuned to be somewhat in proportion of executing complexity to each other. There is tuning need for these in the future, but that can wait until the above are made user variables as that will make tuning much easier. To make the usage of the above easy, there are new (not virtual) cost calclation functions in handler: - ha_read_time(), like read_time(), but take optimizer_cache_cost into account. - ha_read_and_copy_time(), like ha_read_time() but take into account ROW_COPY_TIME - ha_read_and_compare_time(), like ha_read_and_copy_time() but take TIME_FOR_COMPARE into account. - ha_rnd_pos_time(). Read row with row id, taking ROW_COPY_COST into account. This is used with filesort where we don't need to execute the WHERE clause again. - ha_keyread_time(), like keyread_time() but take optimizer_cache_cost into account. - ha_keyread_and_copy_time(), like ha_keyread_time(), but add KEY_COPY_COST. - ha_key_scan_time(), like key_scan_time() but take optimizer_cache_cost nto account. - ha_key_scan_and_compare_time(), like ha_key_scan_time(), but add KEY_COPY_COST & TIME_FOR_COMPARE. I also added some setup costs for doing different types of scans and creating temporary tables (on disk and in memory). This encourages the optimizer to not use these for simple 'a few row' lookups if there are adequate key lookup strategies. - TABLE_SCAN_SETUP_COST, cost of starting a table scan. - INDEX_SCAN_SETUP_COST, cost of starting an index scan. - HEAP_TEMPTABLE_CREATE_COST, cost of creating in memory temporary table. - DISK_TEMPTABLE_CREATE_COST, cost of creating an on disk temporary table. When calculating cost of fetching ranges, we had a cost of IDX_LOOKUP_COST (0.125) for doing a key div for a new range. This is now replaced with 'io_cost * KEY_LOOKUP_COST (1.0) * optimizer_cache_cost', which matches the cost we use for 'ref' and other key lookups. The effect is that the cost is now a bit higher when we have many ranges for a key. Allmost all calculation with TIME_FOR_COMPARE is now done in best_access_path(). 'JOIN::read_time' now includes the full cost for finding the rows in the table. In the result files, many of the changes are now again close to what they where before the "Update cost for hash and cached joins" commit, as that commit didn't fix the filter cost (too complex to do everything in one commit). The above changes showed a lot of a lot of inconsistencies in optimizer cost calculation. The main objective with the other changes was to do calculation as similar (and accurate) as possible and to make different plans more comparable. Detailed list of changes: - Calculate index_only_cost consistently and correctly for all scan and ref accesses. The row fetch_cost and index_only_cost now takes into account clustered keys, covered keys and index only accesses. - cost_for_index_read now returns both full cost and index_only_cost - Fixed cost calculation of get_sweep_read_cost() to match other similar costs. This is bases on the assumption that data is more often stored on SSD than a hard disk. - Replaced constant 2.0 with new define TABLE_SCAN_SETUP_COST. - Some scan cost estimates did not take into account TIME_FOR_COMPARE. Now all scan costs takes this into account. (main.show_explain) - Added session variable optimizer_cache_hit_ratio (default 50%). By adjusting this on can reduce or increase the cost of index or direct record lookups. The effect of the default is that key lookups is now a bit cheaper than before. See usage of 'optimizer_cache_cost' in handler.h. - JOIN_TAB::scan_time() did not take into account index only scans, which produced a wrong cost when index scan was used. Changed JOIN_TAB:::scan_time() to take into consideration clustered and covered keys. The values are now cached and we only have to call this function once. Other calls are changed to use the cached values. Function renamed to JOIN_TAB::estimate_scan_time(). - Fixed that most index cost calculations are done the same way and more close to 'range' calculations. The cost is now lower than before for small data sets and higher for large data sets as we take into account how many keys are read (main.opt_trace_selectivity, main.limit_rows_examined). - Ensured that index_scan_cost() == range(scan_of_all_rows_in_table_using_one_range) + MULTI_RANGE_READ_INFO_CONST. One effect of this is that if there is choice of doing a full index scan and a range-index scan over almost the whole table then index scan will be preferred (no range-read setup cost). (innodb.innodb, main.show_explain, main.range) - Fixed the EQ_REF and REF takes into account clustered and covered keys. This changes some plans to use covered or clustered indexes as these are much cheaper. (main.subselect_mat_cost, main.state_tables_innodb, main.limit_rows_examined) - Rowid filter setup cost and filter compare cost now takes into account fetching and checking the rowid (KEY_NEXT_FIND_COST). (main.partition_pruning heap.heap_btree main.log_state) - Added KEY_NEXT_FIND_COST to Range_rowid_filter_cost_info::lookup_cost to account of the time to find and check the next key value against the container - Introduced ha_keyread_time(rows) that takes into account finding the next row and copying the key value to 'record' (KEY_COPY_COST). - Introduced ha_key_scan_time() for calculating an index scan over all rows. - Added IDX_LOOKUP_COST to keyread_time() as a startup cost. - Added index_only_fetch_cost() as a convenience function to OPT_RANGE. - keyread_time() cost is slightly reduced to prefer shorter keys. (main.index_merge_myisam) - All of the above caused some index_merge combinations to be rejected because of cost (main.index_intersect). In some cases 'ref' where replaced with index_merge because of the low cost calculation of get_sweep_read_cost(). - Some index usage moved from PRIMARY to a covering index. (main.subselect_innodb) - Changed cost calculation of filter to take KEY_LOOKUP_COST and TIME_FOR_COMPARE into account. See sql_select.cc::apply_filter(). filter parameters and costs are now written to optimizer_trace. - Don't use matchings_records_in_range() to try to estimate the number of filtered rows for ranges. The reason is that we want to ensure that 'range' is calculated similar to 'ref'. There is also more work needed to calculate the selectivity when using ranges and ranges and filtering. This causes filtering column in EXPLAIN EXTENDED to be 100.00 for some cases where range cannot use filtering. (main.rowid_filter) - Introduced ha_scan_time() that takes into account the CPU cost of finding the next row and copying the row from the engine to 'record'. This causes costs of table scan to slightly increase and some test to changed their plan from ALL to RANGE or ALL to ref. (innodb.innodb_mysql, main.select_pkeycache) In a few cases where scan time of very small tables have lower cost than a ref or range, things changed from ref/range to ALL. (main.myisam, main.func_group, main.limit_rows_examined, main.subselect2) - Introduced ha_scan_and_compare_time() which is like ha_scan_time() but also adds the cost of the where clause (TIME_FOR_COMPARE). - Added small cost for creating temporary table for materialization. This causes some very small tables to use scan instead of materialization. - Added checking of the WHERE clause (TIME_FOR_COMPARE) of the accepted rows to ROR costs in get_best_ror_intersect() - Removed '- 0.001' from 'join->best_read' and optimize_straight_join() to ensure that the 'Last_query_cost' status variable contains the same value as the one that was calculated by the optimizer. - Take avg_io_cost() into account in handler::keyread_time() and handler::read_time(). This should have no effect as it's 1.0 by default, except for heap that overrides these functions. - Some 'ref_or_null' accesses changed to 'range' because of cost adjustments (main.order_by) - Added scan type "scan_with_join_cache" for optimizer_trace. This is just to show in the trace what kind of scan was used. - When using 'scan_with_join_cache' take into account number of preceding tables (as have to restore all fields for all previous table combination when checking the where clause) The new cost added is: (row_combinations * ROW_COPY_COST * number_of_cached_tables). This increases the cost of join buffering in proportion of the number of tables in the join buffer. One effect is that full scans are now done earlier as the cost is then smaller. (main.join_outer_innodb, main.greedy_optimizer) - Removed the usage of 'worst_seeks' in cost_for_index_read as it caused wrong plans to be created; It prefered JT_EQ_REF even if it would be much more expensive than a full table scan. A related issue was that worst_seeks only applied to full lookup, not to clustered or index only lookups, which is not consistent. This caused some plans to use index scan instead of eq_ref (main.union) - Changed federated block size from 4096 to 1500, which is the typical size of an IO packet. - Added costs for reading rows to Federated. Needed as there is no caching of rows in the federated engine. - Added ha_innobase::rnd_pos_time() cost function. - A lot of extra things added to optimizer trace - More costs, especially for materialization and index_merge. - Make lables more uniform - Fixed a lot of minor bugs - Added 'trace_started()' around a lot of trace blocks. - When calculating ORDER BY with LIMIT cost for using an index the cost did not take into account the number of row retrivals that has to be done or the cost of comparing the rows with the WHERE clause. The cost calculated would be just a fraction of the real cost. Now we calculate the cost as we do for ranges and 'ref'. - 'Using index for group-by' is used a bit more than before as now take into account the WHERE clause cost when comparing with 'ref' and prefer the method with fewer row combinations. (main.group_min_max). Bugs fixed: - Fixed that we don't calculate TIME_FOR_COMPARE twice for some plans, like in optimize_straight_join() and greedy_search() - Fixed bug in save_explain_data where we could test for the wrong index when displaying 'Using index'. This caused some old plans to show 'Using index'. (main.subselect_innodb, main.subselect2) - Fixed bug in get_best_ror_intersect() where 'min_cost' was not updated, and the cost we compared with was not the one that was used. - Fixed very wrong cost calculation for priority queues in check_if_pq_applicable(). (main.order_by now correctly uses priority queue) - When calculating cost of EQ_REF or REF, we added the cost of comparing the WHERE clause with the found rows, not all row combinations. This made ref and eq_ref to be regarded way to cheap compared to other access methods. - FORCE INDEX cost calculation didn't take into account clustered or covered indexes. - JT_EQ_REF cost was estimated as avg_io_cost(), which is half the cost of a JT_REF key. This may be true for InnoDB primary key, but not for other unique keys or other engines. Now we use handler function to calculate the cost, which allows us to handle consistently clustered, covered keys and not covered keys. - ha_start_keyread() didn't call extra_opt() if keyread was already enabled but still changed the 'keyread' variable (which is wrong). Fixed by not doing anything if keyread is already enabled. - multi_range_read_info_cost() didn't take into account io_cost when calculating the cost of ranges. - fix_semijoin_strategies_for_picked_join_order() used the wrong record_count when calling best_access_path() for SJ_OPT_FIRST_MATCH and SJ_OPT_LOOSE_SCAN. - Hash joins didn't provide correct best_cost to the upper level, which means that the cost for hash_joins more expensive than calculated in best_access_path (a difference of 10x * TIME_OF_COMPARE). This is fixed in the new code thanks to that we now include TIME_OF_COMPARE cost in 'read_time'. Other things: - Added some 'if (thd->trace_started())' to speed up code - Removed not used function Cost_estimate::is_zero() - Simplified testing of HA_POS_ERROR in get_best_ror_intersect(). (No cost changes) - Moved ha_start_keyread() from join_read_const_table() to join_read_const() to enable keyread for all types of JT_CONST tables. - Made a few very short functions inline in handler.h Notes: - In main.rowid_filter the join order of order and lineitem is swapped. This is because the cost of doing a range fetch of lineitem(98 rows) is almost as big as the whole join of order,lineitem. The filtering will also ensure that we only have to do very small key fetches of the rows in lineitem. - main.index_merge_myisam had a few changes where we are now using less keys for index_merge. This is because index scans are now more expensive than before. - handler->optimizer_cache_cost is updated in ha_external_lock(). This ensures that it is up to date per statements. Not an optimal solution (for locked tables), but should be ok for now. - 'DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a' does not take cost of filesort into consideration when table scan is chosen. (main.myisam_explain_non_select_all) - perfschema.table_aggregate_global_* has changed because an update on a table with 1 row will now use table scan instead of key lookup. TODO in upcomming commits: - Fix selectivity calculation for ranges with and without filtering and when there is a ref access but scan is chosen. For this we have to store the lowest known value for 'accepted_records' in the OPT_RANGE structure. - Change that records_read does not include filtered rows. - test_if_cheaper_ordering() needs to be updated to properly calculate costs. This will fix tests like main.order_by_innodb, main.single_delete_update - Extend get_range_limit_read_cost() to take into considering cost_for_index_read() if there where no quick keys. This will reduce the computed cost for ORDER BY with LIMIT in some cases. (main.innodb_ext_key) - Fix that we take into account selectivity when counting the number of rows we have to read when considering using a index table scan to resolve ORDER BY. - Add new calculation for rnd_pos_time() where we take into account the benefit of reading multiple rows from the same page.
893 lines
28 KiB
Text
893 lines
28 KiB
Text
SET @@session.default_storage_engine = 'MyISAM';
|
|
# - UNIQUE KEY
|
|
# - INDEX
|
|
# - FULLTEXT INDEX
|
|
# - SPATIAL INDEX (not supported)
|
|
# - FOREIGN INDEX (partially supported)
|
|
# - CHECK (allowed but not used)
|
|
# UNIQUE
|
|
create table t1 (a int, b int generated always as (a*2) virtual unique);
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` int(11) DEFAULT NULL,
|
|
`b` int(11) GENERATED ALWAYS AS (`a` * 2) VIRTUAL,
|
|
UNIQUE KEY `b` (`b`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
describe t1;
|
|
Field Type Null Key Default Extra
|
|
a int(11) YES NULL
|
|
b int(11) YES UNI NULL VIRTUAL GENERATED
|
|
drop table t1;
|
|
create table t1 (a int, b int generated always as (a*2) stored unique);
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` int(11) DEFAULT NULL,
|
|
`b` int(11) GENERATED ALWAYS AS (`a` * 2) STORED,
|
|
UNIQUE KEY `b` (`b`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
describe t1;
|
|
Field Type Null Key Default Extra
|
|
a int(11) YES NULL
|
|
b int(11) YES UNI NULL STORED GENERATED
|
|
drop table t1;
|
|
create table t1 (a int, b int generated always as (a*2) virtual, unique key (b));
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` int(11) DEFAULT NULL,
|
|
`b` int(11) GENERATED ALWAYS AS (`a` * 2) VIRTUAL,
|
|
UNIQUE KEY `b` (`b`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
describe t1;
|
|
Field Type Null Key Default Extra
|
|
a int(11) YES NULL
|
|
b int(11) YES UNI NULL VIRTUAL GENERATED
|
|
drop table t1;
|
|
create table t1 (a int, b int generated always as (a*2) stored, unique (b));
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` int(11) DEFAULT NULL,
|
|
`b` int(11) GENERATED ALWAYS AS (`a` * 2) STORED,
|
|
UNIQUE KEY `b` (`b`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
describe t1;
|
|
Field Type Null Key Default Extra
|
|
a int(11) YES NULL
|
|
b int(11) YES UNI NULL STORED GENERATED
|
|
drop table t1;
|
|
create table t1 (a int, b int generated always as (a*2) virtual);
|
|
alter table t1 add unique key (b);
|
|
drop table t1;
|
|
create table t1 (a int, b int generated always as (a*2) stored);
|
|
alter table t1 add unique key (b);
|
|
drop table t1;
|
|
# Testing data manipulation operations involving UNIQUE keys
|
|
# on generated columns can be found in:
|
|
# - gcol_ins_upd.inc
|
|
# - gcol_select.inc
|
|
#
|
|
# INDEX
|
|
create table t1 (a int, b int generated always as (a*2) virtual, index (b));
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` int(11) DEFAULT NULL,
|
|
`b` int(11) GENERATED ALWAYS AS (`a` * 2) VIRTUAL,
|
|
KEY `b` (`b`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
describe t1;
|
|
Field Type Null Key Default Extra
|
|
a int(11) YES NULL
|
|
b int(11) YES MUL NULL VIRTUAL GENERATED
|
|
drop table t1;
|
|
create table t1 (a int, b int generated always as (a*2) virtual, index (a,b));
|
|
drop table t1;
|
|
create table t1 (a int, b int generated always as (a*2) stored, index (b));
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` int(11) DEFAULT NULL,
|
|
`b` int(11) GENERATED ALWAYS AS (`a` * 2) STORED,
|
|
KEY `b` (`b`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
describe t1;
|
|
Field Type Null Key Default Extra
|
|
a int(11) YES NULL
|
|
b int(11) YES MUL NULL STORED GENERATED
|
|
drop table t1;
|
|
create table t1 (a int, b int generated always as (a*2) stored, index (a,b));
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` int(11) DEFAULT NULL,
|
|
`b` int(11) GENERATED ALWAYS AS (`a` * 2) STORED,
|
|
KEY `a` (`a`,`b`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
describe t1;
|
|
Field Type Null Key Default Extra
|
|
a int(11) YES MUL NULL
|
|
b int(11) YES NULL STORED GENERATED
|
|
drop table t1;
|
|
create table t1 (a int, b int generated always as (a*2) virtual);
|
|
alter table t1 add index (b);
|
|
alter table t1 add index (a,b);
|
|
drop table t1;
|
|
create table t1 (a int, b int generated always as (a*2) stored);
|
|
alter table t1 add index (b);
|
|
drop table t1;
|
|
create table t1 (a int, b int generated always as (a*2) stored);
|
|
alter table t1 add index (a,b);
|
|
create table t2 like t1;
|
|
drop table t2;
|
|
drop table t1;
|
|
# Testing data manipulation operations involving INDEX
|
|
# on generated columns can be found in:
|
|
# - gcol_select.inc
|
|
#
|
|
# TODO: FULLTEXT INDEX
|
|
# SPATIAL INDEX
|
|
# Error "All parts of a SPATIAL index must be geometrical"
|
|
create table t1 (a int, b int generated always as (a+1) stored, spatial index (b));
|
|
ERROR HY000: Incorrect arguments to SPATIAL INDEX
|
|
create table t1 (a int, b int generated always as (a+1) stored);
|
|
alter table t1 add spatial index (b);
|
|
ERROR HY000: Incorrect arguments to SPATIAL INDEX
|
|
drop table t1;
|
|
# FOREIGN KEY
|
|
# Rejected FK options.
|
|
create table t1 (a int, b int generated always as (a+1) stored,
|
|
foreign key (b) references t2(a) on update set null);
|
|
ERROR HY000: Cannot define foreign key with ON UPDATE SET NULL clause on a generated column
|
|
create table t1 (a int, b int generated always as (a+1) stored,
|
|
foreign key (b) references t2(a) on update cascade);
|
|
ERROR HY000: Cannot define foreign key with ON UPDATE CASCADE clause on a generated column
|
|
create table t1 (a int, b int generated always as (a+1) stored,
|
|
foreign key (b) references t2(a) on delete set null);
|
|
ERROR HY000: Cannot define foreign key with ON DELETE SET NULL clause on a generated column
|
|
create table t1 (a int, b int generated always as (a+1) stored);
|
|
alter table t1 add foreign key (b) references t2(a) on update set null;
|
|
ERROR HY000: Cannot define foreign key with ON UPDATE SET NULL clause on a generated column
|
|
alter table t1 add foreign key (b) references t2(a) on update cascade;
|
|
ERROR HY000: Cannot define foreign key with ON UPDATE CASCADE clause on a generated column
|
|
alter table t1 add foreign key (b) references t2(a) on delete set null;
|
|
ERROR HY000: Cannot define foreign key with ON DELETE SET NULL clause on a generated column
|
|
drop table t1;
|
|
# Allowed FK options.
|
|
create table t2 (a int primary key, b char(5));
|
|
create table t1 (a int, b int generated always as (a % 10) stored,
|
|
foreign key (b) references t2(a) on update restrict);
|
|
drop table t1;
|
|
create table t1 (a int, b int generated always as (a % 10) stored,
|
|
foreign key (b) references t2(a) on update no action);
|
|
drop table t1;
|
|
create table t1 (a int, b int generated always as (a % 10) stored,
|
|
foreign key (b) references t2(a) on delete restrict);
|
|
drop table t1;
|
|
create table t1 (a int, b int generated always as (a % 10) stored,
|
|
foreign key (b) references t2(a) on delete cascade);
|
|
drop table t1;
|
|
create table t1 (a int, b int generated always as (a % 10) stored,
|
|
foreign key (b) references t2(a) on delete no action);
|
|
drop table t1,t2;
|
|
#
|
|
# Bug#20553262: WL8149: ASSERTION `DELSUM+(INT) Y/4-TEMP >= 0' FAILED
|
|
#
|
|
CREATE TABLE c (
|
|
pk integer AUTO_INCREMENT,
|
|
col_datetime_nokey DATETIME /*! NULL */,
|
|
col_time_nokey TIME /*! NULL */,
|
|
col_datetime_key DATETIME GENERATED ALWAYS AS
|
|
(ADDTIME(col_datetime_nokey, col_time_nokey)),
|
|
col_time_key TIME GENERATED ALWAYS AS
|
|
(ADDTIME(col_datetime_nokey, col_time_nokey)),
|
|
col_varchar_nokey VARCHAR(1) /*! NULL */,
|
|
PRIMARY KEY (pk),
|
|
KEY (col_time_key),
|
|
KEY (col_datetime_key));
|
|
INSERT INTO c ( col_time_nokey,col_datetime_nokey,col_varchar_nokey) values
|
|
('14:03:03.042673','2001-11-28 00:50:27.051028', 'c'),
|
|
('01:46:09.016386','2007-10-09 19:53:04.008332', NULL),
|
|
('16:21:18.052408','2001-11-08 21:02:12.009395', 'x'),
|
|
('18:56:33.027423','2003-04-01 00:00:00', 'i');
|
|
insert into c (col_time_nokey,col_datetime_nokey,col_varchar_nokey) select '10:10:10', '2021-12-24 01:50:27', 'z' from seq_1_to_10;
|
|
EXPLAIN SELECT
|
|
outr.col_time_key AS x
|
|
FROM c as outr
|
|
WHERE
|
|
outr.col_varchar_nokey in ('c', 'x', 'i')
|
|
AND (outr.col_time_key IS NULL OR
|
|
outr.col_datetime_key = '2009-09-27');
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE outr index_merge col_time_key,col_datetime_key col_time_key,col_datetime_key 4,6 NULL x x
|
|
SELECT
|
|
outr.col_time_key AS x
|
|
FROM c AS outr
|
|
WHERE
|
|
outr.col_varchar_nokey in ('c', 'x', 'i')
|
|
AND (outr.col_time_key IS NULL OR
|
|
outr.col_datetime_key = '2009-09-27');
|
|
x
|
|
DROP TABLE c;
|
|
#
|
|
# Bug#20913803: WL8149: SIG 11 IN DFIELD_DUP |
|
|
# INNOBASE/INCLUDE/DATA0DATA.IC:253
|
|
#
|
|
CREATE TABLE A (
|
|
col_varchar_nokey TEXT ,
|
|
col_varchar_key TEXT GENERATED ALWAYS AS (REPEAT(col_varchar_nokey, 1000)),
|
|
KEY (col_varchar_key(50))
|
|
);
|
|
INSERT INTO A (col_varchar_nokey) VALUES ('');
|
|
CREATE TABLE D (
|
|
pk INTEGER AUTO_INCREMENT,
|
|
col_date_nokey BLOB,
|
|
col_date_key BLOB GENERATED ALWAYS AS (REPEAT(col_date_nokey,1000)) VIRTUAL,
|
|
col_datetime_nokey LONGBLOB,
|
|
col_time_nokey LONGTEXT,
|
|
col_datetime_key LONGBLOB GENERATED ALWAYS AS (REPEAT(col_datetime_nokey, 1000)),
|
|
col_time_key LONGTEXT GENERATED ALWAYS AS (REPEAT(col_datetime_nokey, 1000)),
|
|
col_varchar_nokey TEXT,
|
|
col_varchar_key TEXT GENERATED ALWAYS AS (REPEAT(col_varchar_nokey, 1000)),
|
|
PRIMARY KEY (pk),
|
|
KEY (col_varchar_key(50)),
|
|
KEY (col_date_key(20)),
|
|
KEY (col_time_key(20)),
|
|
KEY (col_datetime_key(20)),
|
|
KEY (col_varchar_key(10), col_date_key(10), col_time_key(5), col_datetime_key(5))
|
|
);
|
|
INSERT INTO D (
|
|
col_date_nokey,
|
|
col_time_nokey,
|
|
col_datetime_nokey,
|
|
col_varchar_nokey
|
|
) VALUES ('', '', '', ''),('', '', '', '');
|
|
DELETE FROM OUTR1.* USING D AS OUTR1 RIGHT JOIN A AS OUTR2 ON
|
|
( OUTR1 . `col_varchar_nokey` = OUTR2 . `col_varchar_nokey` );
|
|
DROP TABLE IF EXISTS A,D;
|
|
#
|
|
# Bug#21024896: SIG 11 INNOBASE_ADD_ONE_VIRTUAL |
|
|
# INNOBASE/HANDLER/HANDLER0ALTER.CC
|
|
#
|
|
CREATE TABLE t1 (
|
|
col1 int(11) DEFAULT NULL,
|
|
col2 int(11) DEFAULT NULL,
|
|
col3 int(11) NOT NULL,
|
|
col4 int(11) DEFAULT NULL,
|
|
col5 int(11) GENERATED ALWAYS AS (col2 / col2) VIRTUAL,
|
|
col7 int(11) GENERATED ALWAYS AS (col5 + col5) VIRTUAL,
|
|
col8 int(11) GENERATED ALWAYS AS (col5 * col5) VIRTUAL,
|
|
col9 text,
|
|
col6 int(11) DEFAULT NULL,
|
|
PRIMARY KEY (`col3`),
|
|
UNIQUE KEY uidx (`col2`),
|
|
KEY idx (`col5`)
|
|
);
|
|
INSERT INTO t1(col1,col2,col3,col4,col9,col6)
|
|
VALUES(1,1,0,1,REPEAT(col1,1000),0), (3,2,1,1,REPEAT(col1,1000),NULL);
|
|
ALTER TABLE t1 ADD COLUMN extra INT;
|
|
DROP TABLE t1;
|
|
#
|
|
# Bug#21316860: WL8149:INNODB: FAILING ASSERTION:
|
|
# TEMPL->CLUST_REC_FIELD_NO != ULINT_UNDEFINED
|
|
#
|
|
CREATE TABLE t1 (
|
|
pk int(11) NOT NULL,
|
|
col_int_nokey int(11),
|
|
col_int_key int(11) GENERATED ALWAYS AS (col_int_nokey) VIRTUAL,
|
|
col_date_nokey date,
|
|
col_date_key date GENERATED ALWAYS AS (col_date_nokey) VIRTUAL,
|
|
PRIMARY KEY (pk),
|
|
UNIQUE KEY col_int_key (col_int_key)
|
|
);
|
|
ALTER TABLE t1 DROP COLUMN pk;
|
|
DROP TABLE t1;
|
|
# Remove the impact on PK choose by index on virtual generated column
|
|
CREATE TABLE t1 (
|
|
pk int(11) NOT NULL,
|
|
col_int_nokey int(11) DEFAULT NULL,
|
|
col_int_key int(11) GENERATED ALWAYS AS (col_int_nokey) VIRTUAL,
|
|
UNIQUE KEY col_int_key (col_int_key)
|
|
);
|
|
ALTER TABLE t1 add unique index idx(pk);
|
|
DESC t1;
|
|
Field Type Null Key Default Extra
|
|
pk int(11) NO PRI NULL
|
|
col_int_nokey int(11) YES NULL
|
|
col_int_key int(11) YES UNI NULL VIRTUAL GENERATED
|
|
DROP TABLE t1;
|
|
#
|
|
# Bug#21320151 WL8149: WRONG RESULT WITH INDEX SCAN
|
|
#
|
|
CREATE TABLE t1 (
|
|
id INTEGER NOT NULL,
|
|
b INTEGER GENERATED ALWAYS AS (id+1) VIRTUAL,
|
|
UNIQUE KEY (b)
|
|
);
|
|
INSERT INTO t1 (id) VALUES (2),(3),(4),(5),(6),(7),(8),(9),(10);
|
|
EXPLAIN SELECT b FROM t1 FORCE INDEX(b);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index NULL b 5 NULL 9 Using index
|
|
SELECT b FROM t1 FORCE INDEX(b);
|
|
b
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
|
8
|
|
9
|
|
10
|
|
11
|
|
EXPLAIN SELECT b FROM t1 FORCE INDEX(b) WHERE b BETWEEN 1 AND 5;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 range b b 5 NULL 3 Using where; Using index
|
|
SELECT b FROM t1 FORCE INDEX(b) WHERE b BETWEEN 1 AND 5;
|
|
b
|
|
3
|
|
4
|
|
5
|
|
DROP TABLE t1;
|
|
|
|
# Testing data manipulation operations involving FOREIGN KEY
|
|
# on generated columns can be found in:
|
|
# - gcol_ins_upd.inc
|
|
# - gcol_select.inc
|
|
#
|
|
# TODO: CHECK
|
|
#
|
|
# Test how optimizer picks indexes defined on a GC
|
|
#
|
|
CREATE TABLE t1 (f1 int, gc int AS (f1 + 1) STORED, UNIQUE(gc));
|
|
INSERT INTO t1(f1) VALUES (1),(2),(0),(9),(3),(4),(8),(7),(5),(6);
|
|
ANALYZE TABLE t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 analyze status Engine-independent statistics collected
|
|
test.t1 analyze status OK
|
|
# Should use index
|
|
SELECT * FROM t1 WHERE f1 + 1 > 7;
|
|
f1 gc
|
|
7 8
|
|
8 9
|
|
9 10
|
|
EXPLAIN SELECT * FROM t1 WHERE f1 + 1 > 7;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
|
|
SELECT * FROM t1 WHERE f1 + 1 = 7;
|
|
f1 gc
|
|
6 7
|
|
EXPLAIN SELECT * FROM t1 WHERE f1 + 1 = 7;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
|
|
SELECT * FROM t1 WHERE f1 + 1 IN (7,5);
|
|
f1 gc
|
|
4 5
|
|
6 7
|
|
EXPLAIN SELECT * FROM t1 WHERE f1 + 1 IN(7,5);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
|
|
SELECT * FROM t1 WHERE f1 + 1 BETWEEN 5 AND 7;
|
|
f1 gc
|
|
4 5
|
|
5 6
|
|
6 7
|
|
EXPLAIN SELECT * FROM t1 WHERE f1 + 1 BETWEEN 5 AND 7;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
|
|
# Check that expression isn't transformed for a disabled key
|
|
SELECT * FROM t1 IGNORE KEY (gc) WHERE f1 + 1 BETWEEN 5 AND 7;
|
|
f1 gc
|
|
4 5
|
|
5 6
|
|
6 7
|
|
EXPLAIN SELECT * FROM t1 IGNORE KEY (gc) WHERE f1 + 1 BETWEEN 5 AND 7;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
|
|
# Check that ORDER BY could be optimized
|
|
SELECT * FROM t1 ORDER BY f1 + 1;
|
|
f1 gc
|
|
0 1
|
|
1 2
|
|
2 3
|
|
3 4
|
|
4 5
|
|
5 6
|
|
6 7
|
|
7 8
|
|
8 9
|
|
9 10
|
|
EXPLAIN SELECT * FROM t1 ORDER BY f1 + 1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using filesort
|
|
EXPLAIN SELECT * FROM t1 IGNORE KEY (gc) ORDER BY f1 + 1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using filesort
|
|
# Check that GROUP BY could be optimized
|
|
SELECT f1 + 1, MAX(GC) FROM t1 GROUP BY f1 + 1;
|
|
f1 + 1 MAX(GC)
|
|
1 1
|
|
2 2
|
|
3 3
|
|
4 4
|
|
5 5
|
|
6 6
|
|
7 7
|
|
8 8
|
|
9 9
|
|
10 10
|
|
EXPLAIN SELECT f1 + 1, MAX(GC) FROM t1 GROUP BY f1 + 1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using temporary; Using filesort
|
|
EXPLAIN SELECT f1 + 1, MAX(GC)
|
|
FROM t1 IGNORE KEY (gc) GROUP BY f1 + 1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using temporary; Using filesort
|
|
# Shouldn't use index
|
|
SELECT * FROM t1 WHERE f1 + 1 > 7.0;
|
|
f1 gc
|
|
7 8
|
|
8 9
|
|
9 10
|
|
EXPLAIN SELECT * FROM t1 WHERE f1 + 1 > 7.0;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
|
|
DROP TABLE t1;
|
|
# Pick index with proper type
|
|
CREATE TABLE t1 (f1 int,
|
|
gc_int int AS (f1 + 1) STORED,
|
|
gc_date DATE AS (f1 + 1) STORED,
|
|
KEY gc_int_idx(gc_int),
|
|
KEY gc_date_idx(gc_date));
|
|
INSERT INTO t1(f1) VALUES
|
|
(030303),(040404),
|
|
(050505),(060606),
|
|
(010101),(020202),
|
|
(030303),(040404),
|
|
(050505),(060606),
|
|
(010101),(020202),
|
|
(090909),(101010),
|
|
(010101),(020202),
|
|
(070707),(080808);
|
|
ANALYZE TABLE t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 analyze status Engine-independent statistics collected
|
|
test.t1 analyze status OK
|
|
SELECT * FROM t1 WHERE f1 + 1 > 070707;
|
|
f1 gc_int gc_date
|
|
101010 101011 2010-10-11
|
|
70707 70708 2007-07-08
|
|
80808 80809 2008-08-09
|
|
90909 90910 2009-09-10
|
|
# INT column & index should be picked
|
|
EXPLAIN SELECT * FROM t1 WHERE f1 + 1 > 070707;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 18 Using where
|
|
SELECT * FROM t1 WHERE f1 + 1 > CAST(070707 AS DATE);
|
|
f1 gc_int gc_date
|
|
101010 101011 2010-10-11
|
|
70707 70708 2007-07-08
|
|
80808 80809 2008-08-09
|
|
90909 90910 2009-09-10
|
|
# DATE column & index should be picked
|
|
EXPLAIN SELECT * FROM t1 WHERE f1 + 1 > CAST(070707 AS DATE);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 18 Using where
|
|
DROP TABLE t1;
|
|
#
|
|
# BUG#21229846: WL8170: SIGNAL 11 IN JOIN::MAKE_SUM_FUNC_LIST
|
|
#
|
|
CREATE TABLE t1 (
|
|
pk int primary key auto_increment,
|
|
col_int_key INTEGER ,
|
|
col_int_gc_key INT GENERATED ALWAYS AS (col_int_key + 1) STORED,
|
|
KEY col_int_gc_key(col_int_gc_key)
|
|
);
|
|
INSERT INTO t1 ( col_int_key) VALUES (7);
|
|
ANALYZE TABLE t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 analyze status Engine-independent statistics collected
|
|
test.t1 analyze status OK
|
|
SELECT table1.col_int_key + 1 AS field1, table2.col_int_key AS field2
|
|
FROM (t1 AS table1 JOIN t1 AS table2 ON (table2.pk = table1.pk))
|
|
ORDER BY field1, field2;
|
|
field1 field2
|
|
8 7
|
|
EXPLAIN SELECT table1.col_int_key + 1 AS field1, table2.col_int_key AS field2
|
|
FROM (t1 AS table1 JOIN t1 AS table2 ON (table2.pk = table1.pk))
|
|
ORDER BY field1, field2;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE table1 system PRIMARY NULL NULL NULL 1
|
|
1 SIMPLE table2 system PRIMARY NULL NULL NULL 1
|
|
SELECT table1.col_int_key + 1 AS field1, table2.col_int_key AS field2
|
|
FROM (t1 AS table1 JOIN t1 AS table2 ON (table2.pk = table1.pk))
|
|
GROUP BY field1, field2;
|
|
field1 field2
|
|
8 7
|
|
EXPLAIN SELECT table1.col_int_key + 1 AS field1, table2.col_int_key AS field2
|
|
FROM (t1 AS table1 JOIN t1 AS table2 ON (table2.pk = table1.pk))
|
|
GROUP BY field1, field2;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE table1 system PRIMARY NULL NULL NULL 1
|
|
1 SIMPLE table2 system PRIMARY NULL NULL NULL 1
|
|
DROP TABLE t1;
|
|
#
|
|
# Bug#21391781 ASSERT WHEN RUNNING ALTER TABLE ON A TABLE WITH INDEX
|
|
# ON VIRTUAL COLUMN
|
|
#
|
|
CREATE TABLE t1 (
|
|
col1 INTEGER NOT NULL,
|
|
col2 INTEGER NOT NULL,
|
|
gcol1 INTEGER GENERATED ALWAYS AS (col1 + col2) VIRTUAL,
|
|
col3 INTEGER NOT NULL,
|
|
col4 INTEGER NOT NULL,
|
|
col5 INTEGER DEFAULT NULL,
|
|
col6 INTEGER DEFAULT NULL,
|
|
col7 INTEGER DEFAULT NULL,
|
|
col8 INTEGER DEFAULT NULL,
|
|
col9 INTEGER DEFAULT NULL,
|
|
col10 INTEGER DEFAULT NULL,
|
|
col11 INTEGER DEFAULT NULL,
|
|
col12 INTEGER DEFAULT NULL,
|
|
col13 INTEGER DEFAULT NULL,
|
|
col14 INTEGER DEFAULT NULL,
|
|
col15 INTEGER DEFAULT NULL,
|
|
col16 INTEGER DEFAULT NULL,
|
|
col17 INTEGER DEFAULT NULL,
|
|
col18 INTEGER DEFAULT NULL,
|
|
col19 INTEGER DEFAULT NULL,
|
|
col20 INTEGER DEFAULT NULL,
|
|
col21 INTEGER DEFAULT NULL,
|
|
col22 INTEGER DEFAULT NULL,
|
|
col23 INTEGER DEFAULT NULL,
|
|
col24 INTEGER DEFAULT NULL,
|
|
col25 INTEGER DEFAULT NULL,
|
|
col26 INTEGER DEFAULT NULL,
|
|
col27 INTEGER DEFAULT NULL,
|
|
col28 INTEGER DEFAULT NULL,
|
|
col29 INTEGER DEFAULT NULL,
|
|
col30 INTEGER DEFAULT NULL,
|
|
col31 INTEGER DEFAULT NULL,
|
|
col32 INTEGER DEFAULT NULL,
|
|
col33 INTEGER DEFAULT NULL,
|
|
col34 INTEGER DEFAULT NULL,
|
|
col35 INTEGER DEFAULT NULL,
|
|
col36 INTEGER DEFAULT NULL,
|
|
col37 INTEGER DEFAULT NULL,
|
|
col38 INTEGER DEFAULT NULL,
|
|
col39 INTEGER DEFAULT NULL,
|
|
col40 INTEGER DEFAULT NULL,
|
|
col41 INTEGER DEFAULT NULL,
|
|
col42 INTEGER DEFAULT NULL,
|
|
col43 INTEGER DEFAULT NULL,
|
|
col44 INTEGER DEFAULT NULL,
|
|
col45 INTEGER DEFAULT NULL,
|
|
col46 INTEGER DEFAULT NULL,
|
|
col47 INTEGER DEFAULT NULL,
|
|
col48 INTEGER DEFAULT NULL,
|
|
col49 INTEGER DEFAULT NULL,
|
|
col50 INTEGER DEFAULT NULL,
|
|
col51 INTEGER DEFAULT NULL,
|
|
col52 INTEGER DEFAULT NULL,
|
|
col53 INTEGER DEFAULT NULL,
|
|
col54 INTEGER DEFAULT NULL,
|
|
col55 INTEGER DEFAULT NULL,
|
|
col56 INTEGER DEFAULT NULL,
|
|
col57 INTEGER DEFAULT NULL,
|
|
col58 INTEGER DEFAULT NULL,
|
|
col59 INTEGER DEFAULT NULL,
|
|
col60 INTEGER DEFAULT NULL,
|
|
col61 INTEGER DEFAULT NULL,
|
|
col62 INTEGER DEFAULT NULL,
|
|
col63 INTEGER DEFAULT NULL,
|
|
col64 INTEGER DEFAULT NULL,
|
|
col65 INTEGER DEFAULT NULL,
|
|
gcol2 INTEGER GENERATED ALWAYS AS (col3 / col4) VIRTUAL,
|
|
KEY idx1 (gcol1)
|
|
);
|
|
INSERT INTO t1 (col1, col2, col3, col4)
|
|
VALUES (1,1,1,1), (2,2,2,2), (3,3,3,3), (4,4,4,4), (5,5,5,5);
|
|
ALTER TABLE t1 ADD COLUMN extra INTEGER;
|
|
SELECT gcol1 FROM t1 FORCE INDEX(idx1);
|
|
gcol1
|
|
2
|
|
4
|
|
6
|
|
8
|
|
10
|
|
DROP TABLE t1;
|
|
CREATE TABLE t1 (
|
|
col1 INTEGER NOT NULL,
|
|
col2 INTEGER NOT NULL,
|
|
gcol1 INTEGER GENERATED ALWAYS AS (col1 + col2) VIRTUAL,
|
|
col3 INTEGER NOT NULL,
|
|
col4 INTEGER NOT NULL,
|
|
col5 INTEGER DEFAULT NULL,
|
|
col6 INTEGER DEFAULT NULL,
|
|
col7 INTEGER DEFAULT NULL,
|
|
col8 INTEGER DEFAULT NULL,
|
|
col9 INTEGER DEFAULT NULL,
|
|
col10 INTEGER DEFAULT NULL,
|
|
col11 INTEGER DEFAULT NULL,
|
|
col12 INTEGER DEFAULT NULL,
|
|
col13 INTEGER DEFAULT NULL,
|
|
col14 INTEGER DEFAULT NULL,
|
|
col15 INTEGER DEFAULT NULL,
|
|
col16 INTEGER DEFAULT NULL,
|
|
col17 INTEGER DEFAULT NULL,
|
|
col18 INTEGER DEFAULT NULL,
|
|
col19 INTEGER DEFAULT NULL,
|
|
col20 INTEGER DEFAULT NULL,
|
|
col21 INTEGER DEFAULT NULL,
|
|
col22 INTEGER DEFAULT NULL,
|
|
col23 INTEGER DEFAULT NULL,
|
|
col24 INTEGER DEFAULT NULL,
|
|
col25 INTEGER DEFAULT NULL,
|
|
col26 INTEGER DEFAULT NULL,
|
|
col27 INTEGER DEFAULT NULL,
|
|
col28 INTEGER DEFAULT NULL,
|
|
col29 INTEGER DEFAULT NULL,
|
|
col30 INTEGER DEFAULT NULL,
|
|
col31 INTEGER DEFAULT NULL,
|
|
col32 INTEGER DEFAULT NULL,
|
|
col33 INTEGER DEFAULT NULL,
|
|
col34 INTEGER DEFAULT NULL,
|
|
col35 INTEGER DEFAULT NULL,
|
|
col36 INTEGER DEFAULT NULL,
|
|
col37 INTEGER DEFAULT NULL,
|
|
col38 INTEGER DEFAULT NULL,
|
|
col39 INTEGER DEFAULT NULL,
|
|
col40 INTEGER DEFAULT NULL,
|
|
col41 INTEGER DEFAULT NULL,
|
|
col42 INTEGER DEFAULT NULL,
|
|
col43 INTEGER DEFAULT NULL,
|
|
col44 INTEGER DEFAULT NULL,
|
|
col45 INTEGER DEFAULT NULL,
|
|
col46 INTEGER DEFAULT NULL,
|
|
col47 INTEGER DEFAULT NULL,
|
|
col48 INTEGER DEFAULT NULL,
|
|
col49 INTEGER DEFAULT NULL,
|
|
col50 INTEGER DEFAULT NULL,
|
|
col51 INTEGER DEFAULT NULL,
|
|
col52 INTEGER DEFAULT NULL,
|
|
col53 INTEGER DEFAULT NULL,
|
|
col54 INTEGER DEFAULT NULL,
|
|
col55 INTEGER DEFAULT NULL,
|
|
col56 INTEGER DEFAULT NULL,
|
|
col57 INTEGER DEFAULT NULL,
|
|
col58 INTEGER DEFAULT NULL,
|
|
col59 INTEGER DEFAULT NULL,
|
|
col60 INTEGER DEFAULT NULL,
|
|
col61 INTEGER DEFAULT NULL,
|
|
col62 INTEGER DEFAULT NULL,
|
|
col63 INTEGER DEFAULT NULL,
|
|
col64 INTEGER DEFAULT NULL,
|
|
col65 INTEGER DEFAULT NULL,
|
|
gcol2 INTEGER GENERATED ALWAYS AS (col3 / col4) VIRTUAL,
|
|
KEY idx1 (gcol2)
|
|
);
|
|
INSERT INTO t1 (col1, col2, col3, col4)
|
|
VALUES (1,1,1,1), (2,2,2,2), (3,3,3,3), (4,4,4,4), (5,5,5,5);
|
|
ALTER TABLE t1 ADD COLUMN extra INTEGER;
|
|
SELECT gcol2 FROM t1 FORCE INDEX(idx1);
|
|
gcol2
|
|
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
DROP TABLE t1;
|
|
#
|
|
# Bug#21628161 CRASH/MEMORY CORRUPTION ADDING INDEXES TO VIRTUAL COLUMN
|
|
#
|
|
CREATE TABLE t (a INT,
|
|
b BOOLEAN GENERATED ALWAYS AS (a+10000) VIRTUAL,
|
|
c BLOB GENERATED ALWAYS AS (b=2) VIRTUAL);
|
|
INSERT INTO t(a) VALUES (1);
|
|
SELECT * FROM t WHERE c = '0';
|
|
a b c
|
|
1 127 0
|
|
SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
|
|
ALTER TABLE t ADD UNIQUE INDEX (c(1));
|
|
Warnings:
|
|
Warning 1264 Out of range value for column 'b' at row 1
|
|
SELECT * FROM t WHERE c = '0';
|
|
a b c
|
|
1 127 0
|
|
DROP TABLE t;
|
|
#
|
|
# Bug#21688115 VIRTUAL COLUMN COMPUTATION SAVE_IN_FIELD()
|
|
# DID NOT RETURN TRUE WITH DIVIDE 0
|
|
#
|
|
CREATE TABLE t (a INT, b INT, h VARCHAR(10));
|
|
INSERT INTO t VALUES (12, 3, "ss");
|
|
INSERT INTO t VALUES (13, 4, "ss");
|
|
INSERT INTO t VALUES (14, 0, "ss");
|
|
SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
|
|
ALTER TABLE t ADD c INT GENERATED ALWAYS AS (a/b) VIRTUAL;
|
|
CREATE INDEX idx ON t(c);
|
|
ERROR 22012: Division by 0
|
|
CALL mtr.add_suppression("\\[Warning\\] InnoDB: Compute virtual column values failed");
|
|
DROP TABLE t;
|
|
#
|
|
# Bug#21770798 OPTIMIZER DOES NOT USE INDEX FOR GENERATED EXPRESSIONS
|
|
# WITH LOGICAL OPERATORS
|
|
#
|
|
CREATE TABLE t (a INT, b INT,
|
|
gc_and INT GENERATED ALWAYS AS (a AND b) STORED,
|
|
gc_or INT GENERATED ALWAYS AS (a OR b) STORED,
|
|
gc_xor INT GENERATED ALWAYS AS (a XOR b) STORED,
|
|
gc_not INT GENERATED ALWAYS AS (NOT a) STORED,
|
|
gc_case INT GENERATED ALWAYS AS
|
|
(CASE WHEN (a AND b) THEN a ELSE b END) STORED,
|
|
INDEX(gc_and), INDEX(gc_or), INDEX(gc_xor), INDEX(gc_not),
|
|
INDEX(gc_case));
|
|
INSERT INTO t (a, b) VALUES (0, 0), (0, 1), (1, 0), (1, 1);
|
|
ANALYZE TABLE t;
|
|
Table Op Msg_type Msg_text
|
|
test.t analyze status Engine-independent statistics collected
|
|
test.t analyze status OK
|
|
EXPLAIN SELECT a, b FROM t WHERE (a AND b) = 1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
|
|
SELECT a, b FROM t WHERE (a AND b) = 1;
|
|
a b
|
|
1 1
|
|
EXPLAIN SELECT a, b FROM t WHERE 1 = (a AND b);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
|
|
SELECT a, b FROM t WHERE 1 = (a AND b);
|
|
a b
|
|
1 1
|
|
EXPLAIN SELECT a, b FROM t WHERE (a AND b) IN (1, 2, 3);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
|
|
SELECT a, b FROM t WHERE (a AND b) IN (1, 2, 3);
|
|
a b
|
|
1 1
|
|
EXPLAIN SELECT a, b FROM t WHERE (a OR b) = 1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
|
|
SELECT a, b FROM t WHERE (a OR b) = 1;
|
|
a b
|
|
0 1
|
|
1 0
|
|
1 1
|
|
EXPLAIN SELECT a, b FROM t WHERE (a OR b) BETWEEN 1 AND 10;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
|
|
SELECT a, b FROM t WHERE (a OR b) BETWEEN 1 AND 10;
|
|
a b
|
|
0 1
|
|
1 0
|
|
1 1
|
|
EXPLAIN SELECT a, b FROM t WHERE (a XOR b) = 1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
|
|
SELECT a, b FROM t WHERE (a XOR b) = 1;
|
|
a b
|
|
0 1
|
|
1 0
|
|
EXPLAIN SELECT a FROM t WHERE (NOT a) = 1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
|
|
SELECT a FROM t WHERE (NOT a) = 1;
|
|
a
|
|
0
|
|
0
|
|
EXPLAIN SELECT a FROM t WHERE (CASE WHEN (a AND b) THEN a ELSE b END) = 1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
|
|
SELECT a FROM t WHERE (CASE WHEN (a AND b) THEN a ELSE b END) = 1;
|
|
a
|
|
0
|
|
1
|
|
EXPLAIN SELECT a, b FROM t WHERE 1 = (b AND a);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
|
|
SELECT a, b FROM t WHERE 1 = (b AND a);
|
|
a b
|
|
1 1
|
|
EXPLAIN SELECT a, b FROM t WHERE 1 = (b OR a);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
|
|
SELECT a, b FROM t WHERE 1 = (b OR a);
|
|
a b
|
|
0 1
|
|
1 0
|
|
1 1
|
|
DROP TABLE t;
|
|
#
|
|
# Bug#22810883: ASSERTION FAILED:
|
|
# !(USED_TABS & (~READ_TABLES & ~FILTER_FOR_TABLE))
|
|
#
|
|
CREATE TABLE t1 (a1 INTEGER GENERATED ALWAYS AS (1 AND 0) STORED,
|
|
a2 INTEGER, KEY (a1));
|
|
INSERT INTO t1 VALUES ();
|
|
CREATE TABLE t2 (b INTEGER);
|
|
INSERT INTO t2 VALUES (1);
|
|
ANALYZE TABLE t1, t2;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 analyze status Engine-independent statistics collected
|
|
test.t1 analyze status OK
|
|
test.t2 analyze status Engine-independent statistics collected
|
|
test.t2 analyze status OK
|
|
# Used to choose the index on a1 and get wrong results.
|
|
EXPLAIN SELECT * FROM t1 WHERE (a2 AND a2) = 0;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
|
|
SELECT * FROM t1 WHERE (a2 AND a2) = 0;
|
|
a1 a2
|
|
# Used to get assertion or wrong results.
|
|
EXPLAIN SELECT * FROM t1 STRAIGHT_JOIN t2 ON b WHERE (b AND b) = 1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 system NULL NULL NULL NULL 1
|
|
1 SIMPLE t2 system NULL NULL NULL NULL 1
|
|
SELECT * FROM t1 STRAIGHT_JOIN t2 ON b WHERE (b AND b) = 1;
|
|
a1 a2 b
|
|
0 NULL 1
|
|
DROP TABLE t1, t2;
|
|
#
|
|
# MDEV-20618 Assertion `btr_validate_index(index, 0, false)' failed
|
|
# in row_upd_sec_index_entry
|
|
#
|
|
CREATE TABLE t1 (A BIT(15), VA BIT(10) GENERATED ALWAYS AS (A),PK INT,
|
|
PRIMARY KEY (PK), UNIQUE KEY (VA));
|
|
INSERT IGNORE INTO t1 VALUES ( '\r1','a',1);
|
|
Warnings:
|
|
Warning 1906 The value specified for generated column 'VA' in table 't1' has been ignored
|
|
Warning 1264 Out of range value for column 'VA' at row 1
|
|
REPLACE INTO t1 (PK) VALUES (1);
|
|
ERROR 22001: Data too long for column 'VA' at row 1
|
|
DROP TABLE t1;
|
|
#
|
|
# MDEV-17890 Record in index was not found on update, server crash in
|
|
# row_upd_build_difference_binary or
|
|
# Assertion `0' failed in row_upd_sec_index_entry
|
|
#
|
|
CREATE TABLE t1 (
|
|
pk BIGINT AUTO_INCREMENT,
|
|
b BIT(15),
|
|
v BIT(10) AS (b) VIRTUAL,
|
|
PRIMARY KEY(pk),
|
|
UNIQUE(v)
|
|
);
|
|
INSERT IGNORE INTO t1 (b) VALUES (b'101110001110100'),(b'011101');
|
|
Warnings:
|
|
Warning 1264 Out of range value for column 'v' at row 1
|
|
SELECT pk, b INTO OUTFILE 'load.data' FROM t1;
|
|
LOAD DATA INFILE 'load.data' REPLACE INTO TABLE t1 (pk, b);
|
|
ERROR 22001: Data too long for column 'v' at row 1
|
|
DROP TABLE t1;
|
|
#
|
|
# MDEV-17834 Server crashes in row_upd_build_difference_binary
|
|
# on LOAD DATA into table with indexed virtual column
|
|
#
|
|
CREATE TABLE t1 (
|
|
pk INT,
|
|
i TINYINT,
|
|
ts TIMESTAMP NULL,
|
|
vi TINYINT AS (i+1) PERSISTENT,
|
|
vts TIMESTAMP(5) AS (ts) VIRTUAL,
|
|
PRIMARY KEY(pk),
|
|
UNIQUE(vts)
|
|
);
|
|
INSERT IGNORE INTO t1 (pk,i) VALUES (1,127);
|
|
Warnings:
|
|
Warning 1264 Out of range value for column 'vi' at row 1
|
|
LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/load.data' REPLACE INTO TABLE t1 (pk,i,ts);
|
|
ERROR 22003: Out of range value for column 'vi' at row 1
|
|
DROP TABLE t1;
|
|
# MDEV-19011 Assertion `file->s->base.reclength < file->s->vreclength'
|
|
# failed in ha_myisam::setup_vcols_for_repair
|
|
CREATE TABLE t1 (a INT GENERATED ALWAYS AS (1) VIRTUAL);
|
|
ALTER TABLE t1 ADD KEY (a);
|
|
DROP TABLE t1;
|
|
DROP VIEW IF EXISTS v1,v2;
|
|
DROP TABLE IF EXISTS t1,t2,t3;
|
|
DROP PROCEDURE IF EXISTS p1;
|
|
DROP FUNCTION IF EXISTS f1;
|
|
DROP TRIGGER IF EXISTS trg1;
|
|
DROP TRIGGER IF EXISTS trg2;
|
|
set sql_warnings = 0;
|