developers
Threads by month
- ----- 2024 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
January 2019
- 13 participants
- 35 discussions
24 Jul '19
Hello!
While trying to release 10.0.26 for Debian and Ubuntu I noticed git
chokes again on Windows line endings. As our .gitattributes states
that by default git should clean up the line endings, why do we keep
getting new Windows line endings in new code?
mariadb-10.0$ cat .gitattributes
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
...
storage/connect/mysql-test/connect/std_data/*.txt -text
mariadb-10.0.26$ find . | xargs file | grep CRLF
./storage/connect/mysql-test/connect/std_data/boyswin.txt:
ASCII text, with CRLF line terminators
./storage/connect/mysql-test/connect/std_data/expenses.txt:
ASCII text, with CRLF line terminators
./storage/connect/mysql-test/connect/std_data/emp.txt:
ASCII text, with CRLF line terminators
./mysql-test/std_data/loaddata7.dat:
ASCII text, with
CRLF line terminators
./mysql-test/r/loadxml.result:
ASCII text, with
CRLF, LF line terminators
./mysql-test/r/perror-win.result:
ASCII text, with
CRLF, LF line terminators
./mysql-test/r/mysql_binary_mode.result:
ASCII English
text, with CRLF, LF line terminators
./mysql-test/r/func_regexp_pcre.result:
UTF-8 Unicode C++
program text, with CRLF, CR, LF line terminators
./pcre/testdata/grepoutputN:
ASCII text, with CRLF, CR, LF line terminators
./pcre/testdata/greppatN4:
ASCII text, with CRLF line terminators
This leads for me to:
dpkg-source: info: building mariadb-10.0 using existing
./mariadb-10.0_10.0.26.orig.tar.gz
dpkg-source: info: local changes detected, the modified files are:
mariadb-10.0/storage/connect/mysql-test/connect/std_data/boyswin.txt
mariadb-10.0/storage/connect/mysql-test/connect/std_data/emp.txt
mariadb-10.0/storage/connect/mysql-test/connect/std_data/expenses.txt
dpkg-source: error: aborting due to unexpected upstream changes, see
/tmp/mariadb-10.0_10.0.26-1.diff.Yzwwhw
Which means I have to do extra work with importing the upstream sources..
- Otto
2
4
Re: [Maria-developers] 7198e7c71fc: MDEV-15458 Segfault in heap_scan() upon UPDATE after ADD SYSTEM VERSIONING
by Sergei Golubchik 13 May '19
by Sergei Golubchik 13 May '19
13 May '19
Hi, Aleksey!
On Dec 23, Aleksey Midenkov wrote:
> revision-id: 7198e7c71fc (versioning-1.0.6-82-g7198e7c71fc)
> parent(s): 6be155757b7
> author: Aleksey Midenkov <midenok(a)gmail.com>
> committer: Aleksey Midenkov <midenok(a)gmail.com>
> timestamp: 2018-12-20 13:25:00 +0300
> message:
>
> MDEV-15458 Segfault in heap_scan() upon UPDATE after ADD SYSTEM VERSIONING
>
> * HA_EXTRA_REMEMBER_POS, HA_EXTRA_RESTORE_POS for HEAP storage engine
> * Versioning tests support
As far as I can see, there are two approaches to fixing this bug.
And if we go the way of HA_EXTRA_REMEMBER_POS/HA_EXTRA_RESTORE_POS then
your fix is good.
But I'd still like to understand whether write_row is supposed to
disturb the scan. Why should heap_write() overwrite
info->current_ptr=pos and info->current_hash_ptr? Inserting a row
doesn't happen at the "current position", so I don't quite understand
why it modifies current_ptr at all. There is no functionality like
"continue the scan from the last inserted row", right? It just doesn't
make sense to me.
Regards,
Sergei
Chief Architect MariaDB
and security(a)mariadb.org
2
2
Re: [Maria-developers] 0608c273598: MDEV-15966: Behavior for TRUNCATE versioned table is not documented and not covered by tests
by Sergei Golubchik 28 Feb '19
by Sergei Golubchik 28 Feb '19
28 Feb '19
Hi, Nikita!
On Dec 26, Nikita Malyavin wrote:
> revision-id: 0608c273598 (versioning-1.0.5-112-g0608c273598)
> parent(s): 49d506cd1d7
> author: Nikita Malyavin <nikitamalyavin(a)gmail.com>
> committer: Nikita Malyavin <nikitamalyavin(a)gmail.com>
> timestamp: 2018-09-05 04:42:17 +1000
> message:
>
> MDEV-15966: Behavior for TRUNCATE versioned table is not documented and not covered by tests
>
> * MDEV-15966: Behavior for TRUNCATE versioned table is not documented and not covered by tests
>
> * add error for truncation of versioned tables: `ER_TRUNCATE_ILLEGAL_VERS`
> * extract reading `extra2` section in function `dd_read_extra2`
> * update `dd_frm_type` and `ha_table_exists` signatures: add new parameter `is_versioned`
>
> test suites run: main, parts, versioning
>
> [fixes tempesta-tech/mariadb#261]
I don't quite like that a small and simple function dd_frm_type(), which
used to just read few first bytes of the frm file, gets more and more
complex, growing into a complete frm-open method.
So, perhaps, I'd consider changing TRUNCATE to open the table properly
without all that just-read-few-bytes shortcuts.
Or, may be, simply document that TRUNCATE works on versioning tables
just as DROP+CREATE does. There is no logical reason why it shouldn't -
if one can do SHOW CREATE TABLE and CREATE OR REPLACE, then TRUNCATE
won't add any new functionality on top of that. That's the easiest and
most logical "fix" to this bug. Agree?
Regards,
Sergei
Chief Architect MariaDB
and security(a)mariadb.org
2
5
Re: [Maria-developers] df203d1daa1: MDEV-15990: REPLACE on a precise-versioned table returns duplicate key error (ER_DUP_ENTRY)
by Sergei Golubchik 28 Feb '19
by Sergei Golubchik 28 Feb '19
28 Feb '19
Hi, Nikita!
Sorry, I don't understand what are you fixing and why :(
Could you please elaborate?
See few minor comments below and the main question at the very end.
On Dec 26, Nikita Malyavin wrote:
> revision-id: df203d1daa1 (versioning-1.0.5-42-gdf203d1daa1)
> parent(s): 5e89a0dc25a
> author: Nikita Malyavin <nikitamalyavin(a)gmail.com>
> committer: Nikita Malyavin <nikitamalyavin(a)gmail.com>
> timestamp: 2018-07-21 00:14:57 +1000
> message:
>
> MDEV-15990: REPLACE on a precise-versioned table returns duplicate key error (ER_DUP_ENTRY)
>
> * handle zero value in `row_start` `trx_id`
> * refuse to do more than one versioned insert on the same transaction and same row
> * generalize versioned cases with and without triggers
>
> [closes tempesta-tech/mariadb#517]
> [closes tempesta-tech/mariadb#520]
>
> diff --git a/mysql-test/suite/versioning/r/replace.result b/mysql-test/suite/versioning/r/replace.result
> --- a/mysql-test/suite/versioning/r/replace.result
> +++ b/mysql-test/suite/versioning/r/replace.result
> @@ -7,10 +7,31 @@ period for system_time (row_start, row_end)
> ) with system versioning;
> insert t values (1, 2);
> replace t values (1, 3);
> -select *, current_row(row_end) as current from t for system_time all order by x;
> -id x current
> -1 2 0
> -1 3 1
> +replace t values (1, 3);
> +# MDEV-15990: REPLACE on a precise-versioned table
> +# returns duplicate key error (ER_DUP_ENTRY)
> +replace t values (1, 3), (1, 30), (1, 40);
> +create table log(s varchar(3));
> +create trigger tr1del before delete on t
> +for each row insert into log values('DEL');
> +replace t values (1, 4), (1, 40), (1, 400);
> +select *, check_row(row_start, row_end), row_start != 0 as start_nonzero
> +from t for system_time all order by x, row_end;
> +id x check_row(row_start, row_end) start_nonzero
> +1 2 HISTORICAL ROW 1
> +1 3 HISTORICAL ROW 1
> +1 3 HISTORICAL ROW 1
> +1 40 HISTORICAL ROW 1
> +1 400 CURRENT ROW 1
> +select * from log;
> +s
> +DEL
> +DEL
> +DEL
better to insert OLD.x too, to be able to see where the DEL comes from
> +# ensure that row_start is not duplicated
> +select count(row_start) as empty from t for system_time all
> +group by row_start having count(row_start) > 1;
> +empty
> drop table t;
> create table t (
> id int unique,
> diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
> --- a/sql/sql_insert.cc
> +++ b/sql/sql_insert.cc
> @@ -1969,23 +1952,22 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
> TRG_ACTION_BEFORE, TRUE))
> goto before_trg_err;
>
> - if (!table->versioned(VERS_TIMESTAMP))
> + if (table->versioned(VERS_TRX_ID) && table->vers_write)
> + {
can table->vers_write be false here? I suspect it can never be false for
REPLACE, so I'd write it as
if (table->versioned(VERS_TRX_ID))
{
DBUG_ASSERT(table->vers_write);
> + bitmap_set_bit(table->write_set, table->vers_start_field()->field_index);
> + table->vers_start_field()->store(0, false);
> + }
> +
> + if (!table->versioned())
> error= table->file->ha_delete_row(table->record[1]);
> else
> - {
> - store_record(table, record[2]);
> - restore_record(table, record[1]);
> - table->vers_update_end();
> error= table->file->ha_update_row(table->record[1],
> table->record[0]);
> - restore_record(table, record[2]);
> - }
> - if (unlikely(error))
> + if (unlikely(error && error != HA_ERR_RECORD_IS_THE_SAME))
> goto err;
> - if (!table->versioned(VERS_TIMESTAMP))
> + if (likely(!error))
> info->deleted++;
> - else
> - info->updated++;
> + error= 0;
> if (!table->file->has_transactions())
> thd->transaction.stmt.modified_non_trans_table= TRUE;
> if (table->triggers &&
> @@ -1995,6 +1977,17 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
> trg_error= 1;
> goto ok_or_after_trg_err;
> }
> + if (table->versioned(VERS_TIMESTAMP) && table->vers_write)
same
> + {
> + store_record(table, record[2]);
> + error = vers_insert_history_row(table);
why are you doing that (insert + goto after_trg_n_copied_inc)
instead of going the normal REPLACE code path?
> + restore_record(table, record[2]);
> + if (unlikely(error))
> + goto err;
> + }
> + if (table->versioned())
> + goto after_trg_n_copied_inc;
> +
> /* Let us attempt do write_row() once more */
> }
> }
> diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
> index db755077e0b..139c43ced38 100644
> --- a/storage/innobase/handler/ha_innodb.cc
> +++ b/storage/innobase/handler/ha_innodb.cc
> @@ -8916,6 +8916,19 @@ ha_innobase::update_row(
> upd_t* uvect = row_get_prebuilt_update_vector(m_prebuilt);
> ib_uint64_t autoinc;
>
> + bool force_insert= table->versioned_write(VERS_TRX_ID)
> + && table->vers_start_id() == 0;
hmm, so you're using vers_start_id() == 0 as a special hack to signal
REPLACE to the storage engine...
> +
> + if (force_insert) {
> + table->vers_start_field()->store(trx->id);
> +
> + Field *start= table->vers_start_field();
> + trx_id_t old_trx_id= uint8korr(start->ptr_in_record(old_row));
> +
> + /* avoid double versioned insert on the same transaction and same row */
> + force_insert= (old_trx_id != trx->id);
okay, I'm confused. What was wrong in the old code? Normally REPLACE is
DELETE + INSERT, why was it not enough for InnoDB and you needed some
special logic here to handle the REPLACE case?
> + }
> +
> /* Build an update vector from the modified fields in the rows
> (uses m_upd_buf of the handle) */
>
Regards,
Sergei
Chief Architect MariaDB
and security(a)mariadb.org
2
1
Re: [Maria-developers] 773d24d457a: MDEV-15951 system versioning by trx id doesn't work with partitioning
by Sergei Golubchik 28 Feb '19
by Sergei Golubchik 28 Feb '19
28 Feb '19
Hi, Nikita!
On Dec 25, Nikita Malyavin wrote:
> revision-id: 773d24d457a (versioning-1.0.6-100-g773d24d457a)
> parent(s): b26736cdb11
> author: Nikita Malyavin <nikitamalyavin(a)gmail.com>
> committer: Nikita Malyavin <nikitamalyavin(a)gmail.com>
> timestamp: 2018-12-21 03:13:47 +1000
> message:
>
> MDEV-15951 system versioning by trx id doesn't work with partitioning
>
> Fix partitioning for trx_id-versioned tables.
> `partition by hash`, `range` and others now work.
> `partition by system_time` is forbidden.
> Currently we cannot use row_start and row_end in `partition by`, because
> insertion of versioned field is done by engine's handler, as well as
> row_start/row_end's value set up, which is a transaction id -- so it's
> also forbidden.
>
> The drawback is that it's now impossible to use `partition by key()`
> without parameters for such tables, because it references row_start and
> row_end implicitly.
>
> * add handler::vers_can_native()
> * drop Table_scope_and_contents_source_st::vers_native()
> * drop partition_element::find_engine_flag as unused
> * forbid versioning partitioning for trx_id as not supported
> * adopt vers tests for trx_id partitioning
> * forbid any row_end referencing in `partition by` clauses,
> including implicit `by key()`
>
> diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
> index 9e6c333d3c9..48bcb828d56 100644
> --- a/sql/sql_partition.cc
> +++ b/sql/sql_partition.cc
> @@ -341,7 +341,16 @@ static bool set_up_field_array(THD *thd, TABLE *table,
> while ((field= *(ptr++)))
> {
> if (field->flags & GET_FIXED_FIELDS_FLAG)
> + {
> + if (table->versioned(VERS_TRX_ID)
> + && unlikely(field->flags & VERS_SYSTEM_FIELD))
> + {
> + my_error(ER_VERS_NOT_SUPPORTED, MYF(0),
> + "Using ROW START/END for patitioning", "transactional");
This is incorrect usage of error message parameters. The error message
can be translated, parameters can be reordered - you should not use
English as parameter values. Consider:
transactional cистемно-версионированные таблицы не поддерживают Using ROW START/END for patitioning
But looks like ER_VERS_NOT_SUPPORTED is not used anywhere at the moment.
So you can change it to be anything you want, even remove all
parameters:
Transactional system versioned tables do not support partitioning by ROW START or ROW END
> + DBUG_RETURN(TRUE);
> + }
> num_fields++;
> + }
> }
> if (unlikely(num_fields > MAX_REF_PARTS))
> {
> diff --git a/sql/table.cc b/sql/table.cc
> index ce7a34a8fe2..0c2ff1eea5a 100644
> --- a/sql/table.cc
> +++ b/sql/table.cc
> @@ -1776,7 +1776,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
> goto err;
> DBUG_PRINT("info", ("Columns with system versioning: [%d, %d]", row_start, row_end));
> versioned= VERS_TIMESTAMP;
> - vers_can_native= plugin_hton(se_plugin)->flags & HTON_NATIVE_SYS_VERSIONING;
> + vers_can_native= handler_file->vers_can_native(thd);
Interesting. How does that work? Your ha_partition::vers_can_native() is
bool can= !thd->lex->part_info
|| thd->lex->part_info->part_type != VERSIONING_PARTITION;
for (uint i= 0; i < m_tot_parts && can; i++)
can= can && m_file[i]->vers_can_native(thd);
return can;
But it doesn't look like thd->lex->part_info->part_type is initialized
at this point in time. Try to add to your test case
flush tables;
select * from t1;
Regards,
Sergei
Chief Architect MariaDB
and security(a)mariadb.org
2
2
Re: [Maria-developers] bc7d600a27f: MDEV-15951 system versioning by trx id doesn't work with partitioning
by Sergei Golubchik 28 Feb '19
by Sergei Golubchik 28 Feb '19
28 Feb '19
Hi, Nikita!
On Dec 21, Nikita Malyavin wrote:
> > > @@ -4938,6 +4938,7 @@ int ha_create_table(THD *thd, const char *path,
> > > !create_info->tmp_table();
> > >
> > > share.frm_image= frm;
> > > + share.orig_table_name= table_name;
> >
> > why? if orig_table_name is NULL, error_table_name() will use table_name,
> > so there's never need to make orig_table_name==table_name.
> >
> > and I don't understand all your other manipulations with
> > orig_table_name. Could you please explain that?
>
> It affects ALTER TABLE error messages. table_name will contain temporary name,
> and error_table_name() will output "(temporary)", which is rather inconvenient.
> AFAICS, orig_table_name purpose is exactly for fixing that, but some
> corner cases were not covered to this moment.
I don't understand that. You've made a lot of changes in many places
passing orig table name around, it's difficult to see what corner cases
you were trying to fix.
Could you please fix it in a separate commit? With tests and an
explanation in a commit comment, describing what exactly corner cases
were not covered.
> > > // open an frm image
> > > if (share.init_from_binary_frm_image(thd, write_frm_now,
Regards,
Sergei
Chief Architect MariaDB
and security(a)mariadb.org
2
1
Re: [Maria-developers] 4f070b59005: 29 Jan, MDEV-371 Unique indexes for blobs
by Sergei Golubchik 12 Feb '19
by Sergei Golubchik 12 Feb '19
12 Feb '19
Hi, Sachin!
That's generally pretty good.
But I still don't understand what you store in frm and how you
manipulate TABLE and TABLE_SHARE key lists.
Could you please explain that?
On Jan 29, Sachin Setiya wrote:
> diff --git a/mysql-test/main/long_unique.result b/mysql-test/main/long_unique.result
> new file mode 100644
> --- /dev/null
> +++ b/mysql-test/main/long_unique.result
> @@ -0,0 +1,1392 @@
> +#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
> +set @allowed_packet= @@max_allowed_packet;
> +#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`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
Good.
But this also mean that HASH is a valid index type, and that one
can write
CREATE TABLE t1 (a blob, unique (a) USING HASH)
generally, this should work. And one can write
CREATE TABLE t1 (a blob, unique (a) USING BTREE)
and this should fail, "key too long; max key length is 1000 bytes"
Note, the syntax is already possible. You just need to handle
these cases correctly in mysql_prepare_create_table().
And if neither HASH nor BTREE is specified, it's auto-detection,
basically. For short keys it's BTREE, for long keys it's HASH.
This is already implemented by this patch :)
> +Comment
> +Index_comment
> +
> +MyISAM file: DATADIR/test/t1
> +Record format: Packed
> +Character set: latin1_swedish_ci (8)
> +Data records: 10 Deleted blocks: 0
> +Recordlength: 20
> +
> +table description:
> +Key Start Len Index Type
> +1 12 8 multip. ulonglong NULL
> +select * 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 PRIVILEGES COLUMN_COMMENT IS_GENERATED GENERATION_EXPRESSION
> +def test t1 a 1 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob UNI select,insert,update,references 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
> +def test t1 0 test a 1 a A NULL NULL NULL YES HASH
> +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 'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm' 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: 20
> +
> +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`(65535))
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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`(65535))
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +#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 `a` (`a`(65535)),
> + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +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
> +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE
> +#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`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +# try to change the blob unique name;
> +#this will change index to b tree;
> +alter table t1 change column a aa blob ;
eh, the comment is wrong. Your old code
changed the column to int, that was indeed changing the
index to a btree. But now you simply rename the blob.
the index is not changed to btree anymore.
> +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`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE
> +t1 0 a 1 aa A NULL NULL NULL YES HASH
> +# 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
> +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
> +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE
> +t1 0 a 1 aa A NULL NULL NULL YES BTREE
> +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`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE
> +t1 0 a 1 aa A NULL NULL NULL YES BTREE
> +t1 0 clm 1 clm_changed A NULL NULL NULL YES HASH
> +#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
> +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
> +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE
> +t1 0 a 1 aa A NULL NULL NULL YES BTREE
> +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
> +t1 0 a 1 a A NULL NULL NULL YES HASH
> +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
> +t1 0 PRIMARY 1 a A 0 NULL NULL BTREE
> +t1 0 b 1 b A NULL NULL NULL YES HASH
> +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`),
> + UNIQUE KEY `c` (`c`),
> + UNIQUE KEY `d` (`d`),
> + UNIQUE KEY `e` (`e`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 a 1 a A NULL NULL NULL YES HASH
> +t1 0 c 1 c A NULL NULL NULL YES HASH
> +t1 0 d 1 d A NULL NULL NULL YES HASH
> +t1 0 e 1 e A NULL NULL NULL YES HASH
> +
> +MyISAM file: DATADIR/test/t1
> +Record format: Packed
> +Character set: latin1_swedish_ci (8)
> +Data records: 8 Deleted blocks: 0
> +Recordlength: 3072
> +
> +table description:
> +Key Start Len Index Type
> +1 3063 8 multip. ulonglong NULL
> +2 3055 8 multip. ulonglong NULL
> +3 3047 8 multip. ulonglong NULL
> +4 3039 8 multip. ulonglong NULL
> +select * 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 PRIVILEGES COLUMN_COMMENT IS_GENERATED GENERATION_EXPRESSION
> +def test t1 a 1 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob UNI select,insert,update,references NEVER NULL
> +def test t1 b 2 NULL YES int NULL NULL 10 0 NULL NULL NULL int(11) select,insert,update,references NEVER NULL
> +def test t1 c 3 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob UNI select,insert,update,references NEVER NULL
> +def test t1 d 4 NULL YES text 65535 65535 NULL NULL NULL latin1 latin1_swedish_ci text UNI select,insert,update,references NEVER NULL
> +def test t1 e 5 NULL YES varchar 3000 3000 NULL NULL NULL latin1 latin1_swedish_ci varchar(3000) UNI select,insert,update,references 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
> +def test t1 0 test a 1 a A NULL NULL NULL YES HASH
> +def test t1 0 test c 1 c A NULL NULL NULL YES HASH
> +def test t1 0 test d 1 d A NULL NULL NULL YES HASH
> +def test t1 0 test e 1 e A NULL NULL NULL YES HASH
> +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 'ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss' 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`(65535)),
> + UNIQUE KEY `c` (`c`(65535)),
> + UNIQUE KEY `d` (`d`(65535)),
> + UNIQUE KEY `e` (`e`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +#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`(65535)),
> + UNIQUE KEY `c` (`c`(65535)),
> + UNIQUE KEY `d` (`d`(65535)),
> + UNIQUE KEY `e` (`e`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +#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 `a` (`a`(65535)),
> + UNIQUE KEY `c` (`c`(65535)),
> + UNIQUE KEY `d` (`d`(65535)),
> + UNIQUE KEY `e` (`e`),
> + 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`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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 `d` (`d`(65535)),
> + UNIQUE KEY `e` (`e`),
> + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
> + UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 d 1 d A NULL 65535 NULL YES HASH
> +t1 0 e 1 e A NULL NULL NULL YES HASH
> +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE
> +t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE
> +#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 `d` (`d`(65535)),
> + UNIQUE KEY `e` (`e`),
> + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
> + UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`),
> + UNIQUE KEY `a` (`a`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 d 1 d A NULL 65535 NULL YES HASH
> +t1 0 e 1 e A NULL NULL NULL YES HASH
> +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE
> +t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE
> +t1 0 a 1 a A NULL NULL NULL YES HASH
> +#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 `d` (`d`(65535)),
> + UNIQUE KEY `e` (`e`),
> + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
> + UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`),
> + UNIQUE KEY `a` (`a`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 d 1 d A NULL 65535 NULL YES HASH
> +t1 0 e 1 e A NULL NULL NULL YES BTREE
> +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE
> +t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE
> +t1 0 a 1 a A NULL NULL NULL YES BTREE
> +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 `d` (`d`(65535)),
> + UNIQUE KEY `e` (`e`),
> + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
> + UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`),
> + UNIQUE KEY `a` (`a`),
> + UNIQUE KEY `clm1` (`clm_changed1`),
> + UNIQUE KEY `clm2` (`clm_changed2`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 d 1 d A NULL 65535 NULL YES HASH
> +t1 0 e 1 e A NULL NULL NULL YES BTREE
> +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE
> +t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE
> +t1 0 a 1 a A NULL NULL NULL YES BTREE
> +t1 0 clm1 1 clm_changed1 A NULL NULL NULL YES HASH
> +t1 0 clm2 1 clm_changed2 A NULL NULL NULL YES HASH
> +#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 `d` (`d`(65535)),
> + UNIQUE KEY `e` (`e`),
> + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
> + UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`),
> + UNIQUE KEY `a` (`a`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 d 1 d A NULL 65535 NULL YES HASH
> +t1 0 e 1 e A NULL NULL NULL YES BTREE
> +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE
> +t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE
> +t1 0 a 1 a A NULL NULL NULL YES BTREE
> +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`),
> + UNIQUE KEY `c` (`c`,`d`,`e`),
> + UNIQUE KEY `e` (`e`,`f`,`g`,`h`),
> + UNIQUE KEY `b` (`b`,`d`,`g`,`h`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 a 1 a A NULL NULL NULL YES HASH
> +t1 0 a 2 b A NULL NULL NULL YES HASH
> +t1 0 a 3 c A NULL NULL NULL YES HASH
> +t1 0 c 1 c A NULL NULL NULL YES HASH
> +t1 0 c 2 d A 0 NULL NULL YES HASH
> +t1 0 c 3 e A 0 NULL NULL YES HASH
> +t1 0 e 1 e A 0 NULL NULL YES HASH
> +t1 0 e 2 f A 0 NULL NULL YES HASH
> +t1 0 e 3 g A 0 NULL NULL YES HASH
> +t1 0 e 4 h A 0 NULL NULL YES HASH
> +t1 0 b 1 b A 0 NULL NULL YES HASH
> +t1 0 b 2 d A 0 NULL NULL YES HASH
> +t1 0 b 3 g A 0 NULL NULL YES HASH
> +t1 0 b 4 h A 0 NULL NULL YES HASH
> +
> +MyISAM file: DATADIR/test/t1
> +Record format: Packed
> +Character set: latin1_swedish_ci (8)
> +Data records: 9 Deleted blocks: 0
> +Recordlength: 5092
> +
> +table description:
> +Key Start Len Index Type
> +1 5081 8 multip. ulonglong NULL
> +2 5073 8 multip. ulonglong NULL
> +3 5065 8 multip. ulonglong NULL
> +4 5057 8 multip. ulonglong NULL
> +select * 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 PRIVILEGES COLUMN_COMMENT IS_GENERATED GENERATION_EXPRESSION
> +def test t1 a 1 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob MUL select,insert,update,references NEVER NULL
> +def test t1 b 2 NULL YES int NULL NULL 10 0 NULL NULL NULL int(11) MUL select,insert,update,references NEVER NULL
> +def test t1 c 3 NULL YES varchar 2000 2000 NULL NULL NULL latin1 latin1_swedish_ci varchar(2000) MUL select,insert,update,references NEVER NULL
> +def test t1 d 4 NULL YES text 65535 65535 NULL NULL NULL latin1 latin1_swedish_ci text select,insert,update,references NEVER NULL
> +def test t1 e 5 NULL YES varchar 3000 3000 NULL NULL NULL latin1 latin1_swedish_ci varchar(3000) MUL select,insert,update,references NEVER NULL
> +def test t1 f 6 NULL YES longblob 4294967295 4294967295 NULL NULL NULL NULL NULL longblob select,insert,update,references NEVER NULL
> +def test t1 g 7 NULL YES int NULL NULL 10 0 NULL NULL NULL int(11) select,insert,update,references NEVER NULL
> +def test t1 h 8 NULL YES text 65535 65535 NULL NULL NULL latin1 latin1_swedish_ci text select,insert,update,references 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
> +def test t1 0 test a 1 a A NULL NULL NULL YES HASH
> +def test t1 0 test a 2 b A NULL NULL NULL YES HASH
> +def test t1 0 test a 3 c A NULL NULL NULL YES HASH
> +def test t1 0 test c 1 c A NULL NULL NULL YES HASH
> +def test t1 0 test c 2 d A 0 NULL NULL YES HASH
> +def test t1 0 test c 3 e A 0 NULL NULL YES HASH
> +def test t1 0 test e 1 e A 0 NULL NULL YES HASH
> +def test t1 0 test e 2 f A 0 NULL NULL YES HASH
> +def test t1 0 test e 3 g A 0 NULL NULL YES HASH
> +def test t1 0 test e 4 h A 0 NULL NULL YES HASH
> +def test t1 0 test b 1 b A 0 NULL NULL YES HASH
> +def test t1 0 test b 2 d A 0 NULL NULL YES HASH
> +def test t1 0 test b 3 g A 0 NULL NULL YES HASH
> +def test t1 0 test b 4 h A 0 NULL NULL YES HASH
> +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`),
> + UNIQUE KEY `c` (`c`,`d`,`e`),
> + UNIQUE KEY `e` (`e`,`f`,`g`,`h`),
> + UNIQUE KEY `b` (`b`,`d`,`g`,`h`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +# 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`(65535),`b`,`c`),
> + UNIQUE KEY `c` (`c`,`d`(65535),`e`),
> + UNIQUE KEY `e` (`e`,`f`(65535),`g`,`h`(65535)),
> + UNIQUE KEY `b` (`b`,`d`(65535),`g`,`h`(65535))
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 a 1 a A NULL 65535 NULL YES HASH
> +t1 0 a 2 b A NULL NULL NULL YES HASH
> +t1 0 a 3 c A NULL NULL NULL YES HASH
> +t1 0 c 1 c A NULL NULL NULL YES HASH
> +t1 0 c 2 d A 0 65535 NULL YES HASH
> +t1 0 c 3 e A 0 NULL NULL YES HASH
> +t1 0 e 1 e A 0 NULL NULL YES HASH
> +t1 0 e 2 f A 0 65535 NULL YES HASH
> +t1 0 e 3 g A 0 NULL NULL YES HASH
> +t1 0 e 4 h A 0 65535 NULL YES HASH
> +t1 0 b 1 b A 0 NULL NULL YES HASH
> +t1 0 b 2 d A 0 65535 NULL YES HASH
> +t1 0 b 3 g A 0 NULL NULL YES HASH
> +t1 0 b 4 h A 0 65535 NULL YES HASH
> +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`(65535),`b`,`c`),
> + UNIQUE KEY `c` (`c`,`d`(65535),`e`),
> + UNIQUE KEY `b` (`b`,`d`(65535),`g`,`h`(65535)),
> + UNIQUE KEY `e` (`e`,`f`(65535),`g`,`h`(65535))
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 a 1 a A NULL 65535 NULL YES HASH
> +t1 0 a 2 b A NULL NULL NULL YES HASH
> +t1 0 a 3 c A NULL NULL NULL YES HASH
> +t1 0 c 1 c A NULL NULL NULL YES HASH
> +t1 0 c 2 d A 0 65535 NULL YES HASH
> +t1 0 c 3 e A 0 NULL NULL YES HASH
> +t1 0 b 1 b A 0 NULL NULL YES HASH
> +t1 0 b 2 d A 0 65535 NULL YES HASH
> +t1 0 b 3 g A 0 NULL NULL YES HASH
> +t1 0 b 4 h A 0 65535 NULL YES HASH
> +t1 0 e 1 e A 0 NULL NULL YES HASH
> +t1 0 e 2 f A 0 65535 NULL YES HASH
> +t1 0 e 3 g A 0 NULL NULL YES HASH
> +t1 0 e 4 h A 0 65535 NULL YES HASH
> +#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`(65535),`bb`,`c`),
> + UNIQUE KEY `c` (`c`,`dd`(65535),`e`),
> + UNIQUE KEY `b` (`bb`,`dd`(65535),`g`,`h`(65535)),
> + UNIQUE KEY `e` (`e`,`f`(65535),`g`,`h`(65535))
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 a 1 aa A NULL 65535 NULL YES HASH
> +t1 0 a 2 bb A NULL NULL NULL YES HASH
> +t1 0 a 3 c A NULL NULL NULL YES HASH
> +t1 0 c 1 c A NULL NULL NULL YES HASH
> +t1 0 c 2 dd A 0 65535 NULL YES HASH
> +t1 0 c 3 e A 0 NULL NULL YES HASH
> +t1 0 b 1 bb A 0 NULL NULL YES HASH
> +t1 0 b 2 dd A 0 65535 NULL YES HASH
> +t1 0 b 3 g A 0 NULL NULL YES HASH
> +t1 0 b 4 h A 0 65535 NULL YES HASH
> +t1 0 e 1 e A 0 NULL NULL YES HASH
> +t1 0 e 2 f A 0 65535 NULL YES HASH
> +t1 0 e 3 g A 0 NULL NULL YES HASH
> +t1 0 e 4 h A 0 65535 NULL YES HASH
> +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`(65535),`b`,`c`),
> + UNIQUE KEY `c` (`c`,`d`(65535),`e`),
> + UNIQUE KEY `b` (`b`,`d`(65535),`g`,`h`(65535)),
> + UNIQUE KEY `e` (`e`,`f`(65535),`g`,`h`(65535))
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 a 1 a A NULL 65535 NULL YES HASH
> +t1 0 a 2 b A NULL NULL NULL YES HASH
> +t1 0 a 3 c A NULL NULL NULL YES HASH
> +t1 0 c 1 c A NULL NULL NULL YES HASH
> +t1 0 c 2 d A 0 65535 NULL YES HASH
> +t1 0 c 3 e A 0 NULL NULL YES HASH
> +t1 0 b 1 b A 0 NULL NULL YES HASH
> +t1 0 b 2 d A 0 65535 NULL YES HASH
> +t1 0 b 3 g A 0 NULL NULL YES HASH
> +t1 0 b 4 h A 0 65535 NULL YES HASH
> +t1 0 e 1 e A 0 NULL NULL YES HASH
> +t1 0 e 2 f A 0 65535 NULL YES HASH
> +t1 0 e 3 g A 0 NULL NULL YES HASH
> +t1 0 e 4 h A 0 65535 NULL YES HASH
> +#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`(65535),`e`),
> + UNIQUE KEY `b` (`b`,`d`(65535),`g`,`h`(65535)),
> + UNIQUE KEY `e` (`e`,`f`(65535),`g`,`h`(65535))
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 a 1 a A NULL NULL NULL YES BTREE
> +t1 0 a 2 b A NULL NULL NULL YES BTREE
> +t1 0 a 3 c A NULL NULL NULL YES BTREE
> +t1 0 c 1 c A NULL NULL NULL YES HASH
> +t1 0 c 2 d A NULL 65535 NULL YES HASH
> +t1 0 c 3 e A NULL NULL NULL YES HASH
> +t1 0 b 1 b A 0 NULL NULL YES HASH
> +t1 0 b 2 d A 0 65535 NULL YES HASH
> +t1 0 b 3 g A 0 NULL NULL YES HASH
> +t1 0 b 4 h A 0 65535 NULL YES HASH
> +t1 0 e 1 e A 0 NULL NULL YES HASH
> +t1 0 e 2 f A 0 65535 NULL YES HASH
> +t1 0 e 3 g A 0 NULL NULL YES HASH
> +t1 0 e 4 h A 0 65535 NULL YES HASH
> +#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`),
> + UNIQUE KEY `c` (`c`,`d`(65535),`e`),
> + UNIQUE KEY `b` (`b`,`d`(65535),`g`,`h`(65535)),
> + UNIQUE KEY `e` (`e`,`f`(65535),`g`,`h`(65535))
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 a 1 a A NULL NULL NULL YES HASH
> +t1 0 a 2 b A NULL NULL NULL YES HASH
> +t1 0 a 3 c A NULL NULL NULL YES HASH
> +t1 0 c 1 c A NULL NULL NULL YES HASH
> +t1 0 c 2 d A 0 65535 NULL YES HASH
> +t1 0 c 3 e A 0 NULL NULL YES HASH
> +t1 0 b 1 b A 0 NULL NULL YES HASH
> +t1 0 b 2 d A 0 65535 NULL YES HASH
> +t1 0 b 3 g A 0 NULL NULL YES HASH
> +t1 0 b 4 h A 0 65535 NULL YES HASH
> +t1 0 e 1 e A 0 NULL NULL YES HASH
> +t1 0 e 2 f A 0 65535 NULL YES HASH
> +t1 0 e 3 g A 0 NULL NULL YES HASH
> +t1 0 e 4 h A 0 65535 NULL YES HASH
> +#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`(65535),`b`(65535),`c`(65535)),
> + UNIQUE KEY `b` (`b`(65535),`d`(65535),`g`,`h`(65535))
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 a 1 a A NULL 65535 NULL YES HASH
> +t1 0 a 2 b A NULL 65535 NULL YES HASH
> +t1 0 a 3 c A 0 65535 NULL YES HASH
> +t1 0 b 1 b A 0 65535 NULL YES HASH
> +t1 0 b 2 d A 0 65535 NULL YES HASH
> +t1 0 b 3 g A 0 NULL NULL YES HASH
> +t1 0 b 4 h A 0 65535 NULL YES HASH
> +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`(65535))
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 a 1 a A NULL 65535 NULL YES HASH
> +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 `a` (`a`(65535),`c`(65535)),
> + UNIQUE KEY `b` (`b`(65535),`d`(65535)),
> + UNIQUE KEY `e` (`e`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 a 1 a A NULL 65535 NULL YES HASH
> +t1 0 a 2 c A NULL 65535 NULL YES HASH
> +t1 0 b 1 b A NULL 65535 NULL YES HASH
> +t1 0 b 2 d A 0 65535 NULL YES HASH
> +t1 0 e 1 e A 0 NULL NULL YES BTREE
> +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
> +22 2
> +33 3
> +44 4
> +11 1
> +22 2
> +33 3
> +44 4
> +11 1
> +22 2
> +33 3
> +44 4
> +11 1
> +22 2
> +33 3
> +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;
> +#very long blob entry;
> +SET @@GLOBAL.max_allowed_packet=67108864;
> +connect 'newcon', localhost, root,,;
> +connection newcon;
> +show variables like 'max_allowed_packet';
> +Variable_name Value
> +max_allowed_packet 67108864
> +create table t1(a longblob unique, b longblob , c longblob , unique(b,c));
> +desc t1;
> +Field Type Null Key Default Extra
> +a longblob YES UNI NULL
> +b longblob YES MUL NULL
> +c longblob YES NULL
> +show create table t1;
> +Table Create Table
> +t1 CREATE TABLE `t1` (
> + `a` longblob DEFAULT NULL,
> + `b` longblob DEFAULT NULL,
> + `c` longblob DEFAULT NULL,
> + UNIQUE KEY `a` (`a`),
> + UNIQUE KEY `b` (`b`,`c`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 a 1 a A NULL NULL NULL YES HASH
> +t1 0 b 1 b A NULL NULL NULL YES HASH
> +t1 0 b 2 c A 0 NULL NULL YES HASH
> +insert into t1 values(concat(repeat('sachin',10000000),'1'),concat(repeat('sachin',10000000),'1'),
> +concat(repeat('sachin',10000000),'1'));
> +insert into t1 values(concat(repeat('sachin',10000000),'2'),concat(repeat('sachin',10000000),'2'),
> +concat(repeat('sachin',10000000),'1'));
> +insert into t1 values(concat(repeat('sachin',10000000),'2'),concat(repeat('sachin',10000000),'2'),
> +concat(repeat('sachin',10000000),'4'));
> +ERROR 23000: Duplicate entry 'sachinsachinsachinsachinsachinsachinsachinsachinsachinsachinsach' for key 'a'
> +insert into t1 values(concat(repeat('sachin',10000000),'3'),concat(repeat('sachin',10000000),'1'),
> +concat(repeat('sachin',10000000),'1'));
> +ERROR 23000: Duplicate entry 'sachinsachinsachinsachinsachinsachinsachinsachinsachinsachinsach' for key 'b'
> +drop table t1;
> +#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
> +t1 0 a 1 a A NULL 3000 NULL YES HASH
> +show create table t1;
> +Table Create Table
> +t1 CREATE TABLE `t1` (
> + `a` blob DEFAULT NULL,
> + UNIQUE KEY `a` (`a`(3000))
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +insert into t1 value(concat(repeat('s',3000),'1'));
> +insert into t1 value(concat(repeat('s',3000),'2'));
> +ERROR 23000: Duplicate entry 'ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss' 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`),
> + UNIQUE KEY `c` (`c`(4500),`d`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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
> +t1 0 a 1 a A NULL 3500 NULL YES HASH
> +t1 0 a 2 b A NULL NULL NULL YES HASH
> +t1 0 c 1 c A 0 4500 NULL YES HASH
> +t1 0 c 2 d A 0 NULL NULL YES HASH
> +drop table t1;
> +disconnect newcon;
> +connection default;
> +SET @@GLOBAL.max_allowed_packet=4194304;
> +#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`),
> + KEY `c` (`c`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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`),
> + KEY `c` (`c`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +insert into t2 values(1,1);
> +insert into t2 values(2,1);
> +drop table t2;
> +#not null test //todo solve warnings
> +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`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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`),
> + UNIQUE KEY `b` (`b`,`c`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +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^15 -1
> +create table t1(a blob, unique(a(100001)));
> +ERROR 42000: Specified key was too long; max key length is 1000 bytes
> +set @@GLOBAL.max_allowed_packet= @allowed_packet;
> diff --git a/mysql-test/main/long_unique_debug.result b/mysql-test/main/long_unique_debug.result
> new file mode 100644
> --- /dev/null
> +++ b/mysql-test/main/long_unique_debug.result
> @@ -0,0 +1,32 @@
> +#In this test case we will check what will happen in the case of hash collusion
collision, not collusion :)
> +SET debug_dbug="d,same_long_unique_hash";
> +create table t1(a blob unique);
> +insert into t1 values('xyz');
> +insert into t1 values('abc');
> +insert into t1 values('sachin');
> +insert into t1 values('sachin');
> +ERROR 23000: Duplicate entry 'sachin' for key 'a'
> +insert into t1 values('maria');
> +insert into t1 values('maria');
> +ERROR 23000: Duplicate entry 'maria' for key 'a'
> +drop table t1;
> +create table t1(a blob unique, b blob unique);
> +insert into t1 values('xyz', 11);
> +insert into t1 values('abc', 22);
> +insert into t1 values('sachin', 1);
> +insert into t1 values('sachin', 4);
> +ERROR 23000: Duplicate entry 'sachin' for key 'a'
> +insert into t1 values('maria', 2);
> +insert into t1 values('maria', 3);
> +ERROR 23000: Duplicate entry 'maria' for key 'a'
> +drop table t1;
> +create table t1(a blob , b blob , unique(a,b));
> +insert into t1 values('xyz', 11);
> +insert into t1 values('abc', 22);
> +insert into t1 values('sachin', 1);
> +insert into t1 values('sachin', 1);
> +ERROR 23000: Duplicate entry 'sachin-1' for key 'a'
> +insert into t1 values('maria', 2);
> +insert into t1 values('maria', 2);
> +ERROR 23000: Duplicate entry 'maria-2' for key 'a'
> +drop table t1;
> diff --git a/mysql-test/main/mdev-504.test b/mysql-test/main/mdev-504.test
> --- a/mysql-test/main/mdev-504.test
> +++ b/mysql-test/main/mdev-504.test
> @@ -44,7 +43,7 @@ while ($trial)
> --connect (con2,localhost,root,,)
> --send CALL p_analyze()
>
> - --let $run = 100
> + --let $run = 1
Why?
>
> while ($run)
> {
> diff --git a/mysql-test/main/type_blob.result b/mysql-test/main/type_blob.result
> --- a/mysql-test/main/type_blob.result
> +++ b/mysql-test/main/type_blob.result
> @@ -370,7 +370,7 @@ a 1
> hello 1
> drop table t1;
> create table t1 (a text, unique (a(2100)));
> -ERROR 42000: Specified key was too long; max key length is 1000 bytes
> +drop table t1;
or remove the create table instead, it's not a useful test anymore
> create table t1 (a text, key (a(2100)));
> Warnings:
> Note 1071 Specified key was too long; max key length is 1000 bytes
> diff --git a/sql/field.h b/sql/field.h
> --- a/sql/field.h
> +++ b/sql/field.h
> @@ -687,7 +687,7 @@ class Field: public Value_source
> GEOM_MULTIPOINT = 4, GEOM_MULTILINESTRING = 5, GEOM_MULTIPOLYGON = 6,
> GEOM_GEOMETRYCOLLECTION = 7
> };
> - enum imagetype { itRAW, itMBR};
> + enum imagetype { itRAW, itMBR, itHASH};
unused
>
> utype unireg_check;
> uint32 field_length; // Length of field
> diff --git a/sql/handler.cc b/sql/handler.cc
> --- a/sql/handler.cc
> +++ b/sql/handler.cc
> @@ -3686,9 +3686,19 @@ void handler::print_error(int error, myf errflag)
> uint key_nr=get_dup_key(error);
> if ((int) key_nr >= 0 && key_nr < table->s->keys)
> {
> + KEY *long_key= NULL;
> + if (table->key_info[key_nr].algorithm
> + == HA_KEY_ALG_LONG_HASH)
> + {
> + long_key= table->key_info + key_nr;
> + setup_keyinfo_hash(long_key);
> + }
> print_keydup_error(table, &table->key_info[key_nr], errflag);
> + if (long_key)
> + re_setup_keyinfo_hash(long_key);
> DBUG_VOID_RETURN;
> }
> + table->re_setup_table();
> }
> textno=ER_DUP_KEY;
> break;
> @@ -6256,6 +6268,162 @@ int handler::ha_reset()
> DBUG_RETURN(reset());
> }
>
> +static int check_duplicate_long_entry_key(TABLE *table, handler *h, uchar *new_rec,
> + uint key_no)
> +{
> + Field *hash_field;
> + int result, error= 0;
> + KEY *key_info= table->key_info + key_no;
> + hash_field= key_info->key_part->field;
> + DBUG_ASSERT((table->key_info[key_no].flags & HA_NULL_PART_KEY &&
> + table->key_info[key_no].key_length == HA_HASH_KEY_LENGTH_WITH_NULL)
> + || table->key_info[key_no].key_length == HA_HASH_KEY_LENGTH_WITHOUT_NULL);
> + uchar ptr[HA_HASH_KEY_LENGTH_WITH_NULL];
> +
> + if (hash_field->is_real_null())
> + return 0;
> +
remember, you have `key_info= table->key_info + key_no` above :)
you don't need to write `table->key_info[key_no]` anymore here
> + key_copy(ptr, new_rec, &table->key_info[key_no],
> + table->key_info[key_no].key_length, false);
> +
> + if (!table->check_unique_buf)
> + table->check_unique_buf= (uchar *)alloc_root(&table->mem_root,
> + table->s->reclength*sizeof(uchar));
C99 standard says
6.5.3.4 The sizeof operator
When applied to an operand that has type char, unsigned
char, or signed char, (or a qualified version thereof) the
result is 1.
so don't bother with `*sizeof(uchar)`
> +
> + result= h->ha_index_init(key_no, 0);
> + if (result)
> + return result;
> + result= h->ha_index_read_map(table->check_unique_buf,
> + ptr, HA_WHOLE_KEY, HA_READ_KEY_EXACT);
> + if (!result)
> + {
> + bool is_same;
> + Field * t_field;
> + Item_func_hash * temp= (Item_func_hash *)hash_field->vcol_info->expr;
> + Item ** arguments= temp->arguments();
> + uint arg_count= temp->argument_count();
> + do
> + {
> + long diff= table->check_unique_buf - new_rec;
> + is_same= true;
> + for (uint j=0; j < arg_count; j++)
you can add `is_same && ` here to the for() condition too.
> + {
> + DBUG_ASSERT(arguments[j]->type() == Item::FIELD_ITEM ||
> + // this one for left(fld_name,length)
> + arguments[j]->type() == Item::FUNC_ITEM);
> + if (arguments[j]->type() == Item::FIELD_ITEM)
> + {
> + t_field= static_cast<Item_field *>(arguments[j])->field;
> + if (t_field->cmp_offset(diff))
> + is_same= false;
> + }
> + else
> + {
> + Item_func_left *fnc= static_cast<Item_func_left *>(arguments[j]);
> + DBUG_ASSERT(!my_strcasecmp(system_charset_info, "left", fnc->func_name()));
> + DBUG_ASSERT(fnc->arguments()[0]->type() == Item::FIELD_ITEM);
> + t_field= static_cast<Item_field *>(fnc->arguments()[0])->field;
> + uint length= fnc->arguments()[1]->val_int();
> + if (t_field->cmp_max(t_field->ptr, t_field->ptr + diff, length))
> + is_same= false;
> + }
> + }
> + }
> + while (!is_same && !(result= table->file->ha_index_next_same(table->check_unique_buf,
> + ptr, table->key_info[key_no].key_length)));
> + if (is_same)
> + {
> + table->dupp_hash_key= key_no;
> + error= HA_ERR_FOUND_DUPP_KEY;
> + goto exit;
> + }
> + else
> + goto exit;
> + }
> + if (result == HA_ERR_LOCK_WAIT_TIMEOUT)
> + {
> + table->dupp_hash_key= key_no;
> + //TODO check if this is the only case
> + error= HA_ERR_FOUND_DUPP_KEY;
why not to keep HA_ERR_LOCK_WAIT_TIMEOUT?
> + }
> + exit:
> + h->ha_index_end();
> + return error;
> +}
empty line between functions, please
> +/** @brief
> + check whether inserted records breaks the
> + unique constraint on long columns.
> + @returns 0 if no duplicate else returns error
> + */
> +static int check_duplicate_long_entries(TABLE *table, handler *h, uchar *new_rec)
> +{
> + table->dupp_hash_key= -1;
> + int result;
> + for (uint i= 0; i < table->s->keys; i++)
> + {
> + if (table->key_info[i].algorithm == HA_KEY_ALG_LONG_HASH &&
> + (result= check_duplicate_long_entry_key(table, h, new_rec, i)))
> + return result;
> + }
> + return 0;
> +}
> +
> +/** @brief
> + check whether updated records breaks the
> + unique constraint on long columns.
> + In the case of update we just need to check the specic key
> + reason for that is consider case
> + create table t1(a blob , b blob , x blob , y blob ,unique(a,b)
> + ,unique(x,y))
> + and update statement like this
> + update t1 set a=23+a; in this case if we try to scan for
> + whole keys in table then index scan on x_y will return 0
> + because data is same so in the case of update we take
> + key as a parameter in normal insert key should be -1
> + @returns 0 if no duplicate else returns error
> + */
> +static int check_duplicate_long_entries_update(TABLE *table, handler *h, uchar *new_rec)
> +{
> + Field *field;
> + uint key_parts;
> + int error= 0;
> + KEY *keyinfo;
> + KEY_PART_INFO *keypart;
> + /*
> + Here we are comparing whether new record and old record are same
> + with respect to fields in hash_str
> + */
> + long reclength= table->record[1]-table->record[0];
> + if (!table->update_handler)
> + table->clone_handler_for_update();
> + for (uint i= 0; i < table->s->keys; i++)
> + {
> + keyinfo= table->key_info + i;
> + if (keyinfo->algorithm == HA_KEY_ALG_LONG_HASH)
> + {
> + key_parts= fields_in_hash_keyinfo(keyinfo);
> + keypart= keyinfo->key_part - key_parts;
> + for (uint j= 0; j < key_parts; j++, keypart++)
> + {
> + field= keypart->field;
> + /* Compare fields if they are different then check for duplicates*/
> + if(field->cmp_binary_offset(reclength))
> + {
> + if((error= check_duplicate_long_entry_key(table, table->update_handler,
> + new_rec, i)))
> + goto exit;
> + /*
> + break beacuse check_duplicate_long_entrie_key will
> + take care of remaning fields
three typos in two lines :)
> + */
> + break;
> + }
> + }
> + }
> + }
> + exit:
> + return error;
> +}
>
> int handler::ha_write_row(uchar *buf)
> {
> diff --git a/sql/item.cc b/sql/item.cc
> --- a/sql/item.cc
> +++ b/sql/item.cc
> @@ -356,7 +356,7 @@ Item::Item(THD *thd):
> /* Initially this item is not attached to any JOIN_TAB. */
> join_tab_idx= MAX_TABLES;
>
> - /* Put item in free list so that we can free all items at end */
> + /* Put item in free list so that we can free all items at end only if*/
Huh?
> next= thd->free_list;
> thd->free_list= this;
> /*
> diff --git a/sql/item_func.cc b/sql/item_func.cc
> --- a/sql/item_func.cc
> +++ b/sql/item_func.cc
> @@ -1718,6 +1718,48 @@ bool Item_func_mod::fix_length_and_dec()
> DBUG_RETURN(FALSE);
> }
>
> +inline void calc_hash_for_unique(ulong &nr1, ulong &nr2, String *str)
static inline (or simply static, a compiler will inline it anyway)
> +{
> + CHARSET_INFO *cs;
> + uchar l[4];
> + int4store(l, str->length());
> + cs= str->charset();
> + cs->coll->hash_sort(cs, l, sizeof(l), &nr1, &nr2);
> + cs= str->charset();
> + cs->coll->hash_sort(cs, (uchar *)str->ptr(), str->length(), &nr1, &nr2);
> +}
> +
> +longlong Item_func_hash::val_int()
> +{
> + DBUG_EXECUTE_IF("same_long_unique_hash", return 9;);
good that you've added tests for collisions!
> + unsigned_flag= true;
> + ulong nr1= 1,nr2= 4;
> + CHARSET_INFO *cs;
> + String * str;
> + for(uint i= 0;i<arg_count;i++)
> + {
> + str = args[i]->val_str();
> + if(args[i]->null_value)
> + {
> + null_value= 1;
> + return 0;
> + }
> + calc_hash_for_unique(nr1, nr2, str);
> + }
> + null_value= 0;
> + return (longlong)nr1;
> +}
> +
> +
> +bool Item_func_hash::fix_length_and_dec()
> +{
> + maybe_null= 1;
Why are you forcing maybe_null=1?
Most functions are "normal" - they can return NULL if one of the
arguments is NULL, otherwise they don't return NULL.
And Item_func::fix_fields() sets maybe_null accordingly, it'll
be 1 if any of the arguments has maybe_null==1, otherwise
maybe_null will be 0.
You only need to set maybe_null explicitly if your function is
special, for ISNULL(x) # never returns NULL, and NULLIF(x,y)
can return NULL when both arguments are not NULL.
Looks like in your case the default maybe_null beahavior is
correct, though.
> + decimals= 0;
> + max_length= 8;
> + return false;
> +}
> +
> +
>
> double Item_func_neg::real_op()
> {
> diff --git a/sql/sql_base.cc b/sql/sql_base.cc
> --- a/sql/sql_base.cc
> +++ b/sql/sql_base.cc
> @@ -994,6 +994,8 @@ void close_thread_table(THD *thd, TABLE **table_ptr)
> table->file->update_global_table_stats();
> table->file->update_global_index_stats();
> }
> + if (table->update_handler)
> + table->delete_update_handler();
you're doing it in sql_update.cc, isn't it enough?
>
> /*
> This look is needed to allow THD::notify_shared_lock() to
> diff --git a/sql/sql_show.cc b/sql/sql_show.cc
> --- a/sql/sql_show.cc
> +++ b/sql/sql_show.cc
> @@ -2306,7 +2307,7 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
> */
> packet->append(STRING_WITH_LEN("PRIMARY KEY"));
> }
> - else if (key_info->flags & HA_NOSAME)
> + else if (key_info->flags & HA_NOSAME || key_info->algorithm == HA_KEY_ALG_LONG_HASH)
I'd think that after setup_table_hash(), HA_NOSAME should be set
and you wouldn't need extra checks.
> packet->append(STRING_WITH_LEN("UNIQUE KEY "));
> else if (key_info->flags & HA_FULLTEXT)
> packet->append(STRING_WITH_LEN("FULLTEXT KEY "));
> @@ -6546,7 +6548,7 @@ static int get_schema_stat_record(THD *thd, TABLE_LIST *tables,
> else if (!tables->view)
> {
> TABLE *show_table= tables->table;
> - KEY *key_info=show_table->s->key_info;
> + KEY *key_info=show_table->key_info;
you mean, TABLE_SHARE::key_info shows your HASH definition?
and but you change (with setup_table_hash) TABLE::key_info
to store the original user's UNIQUE definition?
Why is TABLE_SHARE::key_info changed?
> if (show_table->file)
> {
> show_table->file->info(HA_STATUS_VARIABLE |
> diff --git a/sql/sql_table.cc b/sql/sql_table.cc
> --- a/sql/sql_table.cc
> +++ b/sql/sql_table.cc
> @@ -4106,12 +4177,28 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
> if (key->type == Key::UNIQUE && !(key_info->flags & HA_NULL_PART_KEY))
> unique_key=1;
> key_info->key_length=(uint16) key_length;
> - if (key_length > max_key_length && key->type != Key::FULLTEXT)
> + if (key_length > max_key_length && key->type != Key::FULLTEXT &&
> + !is_hash_field_needed)
> {
> my_error(ER_TOO_LONG_KEY,MYF(0),max_key_length);
> DBUG_RETURN(TRUE);
> }
>
> + if (is_hash_field_needed)
> + {
> + Create_field *hash_fld= add_hash_field(thd, &alter_info->create_list,
> + create_info->default_table_charset,
> + key_info);
> + hash_fld->offset= record_offset;
> + record_offset+= hash_fld->pack_length;
> + if (key_info->flags & HA_NULL_PART_KEY)
> + null_fields++;
> + else
> + {
> + hash_fld->flags|= NOT_NULL_FLAG;
> + hash_fld->pack_flag&= ~FIELDFLAG_MAYBE_NULL;
> + }
> + }
Hmm, haven't we agreed *not* to write the virtual hash field
into the frm, not show it to create/alter table and
add it automatically when the table is opened?
> if (validate_comment_length(thd, &key->key_create_info.comment,
> INDEX_COMMENT_MAXLEN,
> ER_TOO_LONG_INDEX_COMMENT,
> diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
> --- a/sql/sql_yacc.yy
> +++ b/sql/sql_yacc.yy
> @@ -10820,6 +10820,12 @@ function_call_conflict:
> if (unlikely($$ == NULL))
> MYSQL_YYABORT;
> }
> + | HASH_SYM '(' expr_list ')'
> + {
> + $$= new (thd->mem_root)Item_func_hash(thd,*$3);
> + if (unlikely($$ == NULL))
> + MYSQL_YYABORT;
> + }
Haven't we agreed to make this HASH() function fully internal,
not visible to the parser?
> /* LAST_VALUE here conflicts with the definition for window functions.
> We have these 2 separate rules to remove the shift/reduce conflict.
> */
> diff --git a/sql/table.cc b/sql/table.cc
> --- a/sql/table.cc
> +++ b/sql/table.cc
> @@ -747,7 +746,7 @@ static bool create_key_infos(const uchar *strpos, const uchar *frm_image_end,
> if (i == 0)
> {
> ext_key_parts+= (share->use_ext_keys ? first_keyinfo->user_defined_key_parts*(keys-1) : 0);
> - n_length=keys * sizeof(KEY) + ext_key_parts * sizeof(KEY_PART_INFO);
> + n_length=keys * sizeof(KEY) + (ext_key_parts) * sizeof(KEY_PART_INFO);
Another left-over from an intermediate implementation? :)
> if (!(keyinfo= (KEY*) alloc_root(&share->mem_root,
> n_length + len)))
> return 1;
> @@ -798,6 +797,12 @@ static bool create_key_infos(const uchar *strpos, const uchar *frm_image_end,
> }
> key_part->store_length=key_part->length;
> }
> + if (keyinfo->algorithm == HA_KEY_ALG_LONG_HASH)
> + {
> + keyinfo->key_length= HA_HASH_KEY_LENGTH_WITHOUT_NULL;
> + //Storing key hash
> + key_part++;
> + }
I don't understand what you do here
>
> /*
> Add primary key to end of extended keys for non unique keys for
> @@ -831,7 +836,9 @@ static bool create_key_infos(const uchar *strpos, const uchar *frm_image_end,
> if (j == first_key_parts)
> keyinfo->ext_key_flags= keyinfo->flags | HA_EXT_NOSAME;
> }
> - share->ext_key_parts+= keyinfo->ext_key_parts;
> + if (keyinfo->algorithm == HA_KEY_ALG_LONG_HASH)
> + share->ext_key_parts++;
> + share->ext_key_parts+= keyinfo->ext_key_parts;
I don't understand what you do here
> }
> keynames=(char*) key_part;
> strpos+= strnmov(keynames, (char *) strpos, frm_image_end - strpos) - keynames;
> @@ -3322,6 +3421,36 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share,
>
> key_part_end= key_part + (share->use_ext_keys ? key_info->ext_key_parts :
> key_info->user_defined_key_parts) ;
> + if (key_info->algorithm == HA_KEY_ALG_LONG_HASH)
> + {
> + /*
> + Either it can be first time opening the table share or it can be second time
> + of more. The difference is when it is first time key_part[0]->fieldnr points
> + to blob/long field, but when it is 2nd time there will bw always one key_part
> + and it will point to hash_field.
> + So in the case of 2nd time we will make key_info->key_part point to start of long
> + field.
you're overcomplicating here.
if you would *always* create your HASH key_def in
parse_vcol_defs(), you'll have TABLE_SHARE to be always "like
the first time", you simply never modify TABLE_SHARE and always
modify TABLEin parse_vcol_defs().
and you won't need setup_keyinfo_hash/setup_table_hash functions
either.
> + For example we have unique(a,b,c)
> + In first share opening key_part will point to a field
> + but in parse_vcol_defs it will be changed to point to db_row_hash field
> + in Second or later opening key_part will be pointing to db_row_hash
> + We will chnage it back to point to field a, because in this way we can create
> + vcol_info for hash field in parse_vcol_defs.
> + */
> + //Second or more time share opening
> + key_info->user_defined_key_parts= 0;
> + key_part_end= key_part;
> + while(!(share->field[key_part_end->fieldnr -1 ]->flags & LONG_UNIQUE_HASH_FIELD))
> + {
> + key_part_end++;
> + key_info->user_defined_key_parts++;
> + }
> + key_info->usable_key_parts= key_info->ext_key_parts= key_info->user_defined_key_parts;
> + key_part_end++;
> + share_keyinfo= share->key_info + key_no;
> + if (share_keyinfo->key_part->field->flags & LONG_UNIQUE_HASH_FIELD)
> + share_keyinfo->key_part-= key_info->user_defined_key_parts;
> + }
> for ( ; key_part < key_part_end; key_part++)
> {
> Field *field= key_part->field= outparam->field[key_part->fieldnr - 1];
> @@ -8498,6 +8630,120 @@ double KEY::actual_rec_per_key(uint i)
> }
>
>
> +/*
> + find out the field positoin in hash_str()
> + position starts from 0
> + else return -1;
> +*/
> +int find_field_pos_in_hash(Item *hash_item, const char * field_name)
> +{
> + Item_func_or_sum * temp= static_cast<Item_func_or_sum *>(hash_item);
> + Item_args * t_item= static_cast<Item_args *>(temp);
> + uint arg_count= t_item->argument_count();
> + Item ** arguments= t_item->arguments();
> + Field * t_field;
> +
> + for (uint j=0; j < arg_count; j++)
> + {
> + DBUG_ASSERT(arguments[j]->type() == Item::FIELD_ITEM ||
> + arguments[j]->type() == Item::FUNC_ITEM);
> + if (arguments[j]->type() == Item::FIELD_ITEM)
> + {
> + t_field= static_cast<Item_field *>(arguments[j])->field;
> + }
> + else
> + {
> + Item_func_left *fnc= static_cast<Item_func_left *>(arguments[j]);
> + t_field= static_cast<Item_field *>(fnc->arguments()[0])->field;
> + }
> + if (!my_strcasecmp(system_charset_info, t_field->field_name.str, field_name))
> + return j;
> + }
> + return -1;
> +}
> +
> +/*
> + find total number of field in hash expr
> +*/
> +int fields_in_hash_keyinfo(KEY *keyinfo)
> +{
> + Item_func_hash * temp= (Item_func_hash *)
> + keyinfo->key_part->field->vcol_info->expr;
> + return temp->argument_count();
> +}
> +
> +void setup_keyinfo_hash(KEY *key_info)
> +{
> + uint no_of_keyparts= fields_in_hash_keyinfo(key_info);
> + key_info->key_part-= no_of_keyparts;
> + key_info->user_defined_key_parts= key_info->usable_key_parts=
> + key_info->ext_key_parts= no_of_keyparts;
add DBUG_ASSERT to make sure it's your HA_KEY_ALG_LONG_HASH
> +}
> +
> +void re_setup_keyinfo_hash(KEY *key_info)
> +{
> + while(!(key_info->key_part->field->flags & LONG_UNIQUE_HASH_FIELD))
> + key_info->key_part++;
> + key_info->user_defined_key_parts= key_info->usable_key_parts=
> + key_info->ext_key_parts= 1;
> +}
> +/**
> + @brief clone of current handler.
> + Creates a clone of handler used in update for
> + unique hash key.
> +*/
> +void TABLE::clone_handler_for_update()
> +{
> + handler *update_handler= NULL;
> + if (!s->long_unique_table)
> + return;
> + update_handler= file->clone(s->normalized_path.str,
> + in_use->mem_root);
> + update_handler->ha_external_lock(in_use, F_RDLCK);
> + this->update_handler= update_handler;
> + return;
> +}
> +
> +/**
> + @brief Deletes update handler object
> +*/
> +void TABLE::delete_update_handler()
> +{
> + update_handler->ha_external_lock(in_use, F_UNLCK);
> + update_handler->ha_close();
> + delete update_handler;
> + this->update_handler= NULL;
> +}
> +/**
> + @brief This function makes table object with
> + long unique keys ready for optimizer and alter table
Looks like a bad function name and a bad explanation.
I think - but not sure! - that it restores the original
UNIQUE definition, with columns as specified by the user.
Is that so?
> + @param table Table object
> + */
> +void TABLE::setup_table_hash()
> +{
> +
> + if (!this->s->long_unique_table)
> + return;
> + KEY *keyinfo= key_info;
> + for (uint i= 0; i < this->s->keys; i++, keyinfo++)
> + if (keyinfo->algorithm == HA_KEY_ALG_LONG_HASH)
> + setup_keyinfo_hash(keyinfo);
> +}
> +
> +/**
> + @brief Revert the effect of setup_table_hash
> + @param table Table Object
> + */
> +void TABLE::re_setup_table()
> +{
> + if (!s->long_unique_table)
> + return;
> + KEY *keyinfo= key_info;
> + for (uint i= 0; i < s->keys; i++, keyinfo++)
> + if (keyinfo->algorithm == HA_KEY_ALG_LONG_HASH)
> + re_setup_keyinfo_hash(keyinfo);
> +}
> +
> LEX_CSTRING *fk_option_name(enum_fk_option opt)
> {
> static LEX_CSTRING names[]=
> diff --git a/sql/table.h b/sql/table.h
> --- a/sql/table.h
> +++ b/sql/table.h
> @@ -1105,6 +1120,17 @@ struct TABLE
> THD *in_use; /* Which thread uses this */
>
> uchar *record[3]; /* Pointer to records */
> + /* record buf to resolve hash collisions for long UNIQUE constraints */
> + uchar *check_unique_buf;
> + handler *update_handler; /* Handler used in case of update */
> + /*
> + In the case of write row for long unique we are unable to find
> + which key is violated. Because we in case of duplicate hash we never reach
> + handler write_row function. So print_error will always print that
> + key 0 is violated. We store which key is violated in this variable
> + by default this should be initialized to -1
> + */
> + int dupp_hash_key;
couldn't you simply store it in table->file->errkey ?
> uchar *write_row_record; /* Used as optimisation in
> THD::write_row */
> uchar *insert_values; /* used by INSERT ... UPDATE */
> diff --git a/sql/table_cache.cc b/sql/table_cache.cc
> --- a/sql/table_cache.cc
> +++ b/sql/table_cache.cc
> @@ -822,13 +822,10 @@ TABLE_SHARE *tdc_acquire_share(THD *thd, TABLE_LIST *tl, uint flags,
>
> if (res == -1)
> DBUG_RETURN(0);
> - else if (res == 1)
> - continue;
Why?
>
> element= (TDC_element*) lf_hash_search_using_hash_value(&tdc_hash,
> thd->tdc_hash_pins, hash_value, (uchar*) key, key_length);
> lf_hash_search_unpin(thd->tdc_hash_pins);
> - DBUG_ASSERT(element);
>
> if (!(share= alloc_table_share(tl->db.str, tl->table_name.str, key, key_length)))
> {
> diff --git a/storage/myisam/myisamchk.c b/storage/myisam/myisamchk.c
> --- a/storage/myisam/myisamchk.c
> +++ b/storage/myisam/myisamchk.c
> @@ -1333,7 +1333,8 @@ static void descript(HA_CHECK *param, register MI_INFO *info, char * name)
> key++,keyinfo++)
> {
> keyseg=keyinfo->seg;
> - if (keyinfo->flag & HA_NOSAME) text="unique ";
> + if (keyinfo->flag & HA_NOSAME)
> + text="unique ";
I presume you can revert this change, looks like some left-over
from when you tried to make myisamchk to recognize your uniques
and then later reverted it.
> else if (keyinfo->flag & HA_FULLTEXT) text="fulltext ";
> else text="multip.";
>
>
Regards,
Sergei
Chief Architect MariaDB
and security(a)mariadb.org
2
2
Hello,
So, MDEV-16934 introduced eq_range_index_dives_limit into 10.2.8 and 10.3.0.
The default was set to 0 (which means no limit) in order to not introduce
optimizer behavior change into stable versions.
The question is: should 10.4 also have 0 by default or we can set it to some
finite limit? MySQL's default value is 10.
BR
Sergei
--
Sergei Petrunia, Software Developer
MariaDB Corporation | Skype: sergefp | Blog: http://s.petrunia.net/blog
3
2
Re: [Maria-developers] c39f74ce0d9: MDEV-16974 Application period tables: UPDATE
by Sergei Golubchik 05 Feb '19
by Sergei Golubchik 05 Feb '19
05 Feb '19
Hi, Nikita!
See comments below
On Jan 06, Nikita Malyavin wrote:
> revision-id: c39f74ce0d9 (versioning-1.0.7-4-gc39f74ce0d9)
> parent(s): fd18ed07d65
> author: Nikita Malyavin <nikitamalyavin(a)gmail.com>
> committer: Nikita Malyavin <nikitamalyavin(a)gmail.com>
> timestamp: 2018-12-03 13:19:18 +1000
> message:
>
> MDEV-16974 Application period tables: UPDATE
>
> diff --git a/mysql-test/suite/period/r/delete.result b/mysql-test/suite/period/r/delete.result
> index 30c9220d6f9..ccb8663bf72 100644
> --- a/mysql-test/suite/period/r/delete.result
> +++ b/mysql-test/suite/period/r/delete.result
> @@ -83,6 +83,9 @@ log
> <INS: 3, 1997-01-01, 2000-01-01
> >INS: 4, 2018-01-01, 2020-01-01
> <INS: 4, 2018-01-01, 2020-01-01
> +# multi-table DELETE is prohibited
> +delete t, t1 from t for portion of apptime from '2000-01-01' to '2018-01-01', t1;
> +ERROR HY000: PORTION OF time is not allowed here
why not ER_PARSE_ERROR?
> delete history from t2 for portion of apptime from '2000-01-01' to '2018-01-01';
> ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
> delete from t for portion of othertime from '2000-01-01' to '2018-01-01';
> diff --git a/mysql-test/suite/period/r/update.result b/mysql-test/suite/period/r/update.result
> new file mode 100644
> index 00000000000..1f59102c131
> --- /dev/null
> +++ b/mysql-test/suite/period/r/update.result
> @@ -0,0 +1,244 @@
> +create or replace table t (id int, s date, e date, period for apptime(s,e));
> +insert into t values(1, '1999-01-01', '2018-12-12');
> +insert into t values(1, '1999-01-01', '2017-01-01');
> +insert into t values(1, '2017-01-01', '2019-01-01');
> +insert into t values(2, '1998-01-01', '2018-12-12');
> +insert into t values(3, '1997-01-01', '2015-01-01');
> +insert into t values(4, '2016-01-01', '2020-01-01');
I'd insert also, say, (5, '2010-01-01', '2015-01-01').
> +create or replace table t1 (id int, s date, e date, period for apptime(s,e));
> +insert t1 select * from t;
> +create or replace table t2 (id int, s date, e date, period for apptime(s,e));
> +insert t2 select * from t;
> +update t for portion of apptime from '2000-01-01' to '2018-01-01'
> + set id=id + 5;
> +select * from t;
same comment about unsorted selects
> +id s e
> +6 2000-01-01 2018-01-01
> +6 2000-01-01 2017-01-01
> +6 2017-01-01 2018-01-01
> +7 2000-01-01 2018-01-01
> +8 2000-01-01 2015-01-01
> +9 2016-01-01 2018-01-01
> +1 1999-01-01 2000-01-01
> +1 2018-01-01 2018-12-12
> +1 1999-01-01 2000-01-01
> +1 2018-01-01 2019-01-01
> +2 1998-01-01 2000-01-01
> +2 2018-01-01 2018-12-12
> +3 1997-01-01 2000-01-01
> +4 2018-01-01 2020-01-01
> +# Check triggers
> +update t1 for portion of apptime from '2000-01-01' to '2018-01-01'
> + set id=id + 5;
> +select * from t1 order by id, s, e;
> +id s e
> +1 1999-01-01 2000-01-01
> +1 1999-01-01 2000-01-01
> +1 2018-01-01 2018-12-12
> +1 2018-01-01 2019-01-01
> +2 1998-01-01 2000-01-01
> +2 2018-01-01 2018-12-12
> +3 1997-01-01 2000-01-01
> +4 2018-01-01 2020-01-01
> +6 2000-01-01 2017-01-01
> +6 2000-01-01 2018-01-01
> +6 2017-01-01 2018-01-01
> +7 2000-01-01 2018-01-01
> +8 2000-01-01 2015-01-01
> +9 2016-01-01 2018-01-01
> +select * from log_tbl;
> +log
> +>UPD: 1, 1999-01-01, 2018-12-12 -> 6, 2000-01-01, 2018-01-01
> +<UPD: 1, 1999-01-01, 2018-12-12 -> 6, 2000-01-01, 2018-01-01
> +>INS: 1, 1999-01-01, 2000-01-01
> +<INS: 1, 1999-01-01, 2000-01-01
> +>INS: 1, 2018-01-01, 2018-12-12
> +<INS: 1, 2018-01-01, 2018-12-12
> +>UPD: 1, 1999-01-01, 2017-01-01 -> 6, 2000-01-01, 2017-01-01
> +<UPD: 1, 1999-01-01, 2017-01-01 -> 6, 2000-01-01, 2017-01-01
> +>INS: 1, 1999-01-01, 2000-01-01
> +<INS: 1, 1999-01-01, 2000-01-01
> +>UPD: 1, 2017-01-01, 2019-01-01 -> 6, 2017-01-01, 2018-01-01
> +<UPD: 1, 2017-01-01, 2019-01-01 -> 6, 2017-01-01, 2018-01-01
> +>INS: 1, 2018-01-01, 2019-01-01
> +<INS: 1, 2018-01-01, 2019-01-01
> +>UPD: 2, 1998-01-01, 2018-12-12 -> 7, 2000-01-01, 2018-01-01
> +<UPD: 2, 1998-01-01, 2018-12-12 -> 7, 2000-01-01, 2018-01-01
> +>INS: 2, 1998-01-01, 2000-01-01
> +<INS: 2, 1998-01-01, 2000-01-01
> +>INS: 2, 2018-01-01, 2018-12-12
> +<INS: 2, 2018-01-01, 2018-12-12
> +>UPD: 3, 1997-01-01, 2015-01-01 -> 8, 2000-01-01, 2015-01-01
> +<UPD: 3, 1997-01-01, 2015-01-01 -> 8, 2000-01-01, 2015-01-01
> +>INS: 3, 1997-01-01, 2000-01-01
> +<INS: 3, 1997-01-01, 2000-01-01
> +>UPD: 4, 2016-01-01, 2020-01-01 -> 9, 2016-01-01, 2018-01-01
> +<UPD: 4, 2016-01-01, 2020-01-01 -> 9, 2016-01-01, 2018-01-01
> +>INS: 4, 2018-01-01, 2020-01-01
> +<INS: 4, 2018-01-01, 2020-01-01
> +# INSERT trigger only also works
> +drop trigger tr1upd_t2;
> +drop trigger tr2upd_t2;
> +update t2 for portion of apptime from '2000-01-01' to '2018-01-01'
> + set id=id + 5;
> +select * from t2 order by id, s, e;
> +id s e
> +1 1999-01-01 2000-01-01
> +1 1999-01-01 2000-01-01
> +1 2018-01-01 2018-12-12
> +1 2018-01-01 2019-01-01
> +2 1998-01-01 2000-01-01
> +2 2018-01-01 2018-12-12
> +3 1997-01-01 2000-01-01
> +4 2018-01-01 2020-01-01
> +6 2000-01-01 2017-01-01
> +6 2000-01-01 2018-01-01
> +6 2017-01-01 2018-01-01
> +7 2000-01-01 2018-01-01
> +8 2000-01-01 2015-01-01
> +9 2016-01-01 2018-01-01
> +select * from log_tbl;
> +log
> +>INS: 1, 1999-01-01, 2000-01-01
> +<INS: 1, 1999-01-01, 2000-01-01
> +>INS: 1, 2018-01-01, 2018-12-12
> +<INS: 1, 2018-01-01, 2018-12-12
> +>INS: 1, 1999-01-01, 2000-01-01
> +<INS: 1, 1999-01-01, 2000-01-01
> +>INS: 1, 2018-01-01, 2019-01-01
> +<INS: 1, 2018-01-01, 2019-01-01
> +>INS: 2, 1998-01-01, 2000-01-01
> +<INS: 2, 1998-01-01, 2000-01-01
> +>INS: 2, 2018-01-01, 2018-12-12
> +<INS: 2, 2018-01-01, 2018-12-12
> +>INS: 3, 1997-01-01, 2000-01-01
> +<INS: 3, 1997-01-01, 2000-01-01
> +>INS: 4, 2018-01-01, 2020-01-01
> +<INS: 4, 2018-01-01, 2020-01-01
> +select * from t for portion of apptime from 0 to 1 for system_time all;
> +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
should be "right syntax to use near 'for portion of apptime from ...'"
> +update t for portion of apptime from 0 to 1 for system_time all set id=1;
> +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'set id=1' at line 1
why not "right syntax to use near 'for system_time all ...'" ?
> +# Modifying period start/end fields is forbidden.
> +# SQL17:
fix the reference, please
(SQL:2016, Part 2, section ... paragraph ...)
> +# Neither BSTARTCOL nor BENDCOL shall be an explicit <object column>
> +# contained in the <set clause list>.
> +update t for portion of apptime from '2000-01-01' to '2018-01-01'
> + set id= id + 5, s=subdate(s, 5), e=adddate(e, 5);
> +ERROR HY000: Column `s` used in period `apptime` specified in update SET list
> +# Precision timestamps
> +create or replace table t (id int, s timestamp(5), e timestamp(5),
> +period for apptime(s,e));
> +insert into t values(1, '1999-01-01', '2018-12-12');
> +insert into t values(1, '1999-01-01', '2017-01-01');
> +update t for portion of apptime from '2000-01-01 00:00:00.00015'
> + to '2018-01-01 12:34:56.31415'
> + set id= id + 5;
> +select * from t;
> +id s e
> +6 2000-01-01 00:00:00.00015 2018-01-01 12:34:56.31415
> +6 2000-01-01 00:00:00.00015 2017-01-01 00:00:00.00000
> +1 1999-01-01 00:00:00.00000 2000-01-01 00:00:00.00015
> +1 2018-01-01 12:34:56.31415 2018-12-12 00:00:00.00000
> +1 1999-01-01 00:00:00.00000 2000-01-01 00:00:00.00015
> +# Strings
> +create or replace table t (id int, str text, s date, e date,
> +period for apptime(s,e));
> +insert into t values(1, 'data', '1999-01-01', '2018-12-12');
> +insert into t values(1, 'other data', '1999-01-01', '2018-12-12');
> +update t for portion of apptime from '2000-01-01' to '2018-01-01'
> + set id= id + 5;
> +select * from t;
> +id str s e
> +6 data 2000-01-01 2018-01-01
> +6 other data 2000-01-01 2018-01-01
> +1 data 1999-01-01 2000-01-01
> +1 data 2018-01-01 2018-12-12
> +1 other data 1999-01-01 2000-01-01
> +1 other data 2018-01-01 2018-12-12
> +# multi-table UPDATE is prohibited
> +create or replace table t1(x int);
> +update t for portion of apptime from '2000-01-01' to '2018-01-01', t1
> +set t.id= t.id + 5;
> +ERROR HY000: PORTION OF time is not allowed here
why not ER_PARSE_ERROR?
> +update t1 set x= (select id from t for portion of apptime from '2000-01-01' to '2018-01-01');
> +ERROR HY000: PORTION OF time is not allowed here
why not ER_PARSE_ERROR?
> +# SQL17:
fix the reference, please
> +# Let FROMVAL be <point in time 1>. FROMVAL shall not generally contain a
> +# reference to a column of T or a <routine invocation>
> +# whose subject routine is an SQL-invoked routine that
> +# is possibly non-deterministic or that possibly modifies SQL-data.
> +# ...Same for <point in time 2> (TOVAL)
> +update t for portion of apptime from 5*(5+s) to 1 set t.id= t.id + 5;
> +ERROR HY000: Values in range FOR PORTION OF `apptime` should be constant expressions
> +update t for portion of apptime from 1 to e set t.id= t.id + 5;
> +ERROR HY000: Values in range FOR PORTION OF `apptime` should be constant expressions
> +set @s= '2000-01-01';
> +set @e= '2018-01-01';
> +create or replace function f() returns date return @e;
> +create or replace function g() returns date not deterministic return @e;
> +create or replace function h() returns date deterministic return @e;
> +update t for portion of apptime from @s to f() set t.id= t.id + 5;
> +ERROR HY000: Values in range FOR PORTION OF `apptime` should be constant expressions
> +update t for portion of apptime from @s to g() set t.id= t.id + 5;
> +ERROR HY000: Values in range FOR PORTION OF `apptime` should be constant expressions
> +# success
> +update t for portion of apptime from @s to h() set t.id= t.id + 5;
> +# select value is cached
> +update t for portion of apptime from (select s from t2 limit 1) to h() set t.id= t.id + 5;
> +# auto_inrement field is updated
> +create or replace table t (id int primary key auto_increment, x int,
> +s date, e date, period for apptime(s, e));
> +insert into t values (default, 1, '1999-01-01', '2018-12-12');
> +update t for portion of apptime from '2000-01-01' to '2018-01-01' set x= x + 5;
> +select * from t;
> +id x s e
> +1 6 2000-01-01 2018-01-01
> +2 1 1999-01-01 2000-01-01
> +3 1 2018-01-01 2018-12-12
> +truncate t;
> +insert into t values (default, 1, '1999-01-01', '2018-12-12');
> +update t for portion of apptime from '2000-01-01' to '2018-01-01' set x= 1;
> +select * from t;
> +id x s e
> +1 1 2000-01-01 2018-01-01
> +2 1 1999-01-01 2000-01-01
> +3 1 2018-01-01 2018-12-12
> +# generated columns are updated
> +create or replace table t (x int, s date, e date,
> +xs date as (s) stored, xe date as (e) stored,
> +period for apptime(s, e));
> +insert into t values(1, '1999-01-01', '2018-12-12', default, default);
> +select * from t;
> +x s e xs xe
> +1 1999-01-01 2018-12-12 1999-01-01 2018-12-12
> +update t for portion of apptime from '2000-01-01' to '2018-01-01' set x= x + 5;
> +select *, xs=s and xe=e from t;
> +x s e xs xe xs=s and xe=e
> +6 2000-01-01 2018-01-01 2000-01-01 2018-01-01 1
> +1 1999-01-01 2000-01-01 1999-01-01 2000-01-01 1
> +1 2018-01-01 2018-12-12 2018-01-01 2018-12-12 1
> +# system_time columns are updated
> +create or replace table t (x int, s date, e date,
> +row_start SYS_TYPE as row start invisible,
> +row_end SYS_TYPE as row end invisible,
a bit strange to use invisible in tests for strict standard compliance :)
but ok, whatever
> +period for apptime(s, e),
> +period for system_time(row_start, row_end)) with system versioning;
> +insert into t values(1, '1999-01-01', '2018-12-12'),
> +(2, '1999-01-01', '1999-12-12');
> +select row_start into @ins_time from t limit 1;
> +select * from t order by x, s, e;
> +x s e
> +1 1999-01-01 2018-12-12
> +2 1999-01-01 1999-12-12
> +update t for portion of apptime from '2000-01-01' to '2018-01-01' set x= x + 5;
> +select *, if(row_start = @ins_time, "OLD", "NEW"), check_row(row_start, row_end)
> +from t for system_time all
> +order by x, s, e, row_start;
> +x s e if(row_start = @ins_time, "OLD", "NEW") check_row(row_start, row_end)
> +1 1999-01-01 2000-01-01 NEW CURRENT ROW
> +1 1999-01-01 2018-12-12 OLD HISTORICAL ROW
> +1 2018-01-01 2018-12-12 NEW CURRENT ROW
> +2 1999-01-01 1999-12-12 OLD CURRENT ROW
> +6 2000-01-01 2018-01-01 NEW CURRENT ROW
> +create or replace database test;
> diff --git a/mysql-test/suite/period/t/delete.test b/mysql-test/suite/period/t/delete.test
> index b34de6c37e7..39a68959523 100644
> --- a/mysql-test/suite/period/t/delete.test
> +++ b/mysql-test/suite/period/t/delete.test
> @@ -34,6 +34,10 @@ drop trigger tr2del_t2;
> delete from t2 for portion of APPTIME from '2000-01-01' to '2018-01-01';
> select * from log_tbl;
>
> +--echo # multi-table DELETE is prohibited
> +--error ER_PORTION_OF_TIME_NOT_ALLOWED
> +delete t, t1 from t for portion of apptime from '2000-01-01' to '2018-01-01', t1;
move this into your MDEV-16973 commit is possible, please,
> +
> --error ER_PARSE_ERROR
> delete history from t2 for portion of apptime from '2000-01-01' to '2018-01-01';
>
> diff --git a/mysql-test/suite/period/t/update.opt b/mysql-test/suite/period/t/update.opt
> new file mode 100644
> index 00000000000..92a881bef67
> --- /dev/null
> +++ b/mysql-test/suite/period/t/update.opt
> @@ -0,0 +1 @@
> +--explicit_defaults_for_timestamp
Why?
it's best to avoid non-default command line options, unless you actually
test this particular option. If you just need it for convenience - don't.
every non-default command line options means a server restart, and they're slow.
write DEFAULT NULL explicitly when needed.
> diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
> index 7ceff1a215e..c5a359b09e8 100644
> --- a/sql/share/errmsg-utf8.txt
> +++ b/sql/share/errmsg-utf8.txt
> @@ -7951,3 +7951,12 @@ ER_PERIOD_NOT_FOUND
>
> ER_PERIOD_SYSTEM_TIME_NOT_ALLOWED
> eng "period SYSTEM_TIME is not allowed here"
> +
> +ER_PORTION_OF_TIME_NOT_ALLOWED
> + eng "PORTION OF time is not allowed here"
> +
> +ER_PERIOD_PORTION_OF_TIME_CONSTANT
> + eng "Values in range FOR PORTION OF %`s should be constant expressions"
Reuse ER_NO_CONST_EXPR_IN_RANGE_OR_LIST_ERROR please. Like
ER_NO_CONST_EXPR_IN_RANGE_OR_LIST_ERROR -> ER_NOT_CONSTANT_EXPRESSION
eng "Expression in RANGE/LIST VALUES must be constant" ->
eng "Expression in %s must be constant"
and in mysql.h
#define ER_NO_CONST_EXPR_IN_RANGE_OR_LIST_ERROR ER_NOT_CONSTANT_EXPRESSION
> +
> +ER_PERIOD_COLUMNS_UPDATED
> + eng "Column %`s used in period %`s specified in update SET list"
> diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
> index 7a18ac82236..93d2f417a50 100644
> --- a/sql/sql_lex.cc
> +++ b/sql/sql_lex.cc
> @@ -1343,13 +1343,16 @@ int Lex_input_stream::lex_token(YYSTYPE *yylval, THD *thd)
> /*
> * Additional look-ahead to resolve doubtful cases like:
> * SELECT ... FOR UPDATE
> - * SELECT ... FOR SYSTEM_TIME ... .
> + * SELECT ... FOR SYSTEM_TIME ...
> + * SELECT ... FOR PORTION OF ... .
Can you show an example of the statement where you need a second look-ahead
to distinguish between FOR PORTION OF and FOR SYSTEM_TIME or FOR UPDATE ?
> */
> token= lex_one_token(yylval, thd);
> add_digest_token(token, yylval);
> switch(token) {
> case SYSTEM_TIME_SYM:
> return FOR_SYSTEM_TIME_SYM;
> + case PORTION:
> + return FOR_PORTION_SYM;
> default:
> /*
> Save the token following 'FOR_SYM'
> diff --git a/sql/sql_base.cc b/sql/sql_base.cc
> index 220fcf6cc34..44989b20fae 100644
> --- a/sql/sql_base.cc
> +++ b/sql/sql_base.cc
> @@ -8121,6 +8121,12 @@ int setup_conds(THD *thd, TABLE_LIST *tables, List<TABLE_LIST> &leaves,
>
> for (table= tables; table; table= table->next_local)
> {
> + if (table->has_period() && !thd->lex->portion_of_time_applicable())
> + {
> + my_error(ER_PORTION_OF_TIME_NOT_ALLOWED, MYF(0));
> + goto err_no_arena;
> + }
I don't understand that either, why do you need to check the correct syntax
in setup_conds() ?
> +
> if (select_lex == thd->lex->first_select_lex() &&
> select_lex->first_cond_optimization &&
> table->merged_for_insert &&
> diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
> index e76eb729536..4726557d762 100644
> --- a/sql/sql_delete.cc
> +++ b/sql/sql_delete.cc
> @@ -752,6 +752,10 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
> delete_record= true;
> }
>
> + /* SQL standard defines DELETE FOR PORTTION OF time as 0-2 INSERTS + DELETE
> + * We can substitute INSERT+DELETE with one UPDATE, but only if there are
> + * no triggers set. It is also meaningless for system-versioned table
> + */
1. format multi-line comments like everywhere in the code, please
2. every time you refer to the standard, say where the standard says that
3. move this comment in your MDEV-16973 commit, if possible
> portion_of_time_through_update= !has_period_triggers
> && !table->versioned(VERS_TIMESTAMP);
>
> diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
> index 0c368b40836..10535326ce5 100644
> --- a/sql/sql_yacc.yy
> +++ b/sql/sql_yacc.yy
> @@ -11910,12 +11911,13 @@ join_table_parens:
>
>
> table_primary_ident:
> - table_ident opt_use_partition opt_for_system_time_clause
> + table_ident opt_use_partition
> + opt_for_portion_of_time_clause opt_for_system_time_clause
Oh, no. FOR PORTION OF has very few well defined places where the standard
allows it. Don't put it into the generic used-everywhere table_primary_ident.
That's why you needed FOR_PORTION_SYM and a second look-ahead.
> opt_table_alias_clause opt_key_definition
> {
> SELECT_LEX *sel= Select;
> sel->table_join_options= 0;
> - if (!($$= Select->add_table_to_list(thd, $1, $4,
> + if (!($$= Select->add_table_to_list(thd, $1, $5,
> Select->get_table_join_options(),
> YYPS->m_lock_type,
> YYPS->m_mdl_type,
> diff --git a/sql/table.h b/sql/table.h
> index 1b897c1b4c6..f104f4fc99c 100644
> --- a/sql/table.h
> +++ b/sql/table.h
> @@ -2420,7 +2423,7 @@ struct TABLE_LIST
>
> bool has_period() const
> {
> - return period_conditions.name;
> + return period_conditions.is_set();
why?
> }
>
> /**
>
> diff --git a/sql/table.cc b/sql/table.cc
> index 8f1c94dd633..93908a9e2e3 100644
> --- a/sql/table.cc
> +++ b/sql/table.cc
> @@ -6456,7 +6456,7 @@ void TABLE::mark_columns_needed_for_delete(bool with_period)
> retrieve the row again.
> */
>
> -void TABLE::mark_columns_needed_for_update()
> +void TABLE::mark_columns_needed_for_update(bool with_period)
just like in the delete case, I think this is the caller's problem
> {
> DBUG_ENTER("TABLE::mark_columns_needed_for_update");
> bool need_signal= false;
> @@ -7870,19 +7871,41 @@ static int period_make_insert(TABLE *table, Item *src, Field *dst)
> }
>
> +int TABLE::cut_fields_for_portion_of_time(THD *thd, const vers_select_conds_t &period_conds)
looks like something that belongs to sql_update.cc, not TABLE
> +{
> + bool lcond= period_conds.field_start->val_datetime_packed(thd)
> + < period_conds.start.item->val_datetime_packed(thd);
> + bool rcond= period_conds.field_end->val_datetime_packed(thd)
> + > period_conds.end.item->val_datetime_packed(thd);
> +
> + Field *start_field= field[s->period.start_fieldno];
> + Field *end_field= field[s->period.end_fieldno];
> +
> + int res= 0;
> + if (lcond && !start_field->has_explicit_value())
> + res= period_conds.start.item->save_in_field(start_field, true);
> +
> + if (likely(!res) && rcond && !end_field->has_explicit_value())
> + res= period_conds.end.item->save_in_field(end_field, true);
> +
> + return res;
> +}
> +
> -int TABLE::update_portion_of_time(THD *thd, vers_select_conds_t &period_conds,
> +int TABLE::update_portion_of_time(THD *thd, const vers_select_conds_t &period_conds,
> bool *inside_period)
looks like something that belongs to sql_delete.cc, not TABLE
> {
> bool lcond= period_conds.field_start->val_datetime_packed(thd)
> @@ -7917,7 +7940,8 @@ int TABLE::update_portion_of_time(THD *thd, vers_select_conds_t &period_conds,
> return res;
> }
>
> -int TABLE::insert_portion_of_time(THD *thd, vers_select_conds_t &period_conds)
> +int TABLE::insert_portion_of_time(THD *thd, const vers_select_conds_t &period_conds,
> + ha_rows &rows_inserted)
pointers or _constant_ references. Here, rows_inserted must be a pointer.
> {
> bool lcond= period_conds.field_start->val_datetime_packed(thd)
> < period_conds.start.item->val_datetime_packed(thd);
> diff --git a/sql/sql_update.cc b/sql/sql_update.cc
> index 27bd6f04670..d5240f5524e 100644
> --- a/sql/sql_update.cc
> +++ b/sql/sql_update.cc
> @@ -177,6 +178,21 @@ static bool check_fields(THD *thd, List<Item> &items, bool update_view)
> f->set_has_explicit_value();
> }
> }
> +
> + if (thd->lex->sql_command == SQLCOM_UPDATE && table->has_period())
what else can sql_command be here? SQLCOM_UPDATE_MULTI?
SQLCOM_UPDATE_MULTI cannot have table->has_period().
> + {
> + for (List_iterator_fast<Item> it(items); (item=it++);)
> + {
> + Lex_ident name(item->name);
> + vers_select_conds_t &period= table->period_conditions;
> + if (name.streq(period.field_start->name)
> + || name.streq(period.field_end->name))
Don't compare names, compare fields.
The field to be updated is, I guess, item->field_for_view_update()->field
> + {
> + my_error(ER_PERIOD_COLUMNS_UPDATED, MYF(0), name.str, period.name.str);
> + return true;
> + }
> + }
> + }
> return FALSE;
> }
>
> @@ -323,6 +339,7 @@ int mysql_update(THD *thd,
> List<Item> all_fields;
> killed_state killed_status= NOT_KILLED;
> bool has_triggers, binlog_is_row, do_direct_update= FALSE;
> + bool has_period_triggers= false;
same as for sql_delete.cc, one has_triggers is enough, second has_period_triggers
is quite confusing.
> Update_plan query_plan(thd->mem_root);
> Explain_update *explain;
> TABLE_LIST *update_source_table;
> @@ -880,14 +905,25 @@ int mysql_update(THD *thd,
> explain->tracker.on_record_after_where();
> store_record(table,record[1]);
>
> + if (table_list->has_period())
> + table->cut_fields_for_portion_of_time(thd, table_list->period_conditions);
1. this should be done after BEFORE triggers
(see SQL:2016, part 2, 15.13 "Effect of replacing rows in base tables")
2. why in cut_fields_for_portion_of_time() you check for has_explicit_value()?
fields cannot have explicit values there, you've checked that in check_fields().
> +
> if (fill_record_n_invoke_before_triggers(thd, table, fields, values, 0,
> TRG_EVENT_UPDATE))
> break; /* purecov: inspected */
>
> found++;
>
> - if (!can_compare_record || compare_record(table))
> + bool record_was_same= false;
> + bool need_update= !can_compare_record || compare_record(table) ||
> + thd->lex->sql_command == SQLCOM_DELETE;
why sql_command would be SQLCOM_DELETE here?
> +
> + if (need_update)
> {
> + if (table->versioned(VERS_TIMESTAMP) &&
> + thd->lex->sql_command == SQLCOM_DELETE)
> + table->vers_update_end();
> +
> if (table->default_field && table->update_default_fields(1, ignore))
> {
> error= 1;
> @@ -994,6 +1032,13 @@ int mysql_update(THD *thd,
> break;
> }
>
> + if (need_update && !record_was_same && table_list->has_period())
I suspect this should happen even if record_was_same. The standard never says
"if new values are the same as old values, don't update anything"
> + {
> + restore_record(table, record[1]);
> + table->insert_portion_of_time(thd, table_list->period_conditions,
> + rows_inserted);
> + }
> +
> if (!--limit && using_limit)
> {
> /*
Regards,
Sergei
Chief Architect MariaDB
and security(a)mariadb.org
2
4
Re: [Maria-developers] 83444b747f1: MDEV-16975 Application period tables: ALTER TABLE
by Sergei Golubchik 05 Feb '19
by Sergei Golubchik 05 Feb '19
05 Feb '19
Hi, Nikita!
Please, see my comments below
On Dec 28, Nikita Malyavin wrote:
> revision-id: 83444b747f1 (versioning-1.0.7-5-g83444b747f1)
> parent(s): c39f74ce0d9
> author: Nikita Malyavin <nikitamalyavin(a)gmail.com>
> committer: Nikita Malyavin <nikitamalyavin(a)gmail.com>
> timestamp: 2018-12-03 13:19:18 +1000
> message:
>
> MDEV-16975 Application period tables: ALTER TABLE
>
> * implicit period constraint is hidden and cannot be dropped independently
> * create...like and create...select support
>
> diff --git a/mysql-test/suite/period/r/alter.result b/mysql-test/suite/period/r/alter.result
> new file mode 100644
> index 00000000000..6bb9f905358
> --- /dev/null
> +++ b/mysql-test/suite/period/r/alter.result
> @@ -0,0 +1,101 @@
> +set @s= '1992-01-01';
> +set @e= '1999-12-31';
> +create or replace table t (s date, e date);
> +alter table t add period for a(s, e);
> +ERROR HY000: Period field `s` cannot be NULL
> +alter table t change s s date, add period for a(s, e);
> +ERROR HY000: Period field `s` cannot be NULL
> +alter table t change s s date, change e e date, add period for a(s, e);
> +ERROR HY000: Period field `s` cannot be NULL
> +alter table t change s s date not null, change e e date not null,
> +add period for a(s, e);
> +show create table t;
> +Table Create Table
> +t CREATE TABLE `t` (
> + `s` date NOT NULL,
> + `e` date NOT NULL,
> + PERIOD FOR `a` (`s`, `e`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +alter table t add id int;
> +alter table t drop id;
> +insert t values(@e, @s);
> +ERROR 23000: CONSTRAINT `CONSTRAINT_1` failed for `test`.`t`
Hmm. The standard, indeed, says "there's an implicit constraint".
But it does not say "CHECK contraint". UNIQUE is also a constraint,
Foreign key is also a constraint.
So, I think here it means really just *a* constraint (a limitation, in
other words), meaning only that start value must be before the end
value. It doesn't mean that a CHECK constraint must be created.
In other words, it should not be a CHECK constraint, it should not
produce a `CONSTRAINT xxx failed` message, and, of course, it should
never ever be shown as a CHECK constraint.
> +alter table t drop constraint constraint_1;
> +ERROR HY000: Can't DROP CONSTRAINT `CONSTRAINT_1`. Use DROP PERIOD `a` for this
> +alter table t drop period for a;
> +# Constraint is dropped
> +insert t values(@e, @s);
> +alter table t drop period for a;
> +ERROR 42000: Can't DROP PERIOD `a`; check that it exists
> +alter table t add period for a(s, e), drop period for a;
> +ERROR 42000: Can't DROP PERIOD `a`; check that it exists
> +truncate t;
> +alter table t add period for a(s, e);
> +insert t values(@e, @s);
> +ERROR 23000: CONSTRAINT `CONSTRAINT_1` failed for `test`.`t`
> +alter table t add period for a(s, e), drop period for a;
> +insert t values(@e, @s);
> +ERROR 23000: CONSTRAINT `CONSTRAINT_1` failed for `test`.`t`
> +alter table t add s1 date not null, add period for b(s1, e), drop period for a;
> +show create table t;
> +Table Create Table
> +t CREATE TABLE `t` (
> + `s` date NOT NULL,
> + `e` date NOT NULL,
> + `s1` date NOT NULL,
> + PERIOD FOR `b` (`s1`, `e`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +insert t(s, s1, e) values(@e, @s, @e);
> +insert t(s, s1, e) values(@e, @e, @s);
> +ERROR 23000: CONSTRAINT `CONSTRAINT_1` failed for `test`.`t`
> +alter table t add constraint check (s < s1 and s1 < e);
> +ERROR HY000: CONSTRAINT `(null)` uses fields from PERIOD `b`
huh?
looks like a null-pointer dereference with a defensive crash-safe printf.
and why is it an error?
> +create table t1 like t;
> +show create table t1;
> +Table Create Table
> +t1 CREATE TABLE `t1` (
> + `s` date NOT NULL,
> + `e` date NOT NULL,
> + `s1` date NOT NULL,
> + PERIOD FOR `b` (`s1`, `e`)
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +create table t2 (period for b(s,e)) select * from t;
> +ERROR 23000: CONSTRAINT `CONSTRAINT_1` failed for `test`.`t2`
> +create table t2 (period for b(s1,e)) select * from t;
> +# SQL17 p.895
please, fix all the references to the standard to mention the part
number, section number and paragraph number instead of the page number.
> +# The declared type of BC1 shall be either DATE or a timestamp type
> +# and shall be equivalent to the declared type of BC2.
> +create or replace table t (s timestamp not null, e timestamp(6) not null);
> +alter table t add period for a(s, e);
> +ERROR HY000: PERIOD FOR `a` fields types mismatch
> +# SQL17 p.895
> +# No column of T shall have a column name that is equivalent to ATPN.
> +create or replace table t (a int, s date, e date);
> +alter table t add period for a(s, e);
> +ERROR HY000: Period and field `a` cannot have same name.
> +# SQL17 p.895
> +# Neither BC1 nor BC2 shall be an identity column, a generated column,
> +# a system-time period start column, or a system-time period end column.
> +create or replace table t (id int primary key,
> +s date,
> +e date generated always as (s+1));
> +alter table t add period for a(s, e);
> +ERROR HY000: Period field `s` cannot be NULL
> +create or replace table t (id int primary key,
> +s date,
> +e date as (s+1) VIRTUAL);
> +alter table t add period for a(s, e);
> +ERROR HY000: Period field `s` cannot be NULL
> +create or replace table t (id int primary key, s timestamp(6), e timestamp(6),
> +st timestamp(6) as row start,
> +en timestamp(6) as row end,
> +period for system_time (st, en)) with system versioning;
> +alter table t add period for a(s, en);
> +ERROR HY000: Period field `en` cannot be ROW END
> +# SQL17 p.895
> +# The table descriptor of T shall not include a period descriptor other
> +# than a system-time period descriptor.
> +alter table t add period for a(s, e);
> +alter table t add period for b(s, e);
> +ERROR HY000: cannot specify more than one application-time period
> +create or replace database test;
> diff --git a/mysql-test/suite/period/r/create.result b/mysql-test/suite/period/r/create.result
> index 420eceb2e9a..8c06a0cc134 100644
> --- a/mysql-test/suite/period/r/create.result
> +++ b/mysql-test/suite/period/r/create.result
> @@ -51,7 +51,7 @@ ERROR HY000: cannot specify more than one application-time period
> # No <column name> in any <column definition> shall be equivalent to PN.
> create or replace table t (mytime int, s date, e date,
> period for mytime(s,e));
> -ERROR HY000: Could not specify name `mytime` for field. It is already used by period.
> +ERROR HY000: Period and field `mytime` cannot have same name.
This is better. Although I'd just use an existing ER_DUP_FIELDNAME
> # CD1 and CD2 both contain either an explicit or an implicit
> # <column constraint definition> that specifies
> # NOT NULL NOT DEFERRABLE ENFORCED.
> diff --git a/sql/field.cc b/sql/field.cc
> index d7214687e2d..e065d61e3a5 100644
> --- a/sql/field.cc
> +++ b/sql/field.cc
> @@ -10545,6 +10545,8 @@ Column_definition::Column_definition(THD *thd, Field *old_field,
> unireg_check= Field::TMYSQL_COMPRESSED;
> compression_method_ptr= zlib_compression_method;
> }
> + if (orig_field->maybe_null())
> + flags|= EXPLICIT_NULL_FLAG;
This shouldn't be needed, as I wrote in a CREATE TABLE review,
NOT NULL should be implicit, not an error.
> }
> else
> {
> diff --git a/sql/sql_alter.h b/sql/sql_alter.h
> index 108b98afdd7..d917793dd90 100644
> --- a/sql/sql_alter.h
> +++ b/sql/sql_alter.h
> @@ -95,6 +95,8 @@ class Alter_info
> CHECK_CONSTRAINT_IF_NOT_EXISTS= 1
> };
> List<Virtual_column_info> check_constraint_list;
> + List<Table_period_info> period_list;
looks unused (in this patch, at least)
> +
> // Type of ALTER TABLE operation.
> alter_table_operations flags;
> ulong partition_flags;
> diff --git a/sql/sql_table.cc b/sql/sql_table.cc
> index 4189131f801..211969647d4 100644
> --- a/sql/sql_table.cc
> +++ b/sql/sql_table.cc
> @@ -6152,6 +6152,11 @@ handle_if_exists_options(THD *thd, TABLE *table, Alter_info *alter_info)
> }
> }
> }
> + else if (drop->type == Alter_drop::PERIOD)
> + {
> + if (table->s->period.name.streq(drop->name))
> + remove_drop= FALSE;
you don't seem to have a single test for DROP PERIOD IF EXISTS
> + }
> else /* Alter_drop::KEY and Alter_drop::FOREIGN_KEY */
> {
> uint n_key;
> @@ -8406,6 +8412,34 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
> }
> }
>
> + if (table->s->period.name)
> + {
> + drop_it.rewind();
> + Alter_drop *drop;
> + for (bool found= false; !found && (drop= drop_it++); )
> + {
> + found= table->s->period.name.streq(drop->name);
> + }
> +
> + if (drop)
> + {
> + drop_period= true;
> + drop_it.remove();
> + }
> + else if (create_info->period_info.is_set() && table->s->period.name)
> + {
> + my_error(ER_PERIOD_MAX_COUNT_EXCEEDED, MYF(0), "application");
> + goto err;
> + }
> + else
> + {
> + Field *s= table->s->period.start_field(table->s);
> + Field *e= table->s->period.end_field(table->s);
> + create_info->period_info.set_period(s->field_name, e->field_name);
> + create_info->period_info.name= table->s->period.name;
why couldn't you remember Field's, why only names?
is it because period_info is also used on CREATE TABLE and you don't
have Field's there?
> + }
> + }
> +
> /* Add all table level constraints which are not in the drop list */
> if (table->s->table_check_constraints)
> {
> diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
> index 10535326ce5..545c8f831b9 100644
> --- a/sql/sql_yacc.yy
> +++ b/sql/sql_yacc.yy
> @@ -8190,6 +8195,10 @@ alter_list_item:
> {
> Lex->alter_info.flags|= ALTER_ADD_PERIOD;
> }
> + | ADD period_for_application_time
where's ADD PERIOD if_not_exists?
> + {
> + Lex->alter_info.flags|= ALTER_ADD_CHECK_CONSTRAINT;
> + }
> | add_column '(' create_field_list ')'
> {
> LEX *lex=Lex;
Regards,
Sergei
Chief Architect MariaDB
and security(a)mariadb.org
2
3