Commit 3d67c68a authored by Michael Widenius's avatar Michael Widenius Committed by Sergei Golubchik

Fixed MDEV-4970: Wrong result with Aria table populated with disabled keys

Problem was that ALTER TABLE DISABLE KEYS incremented create_trid for the table,
which made the new index entries invisible until the global trid catched up.

Fixed by only updating create_trid if we are rewriting all rows and indexes.


mysql-test/suite/maria/alter.result:
  Added test case
mysql-test/suite/maria/alter.test:
  Added test case
storage/maria/ha_maria.cc:
  Only updating create_trid if we are doing a full repair (and thus rewriting all rows and indexes).
storage/maria/trnman.c:
  More DBUG_PRINT
parent 0ad8eaeb
drop table if exists t1;
Warnings:
Note 1051 Unknown table 't1'
CREATE TABLE t1 (pk INT, d DATETIME, PRIMARY KEY(pk), KEY(d)) ENGINE=Aria;
ALTER TABLE t1 DISABLE KEYS;
INSERT INTO t1 VALUES (1,'2000-01-01 22:22:22'),(2,'2012-12-21 12:12:12');
INSERT INTO t1 VALUES (3, '2008-07-24');
ALTER TABLE t1 ENABLE KEYS;
SELECT t1a.pk FROM t1 AS t1a LEFT JOIN t1 AS t1b ON t1a.pk = t1b.pk;
pk
1
2
3
SELECT * FROM t1 AS t1a LEFT JOIN t1 AS t1b ON t1a.pk = t1b.pk;
pk d pk d
1 2000-01-01 22:22:22 1 2000-01-01 22:22:22
2 2012-12-21 12:12:12 2 2012-12-21 12:12:12
3 2008-07-24 00:00:00 3 2008-07-24 00:00:00
DROP TABLE t1;
CREATE TABLE t1 (pk INT PRIMARY KEY, i INT, KEY(i)) ENGINE=Aria;
ALTER TABLE t1 DISABLE KEYS;
INSERT INTO t1 VALUES (1,11);
INSERT INTO t1 VALUES (2,0),(3,33),(4,0),(5,55),(6,66),(7,0),(8,88),(9,99);
ALTER TABLE t1 ENABLE KEYS;
SELECT * FROM t1 WHERE i = 0 OR pk BETWEEN 6 AND 10;
pk i
2 0
4 0
6 66
7 0
8 88
9 99
DROP TABLE t1;
# Testing of potential problems in Aria and alter table
-- source include/have_maria.inc
drop table if exists t1;
#
# MDEV-4970 Wrong result with Aria table populated with disabled keys
#
CREATE TABLE t1 (pk INT, d DATETIME, PRIMARY KEY(pk), KEY(d)) ENGINE=Aria;
ALTER TABLE t1 DISABLE KEYS;
INSERT INTO t1 VALUES (1,'2000-01-01 22:22:22'),(2,'2012-12-21 12:12:12');
INSERT INTO t1 VALUES (3, '2008-07-24');
ALTER TABLE t1 ENABLE KEYS;
SELECT t1a.pk FROM t1 AS t1a LEFT JOIN t1 AS t1b ON t1a.pk = t1b.pk;
SELECT * FROM t1 AS t1a LEFT JOIN t1 AS t1b ON t1a.pk = t1b.pk;
DROP TABLE t1;
CREATE TABLE t1 (pk INT PRIMARY KEY, i INT, KEY(i)) ENGINE=Aria;
ALTER TABLE t1 DISABLE KEYS;
INSERT INTO t1 VALUES (1,11);
INSERT INTO t1 VALUES (2,0),(3,33),(4,0),(5,55),(6,66),(7,0),(8,88),(9,99);
ALTER TABLE t1 ENABLE KEYS;
SELECT * FROM t1 WHERE i = 0 OR pk BETWEEN 6 AND 10;
DROP TABLE t1;
......@@ -1547,7 +1547,7 @@ int ha_maria::repair(THD *thd, HA_CHECK *param, bool do_optimize)
{
int error= 0;
ulonglong local_testflag= param->testflag;
bool optimize_done= !do_optimize, statistics_done= 0;
bool optimize_done= !do_optimize, statistics_done= 0, full_repair_done= 0;
const char *old_proc_info= thd->proc_info;
char fixed_name[FN_REFLEN];
MARIA_SHARE *share= file->s;
......@@ -1646,6 +1646,11 @@ int ha_maria::repair(THD *thd, HA_CHECK *param, bool do_optimize)
}
param->testflag= save_testflag | (param->testflag & T_RETRY_WITHOUT_QUICK);
optimize_done= 1;
/*
set full_repair_done if we re-wrote all rows and all keys
(and thus removed all transid's from the table
*/
full_repair_done= !test(param->testflag & T_QUICK);
}
if (!error)
{
......@@ -1669,7 +1674,8 @@ int ha_maria::repair(THD *thd, HA_CHECK *param, bool do_optimize)
}
}
thd_proc_info(thd, "Saving state");
if (optimize_done && !error && !(param->testflag & T_NO_CREATE_RENAME_LSN))
if (full_repair_done && !error &&
!(param->testflag & T_NO_CREATE_RENAME_LSN))
{
/* Set trid (needed if the table was moved from another system) */
share->state.create_trid= trnman_get_min_safe_trid();
......@@ -1962,6 +1968,7 @@ int ha_maria::enable_indexes(uint mode)
*/
param.testflag|= T_NO_CREATE_RENAME_LSN;
}
param.myf_rw &= ~MY_WAIT_IF_FULL;
param.sort_buffer_length= THDVAR(thd,sort_buffer_size);
param.stats_method= (enum_handler_stats_method)THDVAR(thd,stats_method);
......
......@@ -383,8 +383,8 @@ TRN *trnman_new_trn(WT_THD *wt)
return 0;
}
DBUG_PRINT("exit", ("trn: 0x%lx trid: 0x%lu",
(ulong) trn, (ulong) trn->trid));
DBUG_PRINT("exit", ("trn: %p trid: 0x%lu min_read_from: 0x%lu",
trn, (ulong) trn->trid, (ulong) trn->min_read_from));
DBUG_RETURN(trn);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment