Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push down DELETE for enforceable filters on Delta Lake #18332

Merged
merged 3 commits into from
Aug 24, 2023

Conversation

findinpath
Copy link
Contributor

@findinpath findinpath commented Jul 18, 2023

Description

Perform DELETE only on the metadata of the Delta Lake
table when the delete filter does not touch any data
columns.

Sample queries affected by this enhancement are:

DELETE FROM table 
DELETE FROM table WHERE true
DELETE FROM partitioned_table WHERE part1=value1 AND part2=value2
DELETE FROM partitioned_table WHERE part2=value2

Fixes #18331

The operation will not be performed on the metadata layer when
there are add file entries in the transaction log of the table
without statistics containing number of records.

Additional context and related issues

Without DELETE pushdown

trino:default> create table delta.tiny.sforders100 as select * from tpch.sf100.orders;
CREATE TABLE: 150000000 rows

trino:default> delete from delta.tiny.sforders100 where true;
DELETE: 150000000 rows

Query 20230725_125258_00003_xfv9h, FINISHED, 1 node
http://localhost:8080/ui/query.html?20230725_125258_00003_xfv9h
Splits: 25 total, 25 done (100.00%)
CPU Time: 115.1s total,  1.3M rows/s, 11.2MB/s, 89% active
Per Node: 1.1 parallelism, 1.46M rows/s, 12.5MB/s
Parallelism: 1.1
Peak Memory: 87.3MB
1:43 [150M rows, 1.26GB] [1.46M rows/s, 12.5MB/s]

With DELETE pushdown

trino:default> delete from delta.tiny.sf100orders where true;
DELETE: 150000000 rows

Query 20230725_123039_00000_fk4kt, FINISHED, 1 node
http://localhost:8080/ui/query.html?20230725_123039_00000_fk4kt
Splits: 1 total, 1 done (100.00%)
CPU Time: 0.1s total,     0 rows/s,     0B/s, 83% active
Per Node: 0.1 parallelism,     0 rows/s,     0B/s
Parallelism: 0.1
Peak Memory: 112B
1.84 [0 rows, 0B] [0 rows/s, 0B/s]

tldr; before 103 s after 1.8 s

Release notes

(x) Release notes are required, with the following suggested text:

# Delta Lake
* Improve performance of `DELETE` statement when it deletes the whole table or the filters apply only to the partition columns. ({issue}`18332 `)

@cla-bot cla-bot bot added the cla-signed label Jul 18, 2023
@findinpath findinpath self-assigned this Jul 18, 2023
@findinpath findinpath added the delta-lake Delta Lake connector label Jul 18, 2023
@@ -361,7 +361,7 @@ private int[] getWriterIndexes(Page page)
partitionName = Optional.of(partName);
}

String fileName = session.getQueryId() + "-" + randomUUID();
String fileName = session.getQueryId() + "_" + randomUUID();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is in sync with

Location targetLocation = sourceLocation.parentDirectory().appendPath(session.getQueryId() + "_" + randomUUID());

I'd benefit from a suggestion in which utility class could i extract the method for creating the file name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can always add a new one ;)

@findinpath findinpath force-pushed the findinpath/delta-push-down-delete branch from 6261a7b to cb8a04f Compare July 18, 2023 22:57
@findinpath
Copy link
Contributor Author

findinpath commented Jul 19, 2023

TestDeltaLakeDelete.testDeleteAllOssDeltaLake is failing because the number of deleted rows is not anymore returned by the DELETE query.

Should the accelerated DELETE (done only based on table metadata) be performed if and only if all the data files have the number of records present in the transaction log file?

As agreed with @findepi , it is rather unusual to deal with add entries in the transaction logs which don't contain the file stats.
In the unlikely case that we're dealing with such a table, simply don't return the number of rows affected for the DELETE operation if we can execute it faster.

@findinpath findinpath force-pushed the findinpath/delta-push-down-delete branch from cb8a04f to 958e634 Compare July 25, 2023 13:50
@findinpath findinpath requested review from ebyhr, alexjo2144 and homar July 25, 2023 13:52
@findinpath findinpath marked this pull request as ready for review July 25, 2023 13:55
@findinpath findinpath force-pushed the findinpath/delta-push-down-delete branch from 958e634 to b791cd1 Compare July 26, 2023 13:12
@findinpath findinpath requested review from homar and findepi July 26, 2023 15:12
@findinpath findinpath force-pushed the findinpath/delta-push-down-delete branch 3 times, most recently from de468d5 to 31f088f Compare August 9, 2023 11:46
@findinpath findinpath force-pushed the findinpath/delta-push-down-delete branch from 31f088f to fd8e62a Compare August 9, 2023 12:33
throw new TransactionConflictException(format("Conflicting concurrent writes found. Expected transaction log version: %s, actual version: %s", tableHandle.getReadVersion(), currentVersion));
}
long commitVersion = currentVersion + 1;
transactionLogWriter.appendCommitInfoEntry(getCommitInfoEntry(session, commitVersion, createdTime, MERGE_OPERATION, tableHandle.getReadVersion()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete operation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just following the same pattern as the one used for UPDATE/DELETE/MERGE statements in Delta Lake. See #15763

@findinpath findinpath force-pushed the findinpath/delta-push-down-delete branch 3 times, most recently from e11f841 to 36b1b96 Compare August 14, 2023 21:14
@findinpath findinpath requested a review from alexjo2144 August 14, 2023 21:18
@findinpath
Copy link
Contributor Author

Rebasing on master to address conflicts

@findinpath findinpath force-pushed the findinpath/delta-push-down-delete branch 2 times, most recently from 7c22b5b to 12e8d36 Compare August 21, 2023 11:40
@findinpath
Copy link
Contributor Author

@pajaks & @alexjo2144 AC. Please review again the PR.

@findinpath findinpath requested a review from pajaks August 21, 2023 11:42
@findinpath findinpath force-pushed the findinpath/delta-push-down-delete branch from 12e8d36 to c2128d4 Compare August 23, 2023 13:29
@findinpath
Copy link
Contributor Author

Thank you everybody for the valuable feedback.
AC

@findinpath findinpath requested a review from ebyhr August 23, 2023 13:30
@findinpath findinpath force-pushed the findinpath/delta-push-down-delete branch 2 times, most recently from adaf4e7 to 4dc908c Compare August 23, 2023 13:50
Perform DELETE only on the metadata of the Delta Lake
table when the delete filter does not touch any data
columns.

Sample queries affected by this enhancement are:

```
DELETE FROM table
DELETE FROM table WHERE true
DELETE FROM partitioned_table WHERE part1=value1 AND part2=value2
DELETE FROM partitioned_table WHERE part2=value2
```

Given that this operation is performed only on the metadata layer,
when there are `add` file entries in the transaction log of the table
without statistics containing number of records, then number of deleted
records will not be returned.
@ebyhr ebyhr force-pushed the findinpath/delta-push-down-delete branch from 4dc908c to 29ba6d3 Compare August 23, 2023 22:14
@ebyhr
Copy link
Member

ebyhr commented Aug 23, 2023

Pushed small changes to fix CI failure.

@ebyhr ebyhr merged commit 82058a9 into trinodb:master Aug 24, 2023
@github-actions github-actions bot added this to the 425 milestone Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed delta-lake Delta Lake connector
Development

Successfully merging this pull request may close these issues.

Push down DELETE to the Delta Lake connector when filter is not applied on the data columns
5 participants