Details
-
Bug
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.11, 11.4, 11.8, 12.3
-
None
Description
The value of an indexed virtual column is stored in the index when the row is written, but recomputed from the current sql_mode when the row is read. If STR_TO_DATE() (or any function whose result depends on NO_ZERO_DATE / NO_ZERO_IN_DATE) returns a zero date under one sql_mode and NULL under another, the index entry and the recomputed value differ. The index is then reported as corrupted.
--source include/have_innodb.inc
|
 |
CREATE TABLE t1 (id INT PRIMARY KEY, a VARCHAR(30), |
c DATE AS (STR_TO_DATE(a,'%Y-%m-%d')) VIRTUAL, KEY(c)) ENGINE=InnoDB; |
SET sql_mode=''; |
INSERT INTO t1(id,a) VALUES (1,'2026-00-00'); |
SET sql_mode='NO_ZERO_IN_DATE,NO_ZERO_DATE'; |
--echo # BUG if the index has no entry for the row
|
SELECT * FROM t1 FORCE INDEX(c) WHERE c IS NULL; |
CHECK TABLE t1 EXTENDED; |
DROP TABLE t1; |
Actual output:
SELECT * FROM t1 FORCE INDEX(c) WHERE c IS NULL;
|
id a c
|
CHECK TABLE t1 EXTENDED;
|
Table Op Msg_type Msg_text
|
test.t1 check Warning Incorrect datetime value: '2026-00-00' for function str_to_date
|
test.t1 check Warning InnoDB: Index 'c' contains 0 entries, should be 1.
|
test.t1 check error Corrupt
|
Expected: FORCE INDEX(c) WHERE c IS NULL returns the same rows as a full scan, and CHECK TABLE succeeds.
Attachments
Issue Links
- relates to
-
MDEV-20763 Table corruption or Assertion `btr_validate_index(index, 0, false)' failed in row_upd_sec_index_entry with virtual column and EMPTY_STRING_IS_NULL SQL mode
-
- Closed
-