Skip to content

DELETE only needs row id, partition key and indexed columns #38911

Open
@tangenta

Description

Enhancement

mysql> create table t (a varchar(100), b int, c int, primary key(a, b) nonclustered);
Query OK, 0 rows affected (0.17 sec)

mysql> explain delete from t where a in ('aaaaa', 'b');
+----------------------------------+---------+-----------+------------------------------+--------------------------------------------------------------------+
| id                               | estRows | task      | access object                | operator info                                                      |
+----------------------------------+---------+-----------+------------------------------+--------------------------------------------------------------------+
| Delete_4                         | N/A     | root      |                              | N/A                                                                |
| └─IndexLookUp_11                 | 20.00   | root      |                              |                                                                    |
|   ├─IndexRangeScan_9(Build)      | 20.00   | cop[tikv] | table:t, index:PRIMARY(a, b) | range:["aaaaa","aaaaa"], ["b","b"], keep order:false, stats:pseudo |
|   └─TableRowIDScan_10(Probe)     | 20.00   | cop[tikv] | table:t                      | keep order:false, stats:pseudo                                     |
+----------------------------------+---------+-----------+------------------------------+--------------------------------------------------------------------+
4 rows in set (0.01 sec)

For the delete operation, only _tidb_rowid and the value a and b are required. In this case, IndexLookUp can be eliminated to a IndexRangeScan.

Detailed work items

We split the cases into details:

  • The most simple case: single table delete on a normal table(no foreign key, no partition)
  • Multi-table delete
  • Support for tables containing foreign key
  • Support for tables containing partitions

A DELETE will contain the read path, reading the needed rows from storage. And the write path, deleting the given row and its indexes. To save the network cost, we need to support the column pruning both for the read path and the write path:

To support the most simple and common case, we need to modify the write path and let planner change the column reference map.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

sig/plannerSIG: Plannertype/enhancementThe issue or PR belongs to an enhancement.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions