mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 03:52:35 +01:00
b6215b9b20
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.
1455 lines
59 KiB
Text
1455 lines
59 KiB
Text
#Structure of tests
|
|
#First we will check all option for
|
|
#table containing single unique column
|
|
#table containing keys like unique(a,b,c,d) etc
|
|
#then table containing 2 blob unique etc
|
|
#table with single long blob column;
|
|
create table t1(a blob unique );
|
|
insert into t1 values(1),(2),(3),(56),('sachin'),('maria'),(123456789034567891),(null),(null),(123456789034567890);
|
|
#blob with primary key not allowed
|
|
create table t2(a blob,primary key(a(10000)));
|
|
ERROR 42000: Specified key was too long; max key length is 1000 bytes
|
|
create table t3(a varchar(10000) primary key);
|
|
ERROR 42000: Specified key was too long; max key length is 1000 bytes
|
|
insert into t1 values(2);
|
|
ERROR 23000: Duplicate entry '2' for key 'a'
|
|
#table structure;
|
|
desc t1;
|
|
Field Type Null Key Default Extra
|
|
a blob YES UNI NULL
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
UNIQUE KEY `a` (`a`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table t1
|
|
Non_unique 0
|
|
Key_name a
|
|
Seq_in_index 1
|
|
Column_name a
|
|
Collation A
|
|
Cardinality NULL
|
|
Sub_part NULL
|
|
Packed NULL
|
|
Null YES
|
|
Index_type HASH
|
|
Comment
|
|
Index_comment
|
|
Ignored NO
|
|
|
|
MyISAM file: DATADIR/test/t1
|
|
Record format: Packed
|
|
Character set: latin1_swedish_ci (8)
|
|
Data records: 10 Deleted blocks: 0
|
|
Recordlength: 12
|
|
|
|
table description:
|
|
Key Start Len Index Type
|
|
1 12 8 multip. ulonglong NULL
|
|
select TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,DATETIME_PRECISION,CHARACTER_SET_NAME,COLLATION_NAME,COLUMN_TYPE,COLUMN_KEY,EXTRA,COLUMN_COMMENT,IS_GENERATED,GENERATION_EXPRESSION from information_schema.columns where table_schema = 'test' and table_name = 't1';
|
|
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE DATETIME_PRECISION CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA COLUMN_COMMENT IS_GENERATED GENERATION_EXPRESSION
|
|
def test t1 a 1 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob UNI NEVER NULL
|
|
select * from information_schema.statistics where table_schema = 'test' and table_name = 't1';
|
|
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLUMN_NAME COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT INDEX_COMMENT IGNORED
|
|
def test t1 0 test a 1 a A NULL NULL NULL YES HASH NO
|
|
select * from information_schema.key_column_usage where table_schema= 'test' and table_name= 't1';
|
|
CONSTRAINT_CATALOG def
|
|
CONSTRAINT_SCHEMA test
|
|
CONSTRAINT_NAME a
|
|
TABLE_CATALOG def
|
|
TABLE_SCHEMA test
|
|
TABLE_NAME t1
|
|
COLUMN_NAME a
|
|
ORDINAL_POSITION 1
|
|
POSITION_IN_UNIQUE_CONSTRAINT NULL
|
|
REFERENCED_TABLE_SCHEMA NULL
|
|
REFERENCED_TABLE_NAME NULL
|
|
REFERENCED_COLUMN_NAME NULL
|
|
# table select we should not be able to see db_row_hash_column;
|
|
select * from t1 order by a;
|
|
a
|
|
NULL
|
|
NULL
|
|
1
|
|
123456789034567890
|
|
123456789034567891
|
|
2
|
|
3
|
|
56
|
|
maria
|
|
sachin
|
|
select db_row_hash_1 from t1;
|
|
ERROR 42S22: Unknown column 'db_row_hash_1' in 'field list'
|
|
#duplicate entry test;
|
|
insert into t1 values(2);
|
|
ERROR 23000: Duplicate entry '2' for key 'a'
|
|
insert into t1 values('sachin');
|
|
ERROR 23000: Duplicate entry 'sachin' for key 'a'
|
|
insert into t1 values(123456789034567891);
|
|
ERROR 23000: Duplicate entry '123456789034567891' for key 'a'
|
|
select * from t1 order by a;
|
|
a
|
|
NULL
|
|
NULL
|
|
1
|
|
123456789034567890
|
|
123456789034567891
|
|
2
|
|
3
|
|
56
|
|
maria
|
|
sachin
|
|
insert into t1 values(11),(22),(33);
|
|
insert into t1 values(12),(22);
|
|
ERROR 23000: Duplicate entry '22' for key 'a'
|
|
select * from t1 order by a;
|
|
a
|
|
NULL
|
|
NULL
|
|
1
|
|
11
|
|
12
|
|
123456789034567890
|
|
123456789034567891
|
|
2
|
|
22
|
|
3
|
|
33
|
|
56
|
|
maria
|
|
sachin
|
|
insert into t1 values(repeat('s',4000*10)),(repeat('s',4001*10));
|
|
insert into t1 values(repeat('m',4000*10)),(repeat('m',4000*10));
|
|
ERROR 23000: Duplicate entry 'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm...' for key 'a'
|
|
insert into t1 values(repeat('m',4001)),(repeat('m',4002));
|
|
truncate table t1;
|
|
insert into t1 values(1),(2),(3),(4),(5),(8),(7);
|
|
|
|
MyISAM file: DATADIR/test/t1
|
|
Record format: Packed
|
|
Character set: latin1_swedish_ci (8)
|
|
Data records: 7 Deleted blocks: 0
|
|
Recordlength: 12
|
|
|
|
table description:
|
|
Key Start Len Index Type
|
|
1 12 8 multip. ulonglong NULL
|
|
#now some alter commands;
|
|
alter table t1 add column b int;
|
|
desc t1;
|
|
Field Type Null Key Default Extra
|
|
a blob YES UNI NULL
|
|
b int(11) YES NULL
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
`b` int(11) DEFAULT NULL,
|
|
UNIQUE KEY `a` (`a`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
insert into t1 values(1,2);
|
|
ERROR 23000: Duplicate entry '1' for key 'a'
|
|
insert into t1 values(2,2);
|
|
ERROR 23000: Duplicate entry '2' for key 'a'
|
|
select db_row_hash_1 from t1;
|
|
ERROR 42S22: Unknown column 'db_row_hash_1' in 'field list'
|
|
#now try to change db_row_hash_1 column;
|
|
alter table t1 drop column db_row_hash_1;
|
|
ERROR 42000: Can't DROP COLUMN `db_row_hash_1`; check that it exists
|
|
alter table t1 add column d int , add column e int , drop column db_row_hash_1;
|
|
ERROR 42000: Can't DROP COLUMN `db_row_hash_1`; check that it exists
|
|
alter table t1 modify column db_row_hash_1 int ;
|
|
ERROR 42S22: Unknown column 'db_row_hash_1' in 't1'
|
|
alter table t1 add column a int , add column b int, modify column db_row_hash_1 int ;
|
|
ERROR 42S22: Unknown column 'db_row_hash_1' in 't1'
|
|
alter table t1 change column db_row_hash_1 dsds int;
|
|
ERROR 42S22: Unknown column 'db_row_hash_1' in 't1'
|
|
alter table t1 add column asd int, change column db_row_hash_1 dsds int;
|
|
ERROR 42S22: Unknown column 'db_row_hash_1' in 't1'
|
|
alter table t1 drop column b , add column c int;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
`c` int(11) DEFAULT NULL,
|
|
UNIQUE KEY `a` (`a`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
#now add some column with name db_row_hash;
|
|
alter table t1 add column db_row_hash_1 int unique;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
`c` int(11) DEFAULT NULL,
|
|
`db_row_hash_1` int(11) DEFAULT NULL,
|
|
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
|
|
UNIQUE KEY `a` (`a`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
insert into t1 values(45,1,55),(46,1,55);
|
|
ERROR 23000: Duplicate entry '55' for key 'db_row_hash_1'
|
|
insert into t1 values(45,1,55),(45,1,55);
|
|
ERROR 23000: Duplicate entry '45' for key 'a'
|
|
alter table t1 add column db_row_hash_2 int, add column db_row_hash_3 int;
|
|
desc t1;
|
|
Field Type Null Key Default Extra
|
|
a blob YES UNI NULL
|
|
c int(11) YES NULL
|
|
db_row_hash_1 int(11) YES UNI NULL
|
|
db_row_hash_2 int(11) YES NULL
|
|
db_row_hash_3 int(11) YES NULL
|
|
#this should also drop the unique index ;
|
|
alter table t1 drop column a;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`c` int(11) DEFAULT NULL,
|
|
`db_row_hash_1` int(11) DEFAULT NULL,
|
|
`db_row_hash_2` int(11) DEFAULT NULL,
|
|
`db_row_hash_3` int(11) DEFAULT NULL,
|
|
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE NO
|
|
#add column with unique index on blob ;
|
|
alter table t1 add column a blob unique;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`c` int(11) DEFAULT NULL,
|
|
`db_row_hash_1` int(11) DEFAULT NULL,
|
|
`db_row_hash_2` int(11) DEFAULT NULL,
|
|
`db_row_hash_3` int(11) DEFAULT NULL,
|
|
`a` blob DEFAULT NULL,
|
|
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
|
|
UNIQUE KEY `a` (`a`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
# try to change the blob unique name;
|
|
alter table t1 change column a aa blob ;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`c` int(11) DEFAULT NULL,
|
|
`db_row_hash_1` int(11) DEFAULT NULL,
|
|
`db_row_hash_2` int(11) DEFAULT NULL,
|
|
`db_row_hash_3` int(11) DEFAULT NULL,
|
|
`aa` blob DEFAULT NULL,
|
|
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
|
|
UNIQUE KEY `a` (`aa`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE NO
|
|
t1 0 a 1 aa A NULL NULL NULL YES HASH NO
|
|
# try to change the blob unique datatype;
|
|
#this will change index to b tree;
|
|
alter table t1 modify column aa int ;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`c` int(11) DEFAULT NULL,
|
|
`db_row_hash_1` int(11) DEFAULT NULL,
|
|
`db_row_hash_2` int(11) DEFAULT NULL,
|
|
`db_row_hash_3` int(11) DEFAULT NULL,
|
|
`aa` int(11) DEFAULT NULL,
|
|
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
|
|
UNIQUE KEY `a` (`aa`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE NO
|
|
t1 0 a 1 aa A NULL NULL NULL YES BTREE NO
|
|
alter table t1 add column clm blob unique;
|
|
#try changing the name ;
|
|
alter table t1 change column clm clm_changed blob;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`c` int(11) DEFAULT NULL,
|
|
`db_row_hash_1` int(11) DEFAULT NULL,
|
|
`db_row_hash_2` int(11) DEFAULT NULL,
|
|
`db_row_hash_3` int(11) DEFAULT NULL,
|
|
`aa` int(11) DEFAULT NULL,
|
|
`clm_changed` blob DEFAULT NULL,
|
|
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
|
|
UNIQUE KEY `a` (`aa`),
|
|
UNIQUE KEY `clm` (`clm_changed`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE NO
|
|
t1 0 a 1 aa A NULL NULL NULL YES BTREE NO
|
|
t1 0 clm 1 clm_changed A NULL NULL NULL YES HASH NO
|
|
#now drop the unique key;
|
|
alter table t1 drop key clm;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`c` int(11) DEFAULT NULL,
|
|
`db_row_hash_1` int(11) DEFAULT NULL,
|
|
`db_row_hash_2` int(11) DEFAULT NULL,
|
|
`db_row_hash_3` int(11) DEFAULT NULL,
|
|
`aa` int(11) DEFAULT NULL,
|
|
`clm_changed` blob DEFAULT NULL,
|
|
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
|
|
UNIQUE KEY `a` (`aa`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE NO
|
|
t1 0 a 1 aa A NULL NULL NULL YES BTREE NO
|
|
drop table t1;
|
|
create table t1 (a TEXT CHARSET latin1 COLLATE latin1_german2_ci unique);
|
|
desc t1;
|
|
Field Type Null Key Default Extra
|
|
a text YES UNI NULL
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 a 1 a A NULL NULL NULL YES HASH NO
|
|
insert into t1 values ('ae');
|
|
insert into t1 values ('AE');
|
|
ERROR 23000: Duplicate entry 'AE' for key 'a'
|
|
insert into t1 values ('Ä');
|
|
drop table t1;
|
|
create table t1 (a int primary key, b blob unique);
|
|
desc t1;
|
|
Field Type Null Key Default Extra
|
|
a int(11) NO PRI NULL
|
|
b blob YES UNI NULL
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 PRIMARY 1 a A 0 NULL NULL BTREE NO
|
|
t1 0 b 1 b A NULL NULL NULL YES HASH NO
|
|
insert into t1 values(1,1),(2,2),(3,3);
|
|
insert into t1 values(1,1);
|
|
ERROR 23000: Duplicate entry '1' for key 'b'
|
|
insert into t1 values(7,1);
|
|
ERROR 23000: Duplicate entry '1' for key 'b'
|
|
drop table t1;
|
|
#table with multiple long blob column and varchar text column ;
|
|
create table t1(a blob unique, b int , c blob unique , d text unique , e varchar(3000) unique);
|
|
insert into t1 values(1,2,3,4,5),(2,11,22,33,44),(3111,222,333,444,555),(5611,2222,3333,4444,5555),
|
|
('sachin',341,'fdf','gfgfgfg','hghgr'),('maria',345,'frter','dasd','utyuty'),
|
|
(123456789034567891,353534,53453453453456,64565464564564,45435345345345),
|
|
(123456789034567890,43545,657567567567,78967657567567,657567567567567676);
|
|
#table structure;
|
|
desc t1;
|
|
Field Type Null Key Default Extra
|
|
a blob YES UNI NULL
|
|
b int(11) YES NULL
|
|
c blob YES UNI NULL
|
|
d text YES UNI NULL
|
|
e varchar(3000) YES UNI NULL
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
`b` int(11) DEFAULT NULL,
|
|
`c` blob DEFAULT NULL,
|
|
`d` text DEFAULT NULL,
|
|
`e` varchar(3000) DEFAULT NULL,
|
|
UNIQUE KEY `a` (`a`) USING HASH,
|
|
UNIQUE KEY `c` (`c`) USING HASH,
|
|
UNIQUE KEY `d` (`d`) USING HASH,
|
|
UNIQUE KEY `e` (`e`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 a 1 a A NULL NULL NULL YES HASH NO
|
|
t1 0 c 1 c A NULL NULL NULL YES HASH NO
|
|
t1 0 d 1 d A NULL NULL NULL YES HASH NO
|
|
t1 0 e 1 e A NULL NULL NULL YES HASH NO
|
|
|
|
MyISAM file: DATADIR/test/t1
|
|
Record format: Packed
|
|
Character set: latin1_swedish_ci (8)
|
|
Data records: 8 Deleted blocks: 0
|
|
Recordlength: 3040
|
|
|
|
table description:
|
|
Key Start Len Index Type
|
|
1 3039 8 multip. ulonglong NULL
|
|
2 3047 8 multip. ulonglong NULL
|
|
3 3055 8 multip. ulonglong NULL
|
|
4 3063 8 multip. ulonglong NULL
|
|
select TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,DATETIME_PRECISION,CHARACTER_SET_NAME,COLLATION_NAME,COLUMN_TYPE,COLUMN_KEY,EXTRA,COLUMN_COMMENT,IS_GENERATED,GENERATION_EXPRESSION from information_schema.columns where table_schema = 'test' and table_name = 't1';
|
|
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE DATETIME_PRECISION CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA COLUMN_COMMENT IS_GENERATED GENERATION_EXPRESSION
|
|
def test t1 a 1 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob UNI NEVER NULL
|
|
def test t1 b 2 NULL YES int NULL NULL 10 0 NULL NULL NULL int(11) NEVER NULL
|
|
def test t1 c 3 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob UNI NEVER NULL
|
|
def test t1 d 4 NULL YES text 65535 65535 NULL NULL NULL latin1 latin1_swedish_ci text UNI NEVER NULL
|
|
def test t1 e 5 NULL YES varchar 3000 3000 NULL NULL NULL latin1 latin1_swedish_ci varchar(3000) UNI NEVER NULL
|
|
select * from information_schema.statistics where table_schema = 'test' and table_name = 't1';
|
|
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLUMN_NAME COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT INDEX_COMMENT IGNORED
|
|
def test t1 0 test a 1 a A NULL NULL NULL YES HASH NO
|
|
def test t1 0 test c 1 c A NULL NULL NULL YES HASH NO
|
|
def test t1 0 test d 1 d A NULL NULL NULL YES HASH NO
|
|
def test t1 0 test e 1 e A NULL NULL NULL YES HASH NO
|
|
select * from information_schema.key_column_usage where table_schema= 'test' and table_name= 't1';
|
|
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION POSITION_IN_UNIQUE_CONSTRAINT REFERENCED_TABLE_SCHEMA REFERENCED_TABLE_NAME REFERENCED_COLUMN_NAME
|
|
def test a def test t1 a 1 NULL NULL NULL NULL
|
|
def test c def test t1 c 1 NULL NULL NULL NULL
|
|
def test d def test t1 d 1 NULL NULL NULL NULL
|
|
def test e def test t1 e 1 NULL NULL NULL NULL
|
|
#table select we should not be able to see db_row_hash_1 column;
|
|
select * from t1 order by a;
|
|
a b c d e
|
|
1 2 3 4 5
|
|
123456789034567890 43545 657567567567 78967657567567 657567567567567676
|
|
123456789034567891 353534 53453453453456 64565464564564 45435345345345
|
|
2 11 22 33 44
|
|
3111 222 333 444 555
|
|
5611 2222 3333 4444 5555
|
|
maria 345 frter dasd utyuty
|
|
sachin 341 fdf gfgfgfg hghgr
|
|
select db_row_hash_1 from t1;
|
|
ERROR 42S22: Unknown column 'db_row_hash_1' in 'field list'
|
|
select db_row_hash_2 from t1;
|
|
ERROR 42S22: Unknown column 'db_row_hash_2' in 'field list'
|
|
select db_row_hash_3 from t1;
|
|
ERROR 42S22: Unknown column 'db_row_hash_3' in 'field list'
|
|
#duplicate entry test;
|
|
insert into t1 values(21,2,3,42,51);
|
|
ERROR 23000: Duplicate entry '3' for key 'c'
|
|
insert into t1 values('sachin',null,null,null,null);
|
|
ERROR 23000: Duplicate entry 'sachin' for key 'a'
|
|
insert into t1 values(1234567890345671890,4353451,6575675675617,789676575675617,657567567567567676);
|
|
ERROR 23000: Duplicate entry '657567567567567676' for key 'e'
|
|
select * from t1 order by a;
|
|
a b c d e
|
|
1 2 3 4 5
|
|
123456789034567890 43545 657567567567 78967657567567 657567567567567676
|
|
123456789034567891 353534 53453453453456 64565464564564 45435345345345
|
|
2 11 22 33 44
|
|
3111 222 333 444 555
|
|
5611 2222 3333 4444 5555
|
|
maria 345 frter dasd utyuty
|
|
sachin 341 fdf gfgfgfg hghgr
|
|
insert into t1 values(repeat('s',4000*10),100,repeat('s',4000*10),repeat('s',4000*10),
|
|
repeat('s',400)),(repeat('s',4001*10),1000,repeat('s',4001*10),repeat('s',4001*10),
|
|
repeat('s',2995));
|
|
insert into t1 values(repeat('m',4000*11),10,repeat('s',4000*11),repeat('s',4000*11),repeat('s',2995));
|
|
ERROR 23000: Duplicate entry 'sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...' for key 'e'
|
|
truncate table t1;
|
|
insert into t1 values(1,2,3,4,5),(2,11,22,33,44),(3111,222,333,444,555),(5611,2222,3333,4444,5555);
|
|
#now some alter commands;
|
|
alter table t1 add column f int;
|
|
desc t1;
|
|
Field Type Null Key Default Extra
|
|
a blob YES UNI NULL
|
|
b int(11) YES NULL
|
|
c blob YES UNI NULL
|
|
d text YES UNI NULL
|
|
e varchar(3000) YES UNI NULL
|
|
f int(11) YES NULL
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
`b` int(11) DEFAULT NULL,
|
|
`c` blob DEFAULT NULL,
|
|
`d` text DEFAULT NULL,
|
|
`e` varchar(3000) DEFAULT NULL,
|
|
`f` int(11) DEFAULT NULL,
|
|
UNIQUE KEY `a` (`a`) USING HASH,
|
|
UNIQUE KEY `c` (`c`) USING HASH,
|
|
UNIQUE KEY `d` (`d`) USING HASH,
|
|
UNIQUE KEY `e` (`e`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
#unique key should not break;
|
|
insert into t1 values(1,2,3,4,5,6);
|
|
ERROR 23000: Duplicate entry '1' for key 'a'
|
|
select db_row_hash_1 , db_row_hash_2, db_row_hash_3 from t1;
|
|
ERROR 42S22: Unknown column 'db_row_hash_1' in 'field list'
|
|
#now try to change db_row_hash_1 column;
|
|
alter table t1 drop column db_row_hash_1, drop column db_row_hash_2, drop column db_row_hash_3;
|
|
ERROR 42000: Can't DROP COLUMN `db_row_hash_1`; check that it exists
|
|
alter table t1 add column dg int , add column ef int , drop column db_row_hash_1;
|
|
ERROR 42000: Can't DROP COLUMN `db_row_hash_1`; check that it exists
|
|
alter table t1 modify column db_row_hash_1 int , modify column db_row_hash_2 int, modify column db_row_hash_3 int;
|
|
ERROR 42S22: Unknown column 'db_row_hash_1' in 't1'
|
|
alter table t1 add column ar int , add column rb int, modify column db_row_hash_1 int , modify column db_row_hash_3 int;
|
|
ERROR 42S22: Unknown column 'db_row_hash_1' in 't1'
|
|
alter table t1 change column db_row_hash_1 dsds int , change column db_row_hash_2 dfdf int , change column db_row_hash_3 gdfg int ;
|
|
ERROR 42S22: Unknown column 'db_row_hash_1' in 't1'
|
|
alter table t1 add column asd int, drop column a, change column db_row_hash_1 dsds int, change db_row_hash_3 fdfdfd int;
|
|
ERROR 42S22: Unknown column 'db_row_hash_1' in 't1'
|
|
alter table t1 drop column b , add column g int;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
`c` blob DEFAULT NULL,
|
|
`d` text DEFAULT NULL,
|
|
`e` varchar(3000) DEFAULT NULL,
|
|
`f` int(11) DEFAULT NULL,
|
|
`g` int(11) DEFAULT NULL,
|
|
UNIQUE KEY `a` (`a`) USING HASH,
|
|
UNIQUE KEY `c` (`c`) USING HASH,
|
|
UNIQUE KEY `d` (`d`) USING HASH,
|
|
UNIQUE KEY `e` (`e`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
#now add some column with name db_row_hash;
|
|
alter table t1 add column db_row_hash_1 int unique;
|
|
alter table t1 add column db_row_hash_2 int unique;
|
|
alter table t1 add column db_row_hash_3 int unique;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
`c` blob DEFAULT NULL,
|
|
`d` text DEFAULT NULL,
|
|
`e` varchar(3000) DEFAULT NULL,
|
|
`f` int(11) DEFAULT NULL,
|
|
`g` int(11) DEFAULT NULL,
|
|
`db_row_hash_1` int(11) DEFAULT NULL,
|
|
`db_row_hash_2` int(11) DEFAULT NULL,
|
|
`db_row_hash_3` int(11) DEFAULT NULL,
|
|
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
|
|
UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`),
|
|
UNIQUE KEY `db_row_hash_3` (`db_row_hash_3`),
|
|
UNIQUE KEY `a` (`a`) USING HASH,
|
|
UNIQUE KEY `c` (`c`) USING HASH,
|
|
UNIQUE KEY `d` (`d`) USING HASH,
|
|
UNIQUE KEY `e` (`e`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
alter table t1 add column db_row_hash_7 int, add column db_row_hash_5 int , add column db_row_hash_4 int ;
|
|
alter table t1 drop column db_row_hash_7,drop column db_row_hash_3, drop column db_row_hash_4;
|
|
desc t1;
|
|
Field Type Null Key Default Extra
|
|
a blob YES UNI NULL
|
|
c blob YES UNI NULL
|
|
d text YES UNI NULL
|
|
e varchar(3000) YES UNI NULL
|
|
f int(11) YES NULL
|
|
g int(11) YES NULL
|
|
db_row_hash_1 int(11) YES UNI NULL
|
|
db_row_hash_2 int(11) YES UNI NULL
|
|
db_row_hash_5 int(11) YES NULL
|
|
#this should not break anything;
|
|
insert into t1 values(1,2,3,4,5,6,23,5,6);
|
|
ERROR 23000: Duplicate entry '1' for key 'a'
|
|
#this should also drop the unique index;
|
|
alter table t1 drop column a, drop column c;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`d` text DEFAULT NULL,
|
|
`e` varchar(3000) DEFAULT NULL,
|
|
`f` int(11) DEFAULT NULL,
|
|
`g` int(11) DEFAULT NULL,
|
|
`db_row_hash_1` int(11) DEFAULT NULL,
|
|
`db_row_hash_2` int(11) DEFAULT NULL,
|
|
`db_row_hash_5` int(11) DEFAULT NULL,
|
|
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
|
|
UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`),
|
|
UNIQUE KEY `d` (`d`) USING HASH,
|
|
UNIQUE KEY `e` (`e`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE NO
|
|
t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE NO
|
|
t1 0 d 1 d A NULL NULL NULL YES HASH NO
|
|
t1 0 e 1 e A NULL NULL NULL YES HASH NO
|
|
#add column with unique index on blob;
|
|
alter table t1 add column a blob unique;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`d` text DEFAULT NULL,
|
|
`e` varchar(3000) DEFAULT NULL,
|
|
`f` int(11) DEFAULT NULL,
|
|
`g` int(11) DEFAULT NULL,
|
|
`db_row_hash_1` int(11) DEFAULT NULL,
|
|
`db_row_hash_2` int(11) DEFAULT NULL,
|
|
`db_row_hash_5` int(11) DEFAULT NULL,
|
|
`a` blob DEFAULT NULL,
|
|
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
|
|
UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`),
|
|
UNIQUE KEY `d` (`d`) USING HASH,
|
|
UNIQUE KEY `e` (`e`) USING HASH,
|
|
UNIQUE KEY `a` (`a`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE NO
|
|
t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE NO
|
|
t1 0 d 1 d A NULL NULL NULL YES HASH NO
|
|
t1 0 e 1 e A NULL NULL NULL YES HASH NO
|
|
t1 0 a 1 a A NULL NULL NULL YES HASH NO
|
|
#try to change the blob unique column name;
|
|
#this will change index to b tree;
|
|
alter table t1 modify column a int , modify column e int;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`d` text DEFAULT NULL,
|
|
`e` int(11) DEFAULT NULL,
|
|
`f` int(11) DEFAULT NULL,
|
|
`g` int(11) DEFAULT NULL,
|
|
`db_row_hash_1` int(11) DEFAULT NULL,
|
|
`db_row_hash_2` int(11) DEFAULT NULL,
|
|
`db_row_hash_5` int(11) DEFAULT NULL,
|
|
`a` int(11) DEFAULT NULL,
|
|
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
|
|
UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`),
|
|
UNIQUE KEY `d` (`d`) USING HASH,
|
|
UNIQUE KEY `e` (`e`),
|
|
UNIQUE KEY `a` (`a`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE NO
|
|
t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE NO
|
|
t1 0 d 1 d A NULL NULL NULL YES HASH NO
|
|
t1 0 e 1 e A NULL NULL NULL YES BTREE NO
|
|
t1 0 a 1 a A NULL NULL NULL YES BTREE NO
|
|
alter table t1 add column clm1 blob unique,add column clm2 blob unique;
|
|
#try changing the name;
|
|
alter table t1 change column clm1 clm_changed1 blob, change column clm2 clm_changed2 blob;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`d` text DEFAULT NULL,
|
|
`e` int(11) DEFAULT NULL,
|
|
`f` int(11) DEFAULT NULL,
|
|
`g` int(11) DEFAULT NULL,
|
|
`db_row_hash_1` int(11) DEFAULT NULL,
|
|
`db_row_hash_2` int(11) DEFAULT NULL,
|
|
`db_row_hash_5` int(11) DEFAULT NULL,
|
|
`a` int(11) DEFAULT NULL,
|
|
`clm_changed1` blob DEFAULT NULL,
|
|
`clm_changed2` blob DEFAULT NULL,
|
|
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
|
|
UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`),
|
|
UNIQUE KEY `e` (`e`),
|
|
UNIQUE KEY `a` (`a`),
|
|
UNIQUE KEY `d` (`d`) USING HASH,
|
|
UNIQUE KEY `clm1` (`clm_changed1`) USING HASH,
|
|
UNIQUE KEY `clm2` (`clm_changed2`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE NO
|
|
t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE NO
|
|
t1 0 e 1 e A NULL NULL NULL YES BTREE NO
|
|
t1 0 a 1 a A NULL NULL NULL YES BTREE NO
|
|
t1 0 d 1 d A NULL NULL NULL YES HASH NO
|
|
t1 0 clm1 1 clm_changed1 A NULL NULL NULL YES HASH NO
|
|
t1 0 clm2 1 clm_changed2 A NULL NULL NULL YES HASH NO
|
|
#now drop the unique key;
|
|
alter table t1 drop key clm1, drop key clm2;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`d` text DEFAULT NULL,
|
|
`e` int(11) DEFAULT NULL,
|
|
`f` int(11) DEFAULT NULL,
|
|
`g` int(11) DEFAULT NULL,
|
|
`db_row_hash_1` int(11) DEFAULT NULL,
|
|
`db_row_hash_2` int(11) DEFAULT NULL,
|
|
`db_row_hash_5` int(11) DEFAULT NULL,
|
|
`a` int(11) DEFAULT NULL,
|
|
`clm_changed1` blob DEFAULT NULL,
|
|
`clm_changed2` blob DEFAULT NULL,
|
|
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
|
|
UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`),
|
|
UNIQUE KEY `e` (`e`),
|
|
UNIQUE KEY `a` (`a`),
|
|
UNIQUE KEY `d` (`d`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE NO
|
|
t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE NO
|
|
t1 0 e 1 e A NULL NULL NULL YES BTREE NO
|
|
t1 0 a 1 a A NULL NULL NULL YES BTREE NO
|
|
t1 0 d 1 d A NULL NULL NULL YES HASH NO
|
|
drop table t1;
|
|
#now the table with key on multiple columns; the ultimate test;
|
|
create table t1(a blob, b int , c varchar(2000) , d text , e varchar(3000) , f longblob , g int , h text ,
|
|
unique(a,b,c), unique(c,d,e),unique(e,f,g,h), unique(b,d,g,h));
|
|
insert into t1 values(1,1,1,1,1,1,1,1),(2,2,2,2,2,2,2,2),(3,3,3,3,3,3,3,3),(4,4,4,4,4,4,4,4),(5,5,5,5,5,5,5,5),
|
|
('maria',6,'maria','maria','maria','maria',6,'maria'),('mariadb',7,'mariadb','mariadb','mariadb','mariadb',8,'mariadb')
|
|
,(null,null,null,null,null,null,null,null),(null,null,null,null,null,null,null,null);
|
|
#table structure;
|
|
desc t1;
|
|
Field Type Null Key Default Extra
|
|
a blob YES MUL NULL
|
|
b int(11) YES MUL NULL
|
|
c varchar(2000) YES MUL NULL
|
|
d text YES NULL
|
|
e varchar(3000) YES MUL NULL
|
|
f longblob YES NULL
|
|
g int(11) YES NULL
|
|
h text YES NULL
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
`b` int(11) DEFAULT NULL,
|
|
`c` varchar(2000) DEFAULT NULL,
|
|
`d` text DEFAULT NULL,
|
|
`e` varchar(3000) DEFAULT NULL,
|
|
`f` longblob DEFAULT NULL,
|
|
`g` int(11) DEFAULT NULL,
|
|
`h` text DEFAULT NULL,
|
|
UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH,
|
|
UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH,
|
|
UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH,
|
|
UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 a 1 a A NULL NULL NULL YES HASH NO
|
|
t1 0 a 2 b A NULL NULL NULL YES HASH NO
|
|
t1 0 a 3 c A NULL NULL NULL YES HASH NO
|
|
t1 0 c 1 c A NULL NULL NULL YES HASH NO
|
|
t1 0 c 2 d A NULL NULL NULL YES HASH NO
|
|
t1 0 c 3 e A NULL NULL NULL YES HASH NO
|
|
t1 0 e 1 e A NULL NULL NULL YES HASH NO
|
|
t1 0 e 2 f A NULL NULL NULL YES HASH NO
|
|
t1 0 e 3 g A NULL NULL NULL YES HASH NO
|
|
t1 0 e 4 h A NULL NULL NULL YES HASH NO
|
|
t1 0 b 1 b A NULL NULL NULL YES HASH NO
|
|
t1 0 b 2 d A NULL NULL NULL YES HASH NO
|
|
t1 0 b 3 g A NULL NULL NULL YES HASH NO
|
|
t1 0 b 4 h A NULL NULL NULL YES HASH NO
|
|
|
|
MyISAM file: DATADIR/test/t1
|
|
Record format: Packed
|
|
Character set: latin1_swedish_ci (8)
|
|
Data records: 9 Deleted blocks: 0
|
|
Recordlength: 5059
|
|
|
|
table description:
|
|
Key Start Len Index Type
|
|
1 5057 8 multip. ulonglong NULL
|
|
2 5065 8 multip. ulonglong NULL
|
|
3 5073 8 multip. ulonglong NULL
|
|
4 5081 8 multip. ulonglong NULL
|
|
select TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,DATETIME_PRECISION,CHARACTER_SET_NAME,COLLATION_NAME,COLUMN_TYPE,COLUMN_KEY,EXTRA,COLUMN_COMMENT,IS_GENERATED,GENERATION_EXPRESSION from information_schema.columns where table_schema = 'test' and table_name = 't1';
|
|
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE DATETIME_PRECISION CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA COLUMN_COMMENT IS_GENERATED GENERATION_EXPRESSION
|
|
def test t1 a 1 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob MUL NEVER NULL
|
|
def test t1 b 2 NULL YES int NULL NULL 10 0 NULL NULL NULL int(11) MUL NEVER NULL
|
|
def test t1 c 3 NULL YES varchar 2000 2000 NULL NULL NULL latin1 latin1_swedish_ci varchar(2000) MUL NEVER NULL
|
|
def test t1 d 4 NULL YES text 65535 65535 NULL NULL NULL latin1 latin1_swedish_ci text NEVER NULL
|
|
def test t1 e 5 NULL YES varchar 3000 3000 NULL NULL NULL latin1 latin1_swedish_ci varchar(3000) MUL NEVER NULL
|
|
def test t1 f 6 NULL YES longblob 4294967295 4294967295 NULL NULL NULL NULL NULL longblob NEVER NULL
|
|
def test t1 g 7 NULL YES int NULL NULL 10 0 NULL NULL NULL int(11) NEVER NULL
|
|
def test t1 h 8 NULL YES text 65535 65535 NULL NULL NULL latin1 latin1_swedish_ci text NEVER NULL
|
|
select * from information_schema.statistics where table_schema = 'test' and table_name = 't1';
|
|
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLUMN_NAME COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT INDEX_COMMENT IGNORED
|
|
def test t1 0 test a 1 a A NULL NULL NULL YES HASH NO
|
|
def test t1 0 test a 2 b A NULL NULL NULL YES HASH NO
|
|
def test t1 0 test a 3 c A NULL NULL NULL YES HASH NO
|
|
def test t1 0 test c 1 c A NULL NULL NULL YES HASH NO
|
|
def test t1 0 test c 2 d A NULL NULL NULL YES HASH NO
|
|
def test t1 0 test c 3 e A NULL NULL NULL YES HASH NO
|
|
def test t1 0 test e 1 e A NULL NULL NULL YES HASH NO
|
|
def test t1 0 test e 2 f A NULL NULL NULL YES HASH NO
|
|
def test t1 0 test e 3 g A NULL NULL NULL YES HASH NO
|
|
def test t1 0 test e 4 h A NULL NULL NULL YES HASH NO
|
|
def test t1 0 test b 1 b A NULL NULL NULL YES HASH NO
|
|
def test t1 0 test b 2 d A NULL NULL NULL YES HASH NO
|
|
def test t1 0 test b 3 g A NULL NULL NULL YES HASH NO
|
|
def test t1 0 test b 4 h A NULL NULL NULL YES HASH NO
|
|
select * from information_schema.key_column_usage where table_schema= 'test' and table_name= 't1';
|
|
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION POSITION_IN_UNIQUE_CONSTRAINT REFERENCED_TABLE_SCHEMA REFERENCED_TABLE_NAME REFERENCED_COLUMN_NAME
|
|
def test a def test t1 a 1 NULL NULL NULL NULL
|
|
def test a def test t1 b 2 NULL NULL NULL NULL
|
|
def test a def test t1 c 3 NULL NULL NULL NULL
|
|
def test c def test t1 c 1 NULL NULL NULL NULL
|
|
def test c def test t1 d 2 NULL NULL NULL NULL
|
|
def test c def test t1 e 3 NULL NULL NULL NULL
|
|
def test e def test t1 e 1 NULL NULL NULL NULL
|
|
def test e def test t1 f 2 NULL NULL NULL NULL
|
|
def test e def test t1 g 3 NULL NULL NULL NULL
|
|
def test e def test t1 h 4 NULL NULL NULL NULL
|
|
def test b def test t1 b 1 NULL NULL NULL NULL
|
|
def test b def test t1 d 2 NULL NULL NULL NULL
|
|
def test b def test t1 g 3 NULL NULL NULL NULL
|
|
def test b def test t1 h 4 NULL NULL NULL NULL
|
|
# table select we should not be able to see db_row_hash_1 column;
|
|
select * from t1 order by a;
|
|
a b c d e f g h
|
|
NULL NULL NULL NULL NULL NULL NULL NULL
|
|
NULL NULL NULL NULL NULL NULL NULL NULL
|
|
1 1 1 1 1 1 1 1
|
|
2 2 2 2 2 2 2 2
|
|
3 3 3 3 3 3 3 3
|
|
4 4 4 4 4 4 4 4
|
|
5 5 5 5 5 5 5 5
|
|
maria 6 maria maria maria maria 6 maria
|
|
mariadb 7 mariadb mariadb mariadb mariadb 8 mariadb
|
|
select db_row_hash_1 from t1;
|
|
ERROR 42S22: Unknown column 'db_row_hash_1' in 'field list'
|
|
select db_row_hash_2 from t1;
|
|
ERROR 42S22: Unknown column 'db_row_hash_2' in 'field list'
|
|
select db_row_hash_3 from t1;
|
|
ERROR 42S22: Unknown column 'db_row_hash_3' in 'field list'
|
|
#duplicate entry test;
|
|
#duplicate keys entry;
|
|
insert into t1 values(1,1,1,0,0,0,0,0);
|
|
ERROR 23000: Duplicate entry '1-1-1' for key 'a'
|
|
insert into t1 values(0,0,1,1,1,0,0,0);
|
|
ERROR 23000: Duplicate entry '1-1-1' for key 'c'
|
|
insert into t1 values(0,0,0,0,1,1,1,1);
|
|
ERROR 23000: Duplicate entry '1-1-1-1' for key 'e'
|
|
insert into t1 values(1,1,1,1,1,0,0,0);
|
|
ERROR 23000: Duplicate entry '1-1-1' for key 'a'
|
|
insert into t1 values(0,0,0,0,1,1,1,1);
|
|
ERROR 23000: Duplicate entry '1-1-1-1' for key 'e'
|
|
insert into t1 values(1,1,1,1,1,1,1,1);
|
|
ERROR 23000: Duplicate entry '1-1-1' for key 'a'
|
|
select db_row_hash_1,db_row_hash_2,db_row_hash_3,db_row_hash_4,db_row_hash_5 from t1;
|
|
ERROR 42S22: Unknown column 'db_row_hash_1' in 'field list'
|
|
alter table t1 drop column db_row_hash_1, drop column db_row_hash_2, drop column db_row_hash_3;
|
|
ERROR 42000: Can't DROP COLUMN `db_row_hash_1`; check that it exists
|
|
alter table t1 add column dg int , add column ef int , drop column db_row_hash_1;
|
|
ERROR 42000: Can't DROP COLUMN `db_row_hash_1`; check that it exists
|
|
alter table t1 modify column db_row_hash_1 int , modify column db_row_hash_2 int, modify column db_row_hash_3 int;
|
|
ERROR 42S22: Unknown column 'db_row_hash_1' in 't1'
|
|
alter table t1 add column ar int , add column rb int, modify column db_row_hash_1 int , modify column db_row_hash_3 int;
|
|
ERROR 42S22: Unknown column 'db_row_hash_1' in 't1'
|
|
alter table t1 change column db_row_hash_1 dsds int , change column db_row_hash_2 dfdf int , change column db_row_hash_3 gdfg int ;
|
|
ERROR 42S22: Unknown column 'db_row_hash_1' in 't1'
|
|
alter table t1 add column asd int, drop column a, change column db_row_hash_1 dsds int, change db_row_hash_3 fdfdfd int;
|
|
ERROR 42S22: Unknown column 'db_row_hash_1' in 't1'
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
`b` int(11) DEFAULT NULL,
|
|
`c` varchar(2000) DEFAULT NULL,
|
|
`d` text DEFAULT NULL,
|
|
`e` varchar(3000) DEFAULT NULL,
|
|
`f` longblob DEFAULT NULL,
|
|
`g` int(11) DEFAULT NULL,
|
|
`h` text DEFAULT NULL,
|
|
UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH,
|
|
UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH,
|
|
UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH,
|
|
UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
# add column named db_row_hash_*;
|
|
alter table t1 add column db_row_hash_7 int , add column db_row_hash_5 int,
|
|
add column db_row_hash_1 int, add column db_row_hash_2 int;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
`b` int(11) DEFAULT NULL,
|
|
`c` varchar(2000) DEFAULT NULL,
|
|
`d` text DEFAULT NULL,
|
|
`e` varchar(3000) DEFAULT NULL,
|
|
`f` longblob DEFAULT NULL,
|
|
`g` int(11) DEFAULT NULL,
|
|
`h` text DEFAULT NULL,
|
|
`db_row_hash_7` int(11) DEFAULT NULL,
|
|
`db_row_hash_5` int(11) DEFAULT NULL,
|
|
`db_row_hash_1` int(11) DEFAULT NULL,
|
|
`db_row_hash_2` int(11) DEFAULT NULL,
|
|
UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH,
|
|
UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH,
|
|
UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH,
|
|
UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 a 1 a A NULL NULL NULL YES HASH NO
|
|
t1 0 a 2 b A NULL NULL NULL YES HASH NO
|
|
t1 0 a 3 c A NULL NULL NULL YES HASH NO
|
|
t1 0 c 1 c A NULL NULL NULL YES HASH NO
|
|
t1 0 c 2 d A NULL NULL NULL YES HASH NO
|
|
t1 0 c 3 e A NULL NULL NULL YES HASH NO
|
|
t1 0 e 1 e A NULL NULL NULL YES HASH NO
|
|
t1 0 e 2 f A NULL NULL NULL YES HASH NO
|
|
t1 0 e 3 g A NULL NULL NULL YES HASH NO
|
|
t1 0 e 4 h A NULL NULL NULL YES HASH NO
|
|
t1 0 b 1 b A NULL NULL NULL YES HASH NO
|
|
t1 0 b 2 d A NULL NULL NULL YES HASH NO
|
|
t1 0 b 3 g A NULL NULL NULL YES HASH NO
|
|
t1 0 b 4 h A NULL NULL NULL YES HASH NO
|
|
alter table t1 drop column db_row_hash_7 , drop column db_row_hash_5 ,
|
|
drop column db_row_hash_1, drop column db_row_hash_2 ;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
`b` int(11) DEFAULT NULL,
|
|
`c` varchar(2000) DEFAULT NULL,
|
|
`d` text DEFAULT NULL,
|
|
`e` varchar(3000) DEFAULT NULL,
|
|
`f` longblob DEFAULT NULL,
|
|
`g` int(11) DEFAULT NULL,
|
|
`h` text DEFAULT NULL,
|
|
UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH,
|
|
UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH,
|
|
UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH,
|
|
UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 a 1 a A NULL NULL NULL YES HASH NO
|
|
t1 0 a 2 b A NULL NULL NULL YES HASH NO
|
|
t1 0 a 3 c A NULL NULL NULL YES HASH NO
|
|
t1 0 c 1 c A NULL NULL NULL YES HASH NO
|
|
t1 0 c 2 d A NULL NULL NULL YES HASH NO
|
|
t1 0 c 3 e A NULL NULL NULL YES HASH NO
|
|
t1 0 e 1 e A NULL NULL NULL YES HASH NO
|
|
t1 0 e 2 f A NULL NULL NULL YES HASH NO
|
|
t1 0 e 3 g A NULL NULL NULL YES HASH NO
|
|
t1 0 e 4 h A NULL NULL NULL YES HASH NO
|
|
t1 0 b 1 b A NULL NULL NULL YES HASH NO
|
|
t1 0 b 2 d A NULL NULL NULL YES HASH NO
|
|
t1 0 b 3 g A NULL NULL NULL YES HASH NO
|
|
t1 0 b 4 h A NULL NULL NULL YES HASH NO
|
|
#try to change column names;
|
|
alter table t1 change column a aa blob , change column b bb blob , change column d dd blob;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`aa` blob DEFAULT NULL,
|
|
`bb` blob DEFAULT NULL,
|
|
`c` varchar(2000) DEFAULT NULL,
|
|
`dd` blob DEFAULT NULL,
|
|
`e` varchar(3000) DEFAULT NULL,
|
|
`f` longblob DEFAULT NULL,
|
|
`g` int(11) DEFAULT NULL,
|
|
`h` text DEFAULT NULL,
|
|
UNIQUE KEY `a` (`aa`,`bb`,`c`) USING HASH,
|
|
UNIQUE KEY `c` (`c`,`dd`,`e`) USING HASH,
|
|
UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH,
|
|
UNIQUE KEY `b` (`bb`,`dd`,`g`,`h`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 a 1 aa A NULL NULL NULL YES HASH NO
|
|
t1 0 a 2 bb A NULL NULL NULL YES HASH NO
|
|
t1 0 a 3 c A NULL NULL NULL YES HASH NO
|
|
t1 0 c 1 c A NULL NULL NULL YES HASH NO
|
|
t1 0 c 2 dd A NULL NULL NULL YES HASH NO
|
|
t1 0 c 3 e A NULL NULL NULL YES HASH NO
|
|
t1 0 e 1 e A NULL NULL NULL YES HASH NO
|
|
t1 0 e 2 f A NULL NULL NULL YES HASH NO
|
|
t1 0 e 3 g A NULL NULL NULL YES HASH NO
|
|
t1 0 e 4 h A NULL NULL NULL YES HASH NO
|
|
t1 0 b 1 bb A NULL NULL NULL YES HASH NO
|
|
t1 0 b 2 dd A NULL NULL NULL YES HASH NO
|
|
t1 0 b 3 g A NULL NULL NULL YES HASH NO
|
|
t1 0 b 4 h A NULL NULL NULL YES HASH NO
|
|
alter table t1 change column aa a blob , change column bb b blob , change column dd d blob;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
`b` blob DEFAULT NULL,
|
|
`c` varchar(2000) DEFAULT NULL,
|
|
`d` blob DEFAULT NULL,
|
|
`e` varchar(3000) DEFAULT NULL,
|
|
`f` longblob DEFAULT NULL,
|
|
`g` int(11) DEFAULT NULL,
|
|
`h` text DEFAULT NULL,
|
|
UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH,
|
|
UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH,
|
|
UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH,
|
|
UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 a 1 a A NULL NULL NULL YES HASH NO
|
|
t1 0 a 2 b A NULL NULL NULL YES HASH NO
|
|
t1 0 a 3 c A NULL NULL NULL YES HASH NO
|
|
t1 0 c 1 c A NULL NULL NULL YES HASH NO
|
|
t1 0 c 2 d A NULL NULL NULL YES HASH NO
|
|
t1 0 c 3 e A NULL NULL NULL YES HASH NO
|
|
t1 0 e 1 e A NULL NULL NULL YES HASH NO
|
|
t1 0 e 2 f A NULL NULL NULL YES HASH NO
|
|
t1 0 e 3 g A NULL NULL NULL YES HASH NO
|
|
t1 0 e 4 h A NULL NULL NULL YES HASH NO
|
|
t1 0 b 1 b A NULL NULL NULL YES HASH NO
|
|
t1 0 b 2 d A NULL NULL NULL YES HASH NO
|
|
t1 0 b 3 g A NULL NULL NULL YES HASH NO
|
|
t1 0 b 4 h A NULL NULL NULL YES HASH NO
|
|
#now we will change the data type to int and varchar limit so that we no longer require hash_index;
|
|
#on key a_b_c;
|
|
alter table t1 modify column a varchar(20) , modify column b varchar(20) , modify column c varchar(20);
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` varchar(20) DEFAULT NULL,
|
|
`b` varchar(20) DEFAULT NULL,
|
|
`c` varchar(20) DEFAULT NULL,
|
|
`d` blob DEFAULT NULL,
|
|
`e` varchar(3000) DEFAULT NULL,
|
|
`f` longblob DEFAULT NULL,
|
|
`g` int(11) DEFAULT NULL,
|
|
`h` text DEFAULT NULL,
|
|
UNIQUE KEY `a` (`a`,`b`,`c`),
|
|
UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH,
|
|
UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH,
|
|
UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 a 1 a A NULL NULL NULL YES BTREE NO
|
|
t1 0 a 2 b A NULL NULL NULL YES BTREE NO
|
|
t1 0 a 3 c A NULL NULL NULL YES BTREE NO
|
|
t1 0 c 1 c A NULL NULL NULL YES HASH NO
|
|
t1 0 c 2 d A NULL NULL NULL YES HASH NO
|
|
t1 0 c 3 e A NULL NULL NULL YES HASH NO
|
|
t1 0 e 1 e A NULL NULL NULL YES HASH NO
|
|
t1 0 e 2 f A NULL NULL NULL YES HASH NO
|
|
t1 0 e 3 g A NULL NULL NULL YES HASH NO
|
|
t1 0 e 4 h A NULL NULL NULL YES HASH NO
|
|
t1 0 b 1 b A NULL NULL NULL YES HASH NO
|
|
t1 0 b 2 d A NULL NULL NULL YES HASH NO
|
|
t1 0 b 3 g A NULL NULL NULL YES HASH NO
|
|
t1 0 b 4 h A NULL NULL NULL YES HASH NO
|
|
#change it back;
|
|
alter table t1 modify column a blob , modify column b blob , modify column c blob;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
`b` blob DEFAULT NULL,
|
|
`c` blob DEFAULT NULL,
|
|
`d` blob DEFAULT NULL,
|
|
`e` varchar(3000) DEFAULT NULL,
|
|
`f` longblob DEFAULT NULL,
|
|
`g` int(11) DEFAULT NULL,
|
|
`h` text DEFAULT NULL,
|
|
UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH,
|
|
UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH,
|
|
UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH,
|
|
UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 a 1 a A NULL NULL NULL YES HASH NO
|
|
t1 0 a 2 b A NULL NULL NULL YES HASH NO
|
|
t1 0 a 3 c A NULL NULL NULL YES HASH NO
|
|
t1 0 c 1 c A NULL NULL NULL YES HASH NO
|
|
t1 0 c 2 d A NULL NULL NULL YES HASH NO
|
|
t1 0 c 3 e A NULL NULL NULL YES HASH NO
|
|
t1 0 e 1 e A NULL NULL NULL YES HASH NO
|
|
t1 0 e 2 f A NULL NULL NULL YES HASH NO
|
|
t1 0 e 3 g A NULL NULL NULL YES HASH NO
|
|
t1 0 e 4 h A NULL NULL NULL YES HASH NO
|
|
t1 0 b 1 b A NULL NULL NULL YES HASH NO
|
|
t1 0 b 2 d A NULL NULL NULL YES HASH NO
|
|
t1 0 b 3 g A NULL NULL NULL YES HASH NO
|
|
t1 0 b 4 h A NULL NULL NULL YES HASH NO
|
|
#try to delete blob column in unique;
|
|
truncate table t1;
|
|
#now try to delete keys;
|
|
alter table t1 drop key c, drop key e;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
`b` blob DEFAULT NULL,
|
|
`c` blob DEFAULT NULL,
|
|
`d` blob DEFAULT NULL,
|
|
`e` varchar(3000) DEFAULT NULL,
|
|
`f` longblob DEFAULT NULL,
|
|
`g` int(11) DEFAULT NULL,
|
|
`h` text DEFAULT NULL,
|
|
UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH,
|
|
UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 a 1 a A NULL NULL NULL YES HASH NO
|
|
t1 0 a 2 b A NULL NULL NULL YES HASH NO
|
|
t1 0 a 3 c A NULL NULL NULL YES HASH NO
|
|
t1 0 b 1 b A NULL NULL NULL YES HASH NO
|
|
t1 0 b 2 d A NULL NULL NULL YES HASH NO
|
|
t1 0 b 3 g A NULL NULL NULL YES HASH NO
|
|
t1 0 b 4 h A NULL NULL NULL YES HASH NO
|
|
drop table t1;
|
|
#now alter table containing some data basically some tests with ignore;
|
|
create table t1 (a blob);
|
|
insert into t1 values(1),(2),(3);
|
|
#normal alter table;
|
|
alter table t1 add unique key(a);
|
|
alter table t1 drop key a;
|
|
truncate table t1;
|
|
insert into t1 values(1),(1),(2),(2),(3);
|
|
alter table t1 add unique key(a);
|
|
ERROR 23000: Duplicate entry '1' for key 'a'
|
|
alter ignore table t1 add unique key(a);
|
|
select * from t1 order by a;
|
|
a
|
|
1
|
|
2
|
|
3
|
|
insert into t1 values(1);
|
|
ERROR 23000: Duplicate entry '1' for key 'a'
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
UNIQUE KEY `a` (`a`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 a 1 a A NULL NULL NULL YES HASH NO
|
|
drop table t1;
|
|
#Now with multiple keys;
|
|
create table t1(a blob , b blob, c blob , d blob , e int);
|
|
insert into t1 values (1,1,1,1,1);
|
|
insert into t1 values (1,1,1,1,1);
|
|
insert into t1 values (2,1,1,1,1);
|
|
insert into t1 values (2,2,2,2,2);
|
|
insert into t1 values (3,3,4,4,4);
|
|
insert into t1 values (4,4,4,4,4);
|
|
alter table t1 add unique key(a,c), add unique key(b,d), add unique key(e);
|
|
ERROR 23000: Duplicate entry '1-1' for key 'a'
|
|
alter ignore table t1 add unique key(a,c), add unique key(b,d), add unique key(e);
|
|
select * from t1 order by a;
|
|
a b c d e
|
|
1 1 1 1 1
|
|
2 2 2 2 2
|
|
3 3 4 4 4
|
|
insert into t1 values (1,12,1,13,14);
|
|
ERROR 23000: Duplicate entry '1-1' for key 'a'
|
|
insert into t1 values (12,1,14,1,14);
|
|
ERROR 23000: Duplicate entry '1-1' for key 'b'
|
|
insert into t1 values (13,12,13,14,4);
|
|
ERROR 23000: Duplicate entry '4' for key 'e'
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
`b` blob DEFAULT NULL,
|
|
`c` blob DEFAULT NULL,
|
|
`d` blob DEFAULT NULL,
|
|
`e` int(11) DEFAULT NULL,
|
|
UNIQUE KEY `e` (`e`),
|
|
UNIQUE KEY `a` (`a`,`c`) USING HASH,
|
|
UNIQUE KEY `b` (`b`,`d`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 e 1 e A NULL NULL NULL YES BTREE NO
|
|
t1 0 a 1 a A NULL NULL NULL YES HASH NO
|
|
t1 0 a 2 c A NULL NULL NULL YES HASH NO
|
|
t1 0 b 1 b A NULL NULL NULL YES HASH NO
|
|
t1 0 b 2 d A NULL NULL NULL YES HASH NO
|
|
drop table t1;
|
|
#visibility of db_row_hash
|
|
create table t1 (a blob unique , b blob unique);
|
|
desc t1;
|
|
Field Type Null Key Default Extra
|
|
a blob YES UNI NULL
|
|
b blob YES UNI NULL
|
|
insert into t1 values(1,19);
|
|
insert into t1 values(2,29);
|
|
insert into t1 values(3,39);
|
|
insert into t1 values(4,49);
|
|
create table t2 (DB_ROW_HASH_1 int, DB_ROW_HASH_2 int);
|
|
insert into t2 values(11,1);
|
|
insert into t2 values(22,2);
|
|
insert into t2 values(33,3);
|
|
insert into t2 values(44,4);
|
|
select * from t1 order by a;
|
|
a b
|
|
1 19
|
|
2 29
|
|
3 39
|
|
4 49
|
|
select * from t2 order by DB_ROW_HASH_1;
|
|
DB_ROW_HASH_1 DB_ROW_HASH_2
|
|
11 1
|
|
22 2
|
|
33 3
|
|
44 4
|
|
select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1;
|
|
ERROR 42S22: Unknown column 'DB_ROW_HASH_1' in 'field list'
|
|
#bug
|
|
select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1,t2;
|
|
DB_ROW_HASH_1 DB_ROW_HASH_2
|
|
11 1
|
|
11 1
|
|
11 1
|
|
11 1
|
|
22 2
|
|
22 2
|
|
22 2
|
|
22 2
|
|
33 3
|
|
33 3
|
|
33 3
|
|
33 3
|
|
44 4
|
|
44 4
|
|
44 4
|
|
44 4
|
|
select * from t1 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t2);
|
|
ERROR 42S22: Unknown column 'DB_ROW_HASH_1' in 'IN/ALL/ANY subquery'
|
|
select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1,t2 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t2);
|
|
DB_ROW_HASH_1 DB_ROW_HASH_2
|
|
11 1
|
|
11 1
|
|
11 1
|
|
11 1
|
|
22 2
|
|
22 2
|
|
22 2
|
|
22 2
|
|
33 3
|
|
33 3
|
|
33 3
|
|
33 3
|
|
44 4
|
|
44 4
|
|
44 4
|
|
44 4
|
|
select * from t2 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t1);
|
|
DB_ROW_HASH_1 DB_ROW_HASH_2
|
|
11 1
|
|
22 2
|
|
33 3
|
|
44 4
|
|
select DB_ROW_HASH_1 from t1,t2 where t1.DB_ROW_HASH_1 = t2.DB_ROW_HASH_2;
|
|
ERROR 42S22: Unknown column 't1.DB_ROW_HASH_1' in 'where clause'
|
|
select DB_ROW_HASH_1 from t1 inner join t2 on t1.a = t2.DB_ROW_HASH_2;
|
|
DB_ROW_HASH_1
|
|
11
|
|
22
|
|
33
|
|
44
|
|
drop table t1,t2;
|
|
#long key unique with different key length
|
|
create table t1(a blob, unique(a(3000)));
|
|
desc t1;
|
|
Field Type Null Key Default Extra
|
|
a blob YES UNI NULL
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 a 1 a A NULL 3000 NULL YES HASH NO
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
UNIQUE KEY `a` (`a`(3000)) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
insert into t1 value(concat(repeat('s',3000),'1'));
|
|
insert into t1 value(concat(repeat('s',3000),'2'));
|
|
ERROR 23000: Duplicate entry 'sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...' for key 'a'
|
|
insert into t1 value(concat(repeat('a',3000),'2'));
|
|
drop table t1;
|
|
create table t1(a varchar(4000), b longblob , c varchar(5000), d longblob,
|
|
unique(a(3500), b), unique(c(4500), d));
|
|
desc t1;
|
|
Field Type Null Key Default Extra
|
|
a varchar(4000) YES MUL NULL
|
|
b longblob YES NULL
|
|
c varchar(5000) YES MUL NULL
|
|
d longblob YES NULL
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` varchar(4000) DEFAULT NULL,
|
|
`b` longblob DEFAULT NULL,
|
|
`c` varchar(5000) DEFAULT NULL,
|
|
`d` longblob DEFAULT NULL,
|
|
UNIQUE KEY `a` (`a`(3500),`b`) USING HASH,
|
|
UNIQUE KEY `c` (`c`(4500),`d`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
show keys from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
|
|
t1 0 a 1 a A NULL 3500 NULL YES HASH NO
|
|
t1 0 a 2 b A NULL NULL NULL YES HASH NO
|
|
t1 0 c 1 c A NULL 4500 NULL YES HASH NO
|
|
t1 0 c 2 d A NULL NULL NULL YES HASH NO
|
|
drop table t1;
|
|
#ext bug
|
|
create table t1(a int primary key, b blob unique, c int, d blob , index(c));
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` int(11) NOT NULL,
|
|
`b` blob DEFAULT NULL,
|
|
`c` int(11) DEFAULT NULL,
|
|
`d` blob DEFAULT NULL,
|
|
PRIMARY KEY (`a`),
|
|
UNIQUE KEY `b` (`b`) USING HASH,
|
|
KEY `c` (`c`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
insert into t1 values(1,23,1,33);
|
|
insert into t1 values(2,23,1,33);
|
|
ERROR 23000: Duplicate entry '23' for key 'b'
|
|
drop table t1;
|
|
create table t2 (a blob unique , c int , index(c));
|
|
show create table t2;
|
|
Table Create Table
|
|
t2 CREATE TABLE `t2` (
|
|
`a` blob DEFAULT NULL,
|
|
`c` int(11) DEFAULT NULL,
|
|
UNIQUE KEY `a` (`a`) USING HASH,
|
|
KEY `c` (`c`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
insert into t2 values(1,1);
|
|
insert into t2 values(2,1);
|
|
drop table t2;
|
|
#not null test
|
|
create table t1(a blob unique not null);
|
|
desc t1;
|
|
Field Type Null Key Default Extra
|
|
a blob NO UNI NULL
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob NOT NULL,
|
|
UNIQUE KEY `a` (`a`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
insert into t1 values(1);
|
|
insert into t1 values(3);
|
|
insert into t1 values(1);
|
|
ERROR 23000: Duplicate entry '1' for key 'a'
|
|
drop table t1;
|
|
create table t1(a int primary key, b blob unique , c blob unique not null);
|
|
insert into t1 values(1,1,1);
|
|
insert into t1 values(2,1,2);
|
|
ERROR 23000: Duplicate entry '1' for key 'b'
|
|
insert into t1 values(3,3,1);
|
|
ERROR 23000: Duplicate entry '1' for key 'c'
|
|
drop table t1;
|
|
create table t1 (a blob unique not null, b blob not null, c blob not null, unique(b,c));
|
|
desc t1;
|
|
Field Type Null Key Default Extra
|
|
a blob NO UNI NULL
|
|
b blob NO MUL NULL
|
|
c blob NO NULL
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob NOT NULL,
|
|
`b` blob NOT NULL,
|
|
`c` blob NOT NULL,
|
|
UNIQUE KEY `a` (`a`) USING HASH,
|
|
UNIQUE KEY `b` (`b`,`c`) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
insert into t1 values (1, 2, 3);
|
|
insert into t1 values (2, 1, 3);
|
|
insert into t1 values (2, 1, 3);
|
|
ERROR 23000: Duplicate entry '2' for key 'a'
|
|
drop table t1;
|
|
#partition
|
|
create table t1(a blob unique) partition by hash(a);
|
|
ERROR HY000: A BLOB field is not allowed in partition function
|
|
#key length > 2^16 -1
|
|
create table t1(a blob, unique(a(65536)));
|
|
ERROR 42000: Specified key part was too long; max key part length is 65535 bytes
|
|
create table t1(a blob, unique(a(65535)));
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
UNIQUE KEY `a` (`a`(65535)) USING HASH
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
drop table t1;
|
|
#64 indexes
|
|
create table t1 ( a63 blob unique, a62 blob unique, a61 blob unique, a60 blob unique, a59 blob unique, a58 blob unique, a57 blob unique, a56 blob unique, a55 blob unique, a54 blob unique, a53 blob unique, a52 blob unique, a51 blob unique, a50 blob unique, a49 blob unique, a48 blob unique, a47 blob unique, a46 blob unique, a45 blob unique, a44 blob unique, a43 blob unique, a42 blob unique, a41 blob unique, a40 blob unique, a39 blob unique, a38 blob unique, a37 blob unique, a36 blob unique, a35 blob unique, a34 blob unique, a33 blob unique, a32 blob unique, a31 blob unique, a30 blob unique, a29 blob unique, a28 blob unique, a27 blob unique, a26 blob unique, a25 blob unique, a24 blob unique, a23 blob unique, a22 blob unique, a21 blob unique, a20 blob unique, a19 blob unique, a18 blob unique, a17 blob unique, a16 blob unique, a15 blob unique, a14 blob unique, a13 blob unique, a12 blob unique, a11 blob unique, a10 blob unique, a9 blob unique, a8 blob unique, a7 blob unique, a6 blob unique, a5 blob unique, a4 blob unique, a3 blob unique, a2 blob unique, a1 blob unique, a blob unique);;
|
|
insert into t1 values( 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);;
|
|
insert into t1 values( 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);;
|
|
ERROR 23000: Duplicate entry '63' for key 'a63'
|
|
insert into t1 values( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63);;
|
|
insert into t1 values( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63);;
|
|
ERROR 23000: Duplicate entry '0' for key 'a63'
|
|
drop table t1;
|
|
create table t1(a blob , key(a));
|
|
Warnings:
|
|
Note 1071 Specified key was too long; max key length is 1000 bytes
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
KEY `a` (`a`(1000))
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
drop table t1;
|
|
create table t1(a blob);
|
|
alter table t1 add index(a);
|
|
Warnings:
|
|
Note 1071 Specified key was too long; max key length is 1000 bytes
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` blob DEFAULT NULL,
|
|
KEY `a` (`a`(1000))
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
drop table t1;
|
|
create table t1(a text, key(a));
|
|
Warnings:
|
|
Note 1071 Specified key was too long; max key length is 1000 bytes
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` text DEFAULT NULL,
|
|
KEY `a` (`a`(1000))
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
drop table t1;
|
|
create table t1(a varchar(4000));
|
|
alter table t1 add index(a);
|
|
Warnings:
|
|
Note 1071 Specified key was too long; max key length is 1000 bytes
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` varchar(4000) DEFAULT NULL,
|
|
KEY `a` (`a`(1000))
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
drop table t1;
|
|
create table t1 (pk int, a int, b int, primary key(pk), key(pk,a));
|
|
alter table t1 modify a text;
|
|
ERROR 42000: Specified key was too long; max key length is 1000 bytes
|
|
alter table t1 modify a varchar(1000);
|
|
ERROR 42000: Specified key was too long; max key length is 1000 bytes
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`pk` int(11) NOT NULL,
|
|
`a` int(11) DEFAULT NULL,
|
|
`b` int(11) DEFAULT NULL,
|
|
PRIMARY KEY (`pk`),
|
|
KEY `pk` (`pk`,`a`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
|
drop table t1;
|
|
#
|
|
# MDEV-19705: Assertion `tmp >= 0' failed in best_access_path
|
|
#
|
|
CREATE TABLE t1 (d varchar(10)) ENGINE=MyISAM;
|
|
INSERT INTO t1 VALUES ('a'),('q');
|
|
CREATE TABLE t2 (f varchar(10), a2 datetime, b int, a1 varchar(1024), pk int NOT NULL, PRIMARY KEY (pk), UNIQUE KEY (f,a1,a2), KEY f2 (f(4),a2)) ENGINE=MyISAM;
|
|
INSERT INTO t2 VALUES ('aaa','1985-09-06',-163,'s',1),('bbb','1995-01-05',3,'pucaz',2),('ccc','0000-00-00',NULL,'help',3),('ddd',NULL,618,'v',4),('eee','1995-12-20',410,'m',5),('ffq','1976-06-12 20:02:56',NULL,'POKNC',6),('dddd','0000-00-00',-328,'hgsu',7);
|
|
explain
|
|
SELECT t2.b FROM t1 JOIN t2 ON t1.d = t2.f WHERE t2.pk >= 20;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t2 range PRIMARY,f,f2 PRIMARY 4 NULL 1 Using index condition
|
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
|
|
SELECT t2.b FROM t1 JOIN t2 ON t1.d = t2.f WHERE t2.pk >= 20;
|
|
b
|
|
drop table t1,t2;
|
|
# End of 10.4 tests
|
|
#
|
|
# MDEV-21470 MyISAM start_bulk_insert doesn't work with long unique
|
|
#
|
|
CREATE TABLE t1 (a INT, b BLOB) ENGINE=MyISAM;
|
|
INSERT INTO t1 VALUES (1,'foo'),(2,'bar');
|
|
CREATE TABLE t2 (c BIT, d BLOB, UNIQUE(d)) ENGINE=MyISAM;
|
|
INSERT INTO t2 SELECT * FROM t1;
|
|
Warnings:
|
|
Warning 1264 Out of range value for column 'c' at row 2
|
|
DROP TABLE t1, t2;
|
|
#
|
|
# MDEV-19338 Using AUTO_INCREMENT with long unique
|
|
#
|
|
CREATE TABLE t1 (pk INT, a TEXT NOT NULL DEFAULT '', PRIMARY KEY (pk), b INT AUTO_INCREMENT, UNIQUE(b), UNIQUE (a,b)) ENGINE=myisam;
|
|
ERROR HY000: AUTO_INCREMENT column `b` cannot be used in the UNIQUE index `a`
|
|
# End of 10.5 tests
|