trinodb / trino

Official repository of Trino, the distributed SQL query engine for big data, formerly known as PrestoSQL (https://trino.io)
https://trino.io
Apache License 2.0
10.42k stars 3k forks source link

DELETE target table is captured as a input in event listener #16433

Open kokosing opened 1 year ago

kokosing commented 1 year ago

For a query like this DELETE FROM x WHERE (SELECT … FROM y) we currently get x, y as input table but it should be just y.

See io.trino.spi.eventlistener.QueryIOMetadata.

kokosing commented 1 year ago

CC: @Praveen2112 @lukasz-walkiewicz

chenjian2664 commented 1 year ago

I think it's because of the we plan the DeleteNode into the MergeWriteNode, thus the table x treated as merge target, it's scanned by default. Maybe we don't need to "fix" this?

kokosing commented 1 year ago

Maybe we don't need to "fix" this?

We need to fix this. The way how it is implemented should not matter what is the semantic of the query. If someone is using listener to capture some logical information then here they will get a corrupted data.

@Praveen2112 do you happen to remember the details of it?

chenjian2664 commented 1 year ago

@kokosing Can I take this?

chenjian2664 commented 1 year ago

I think we can fix this by adding a check on the InputExtractor#Visitor.visitTableScan if the scan is update target, if yes skip the table. @kokosing What do you think

kokosing commented 1 year ago

Can I take this?

I would be delighted. Please do!

I think we can fix this by adding a check on the InputExtractor#Visitor.visitTableScan if the scan is update target, if yes skip the table. What do you think?

@Praveen2112 can you please respond? I don't have the full context here.