Hi everyone, it seems there's a very "weird" and dangerous regression in mysql 10.4.6...
So basically for it to work you need myisam table with UNIQUE KEY ... USING HASH. I was reading in docs it doesn't make a difference, but when used in newest maria it'll make the table behave very strangely, so you can NOT do INSERT INTO with > 100 rows at once.
So this code will produce [Err] 1032 - Can't find record in '_hits'
To make it work correctly again you can do just one of the following:
Change engine to innodb or memory
Remove ANY dataset from insert so it'll do 99 items correctly
Change key, remove "USING HASH"
Change key, remove "UNIQUE"
When you change the engine to aria it exhibits same behaviour as myisam, but it gives different error: [Err] 1904 - Key/Index cannot be defined on a virtual generated column
(and works correctly for USING BTREE)
It works totally fine in older versions eg. Maria 10.2.9, 10.1.22 etc. I was trying to find somethig related to this and found some report with same bug related to replication. I don't remember the URL and details, it wasn't resolved... so i think it could also be breaking statement based replication and it's probably hard to diagnose.
Most strange thing is that HASH indexes shouldn't even be supported by myisam so it should work like default b-tree index, so in fact it should make no difference if USING HASH is there or not, right?
Thanks a lot for the report! I repeated as described on MariaDB 10.4:
MariaDB [test]> CREATE TABLE `t2` (
-> `creative_id` int(11) NOT NULL,
-> `ip` varchar(15) NOT NULL,
-> `date` date NOT NULL,
-> UNIQUE KEY (`creative_id`,`date`,`ip`) USING HASH
-> ) ENGINE=myisam;
Query OK, 0 rows affected (0.021 sec)
MariaDB [test]> INSERT INTO `t2` select seq, CONCAT(seq,'1.1',seq), '2018-01-01' from seq_1_to_100;
ERROR 1032 (HY000): Can't find record in 't2'
MariaDB [test]> CREATE TABLE `t3` (
-> `creative_id` int(11) NOT NULL,
-> `ip` varchar(15) NOT NULL,
-> `date` date NOT NULL,
-> UNIQUE KEY (`creative_id`,`date`,`ip`) USING HASH
-> ) ENGINE=aria;
ERROR 1904 (HY000): Key/Index cannot be defined on a virtual generated column
Alice Sherepa
added a comment - Thanks a lot for the report! I repeated as described on MariaDB 10.4:
MariaDB [test]> CREATE TABLE `t2` (
-> `creative_id` int(11) NOT NULL,
-> `ip` varchar(15) NOT NULL,
-> `date` date NOT NULL,
-> UNIQUE KEY (`creative_id`,`date`,`ip`) USING HASH
-> ) ENGINE=myisam;
Query OK, 0 rows affected (0.021 sec)
MariaDB [test]> INSERT INTO `t2` select seq, CONCAT(seq,'1.1',seq), '2018-01-01' from seq_1_to_100;
ERROR 1032 (HY000): Can't find record in 't2'
MariaDB [test]> CREATE TABLE `t3` (
-> `creative_id` int(11) NOT NULL,
-> `ip` varchar(15) NOT NULL,
-> `date` date NOT NULL,
-> UNIQUE KEY (`creative_id`,`date`,`ip`) USING HASH
-> ) ENGINE=aria;
ERROR 1904 (HY000): Key/Index cannot be defined on a virtual generated column
It fails on first insert itself, Even this also fails
create table t1(a int, unique(a) using hash);
--let $count=99
--let insert_stmt= insert into t1 values(1)
while ($count)
{
--let $insert_stmt=$insert_stmt,(1)
--dec $count
}
--eval $insert_stmt
drop table t1;
Sachin Setiya (Inactive)
added a comment - It fails on first insert itself, Even this also fails
create table t1(a int, unique(a) using hash);
--let $count=99
--let insert_stmt= insert into t1 values(1)
while ($count)
{
--let $insert_stmt=$insert_stmt,(1)
--dec $count
}
--eval $insert_stmt
drop table t1;
Sachin Setiya (Inactive)
added a comment - I think something is going on in myisam
Case when insert is less then 100
#0 handler::ha_write_row (this=0x7fffe01524c0, buf=0x7fffe00124a0 "\371\001") at /home/sachin/10.4/server/sql/handler.cc:6664
6664 Log_func *log_func= Write_rows_log_event::binlog_row_logging_function;
(gdb) p table->file->file->s->state->key_map
$3 = 1
Case when insert is >= 100
Thread 6 "mysqld" hit Breakpoint 1, handler::ha_write_row (this=0x7fffe008c300, buf=0x7fffe01a0890 "\371\001") at /home/sachin/10.4/server/sql/handler.cc:6664
6664 Log_func *log_func= Write_rows_log_event::binlog_row_logging_function;
(gdb) p table->file->file->s->state->key_map
$1 = 0
It does not work in earlier version , before 10.4 we did not had hash index for innodb and myisam
So hash index was converted to btree, without user knowledge
Thanks a lot for the report! I repeated as described on MariaDB 10.4:
MariaDB [test]> CREATE TABLE `t2` (
-> `creative_id` int(11) NOT NULL,
-> `ip` varchar(15) NOT NULL,
-> `date` date NOT NULL,
-> UNIQUE KEY (`creative_id`,`date`,`ip`) USING HASH
-> ) ENGINE=myisam;
Query OK, 0 rows affected (0.021 sec)
MariaDB [test]> INSERT INTO `t2` select seq, CONCAT(seq,'1.1',seq), '2018-01-01' from seq_1_to_100;
ERROR 1032 (HY000): Can't find record in 't2'
MariaDB [test]> CREATE TABLE `t3` (
-> `creative_id` int(11) NOT NULL,
-> `ip` varchar(15) NOT NULL,
-> `date` date NOT NULL,
-> UNIQUE KEY (`creative_id`,`date`,`ip`) USING HASH
-> ) ENGINE=aria;
ERROR 1904 (HY000): Key/Index cannot be defined on a virtual generated column