Skip to content

projection containing virtual columns should be evaluated before the UnionScan(dirty write content) #53951

@bb7133

Description

@bb7133

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE `gholla_dummy1` (
  `id` varchar(10) NOT NULL,
  `mark` int,
  `deleted_at` datetime(3) NOT NULL DEFAULT '1970-01-01 01:00:01.000',
  `account_id` varchar(10) NOT NULL,
  `metastore_id` varchar(10) NOT NULL,
  `is_deleted` tinyint(1) GENERATED ALWAYS AS ((`deleted_at` > _utf8mb4'1970-01-01 01:00:01.000')) VIRTUAL NOT NULL,
  PRIMARY KEY (`account_id`,`metastore_id`,`id`),
  KEY `isDeleted_accountId_metastoreId` (`is_deleted`,`account_id`,`metastore_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

CREATE TABLE `gholla_dummy2` (
  `id` varchar(10) NOT NULL,
  `mark` int,
  `deleted_at` datetime(3) NOT NULL DEFAULT '1970-01-01 01:00:01.000',
  `account_id` varchar(10) NOT NULL,
  `metastore_id` varchar(10) NOT NULL,
  `is_deleted` tinyint(1) GENERATED ALWAYS AS ((`deleted_at` > _utf8mb4'1970-01-01 01:00:01.000')) VIRTUAL NOT NULL,
  PRIMARY KEY (`account_id`,`metastore_id`,`id`),
  KEY `isDeleted_accountId_metastoreId` (`is_deleted`,`account_id`,`metastore_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; 

INSERT INTO gholla_dummy1 (id,mark,deleted_at,account_id,metastore_id) VALUES ('ABC', 1, '1970-01-01 01:00:01.000', 'ABC', 'ABC');

INSERT INTO gholla_dummy2 (id,mark,deleted_at,account_id,metastore_id) VALUES ('ABC', 1, '1970-01-01 01:00:01.000', 'ABC', 'ABC');

start transaction;
update gholla_dummy2 set deleted_at = NOW(), mark=2 where account_id = 'ABC' and metastore_id = 'ABC' and id = 'ABC';
select
  /*+ INL_JOIN(g1, g2) */
  g1.account_id,
  g2.mark
from
  gholla_dummy1 g1 FORCE INDEX(isDeleted_accountId_metastoreId) 
STRAIGHT_JOIN
  gholla_dummy2 g2 FORCE INDEX (PRIMARY)
ON
  g1.account_id = g2.account_id AND
  g1.metastore_id = g2.metastore_id AND
  g1.id = g2.id
WHERE
  g1.account_id = 'ABC' AND
  g1.metastore_id = 'ABC' AND
  g1.is_deleted = FALSE AND
  g2.is_deleted = FALSE;

2. What did you expect to see? (Required)

No result was returned because we updated is_deleted in the transaction.

3. What did you see instead (Required)

tidb> select
    ->   /*+ INL_JOIN(g1, g2) */
    ->   g1.account_id,
    ->   g2.mark
    -> from
    ->   gholla_dummy1 g1 FORCE INDEX(isDeleted_accountId_metastoreId)
    -> STRAIGHT_JOIN
    ->   gholla_dummy2 g2 FORCE INDEX (PRIMARY)
    -> ON
    ->   g1.account_id = g2.account_id AND
    ->   g1.metastore_id = g2.metastore_id AND
    ->   g1.id = g2.id
    -> WHERE
    ->   g1.account_id = 'ABC' AND
    ->   g1.metastore_id = 'ABC' AND
    ->   g1.is_deleted = FALSE AND
    ->   g2.is_deleted = FALSE;
+------------+------+
| account_id | mark |
+------------+------+
| ABC        |    1 |
+------------+------+
1 row in set (0.01 sec)

The update in the transaction was not read.

4. What is your TiDB version? (Required)

It exists in all versions of TiDB.

Metadata

Metadata

Assignees

Labels

affects-5.4This bug affects the 5.4.x(LTS) versions.affects-6.1This bug affects the 6.1.x(LTS) versions.affects-6.5This bug affects the 6.5.x(LTS) versions.affects-7.1This bug affects the 7.1.x(LTS) versions.affects-7.5This bug affects the 7.5.x(LTS) versions.affects-8.1This bug affects the 8.1.x(LTS) versions.impact/wrong-resultreport/customerCustomers have encountered this bug.severity/criticalsig/plannerSIG: Plannertype/bugThe issue is confirmed as a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions