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

OR expression pushdown #11086

Merged
merged 8 commits into from
Mar 10, 2022
Merged

Conversation

findepi
Copy link
Member

@findepi findepi commented Feb 17, 2022

This includes OR pushdown framework for JDBC connectors, implemented
initially for PostgreSQL.
Along with this, there comes support for comparison expressions,
effective literals, generic literals (used e.g. for BIGINT), to support
a minimal viable usage example for the OR pushdown.

Relates to #18

@cla-bot cla-bot bot added the cla-signed label Feb 17, 2022
@findepi
Copy link
Member Author

findepi commented Feb 17, 2022

Currently based on #11045

@findepi findepi force-pushed the findepi/sql-or-pushdown branch 2 times, most recently from 01e25d6 to fedfff7 Compare February 17, 2022 16:23
@findepi findepi force-pushed the findepi/sql-or-pushdown branch from fedfff7 to f81ceb6 Compare February 18, 2022 09:53
@findepi findepi force-pushed the findepi/sql-or-pushdown branch from 70390c5 to 745dfc1 Compare March 4, 2022 09:51
@findepi
Copy link
Member Author

findepi commented Mar 4, 2022

Rebased after #11045 merged.

@findepi
Copy link
Member Author

findepi commented Mar 4, 2022

CI ci / test (plugin/trino-hive, test-failure-recovery) - #11196 / #10631

(green otherwise)

@Override
protected Optional<ConnectorExpression> visitCast(Cast node, Void context)
{
if (isEffectivelyLiteral(plannerContext, session, node)) {
Copy link
Member

Choose a reason for hiding this comment

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

add if (!isComplexExpressionPushdown(session)) {

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure about this. What's complex about a constant? The explicit literals don't have such a check.

@findepi findepi force-pushed the findepi/sql-or-pushdown branch from 745dfc1 to 5a911f8 Compare March 9, 2022 11:11
@findepi
Copy link
Member Author

findepi commented Mar 9, 2022

(just rebased)

@findepi findepi force-pushed the findepi/sql-or-pushdown branch from 5a911f8 to 042c452 Compare March 9, 2022 12:53
@findepi
Copy link
Member Author

findepi commented Mar 9, 2022

AC. Changes as fixups (inline) + new commit Remove redundant argument being field.

@hashhar
Copy link
Member

hashhar commented Mar 9, 2022

reminder to squash fixups before merge

@findepi findepi force-pushed the findepi/sql-or-pushdown branch from 042c452 to 64988d6 Compare March 9, 2022 15:35
@findepi
Copy link
Member Author

findepi commented Mar 9, 2022

squashed, rebased, resolved conflicts and added Simplify TestConnectorExpressionTranslator commit to do a TODO comment i am adding in an earlier commit

findepi added 3 commits March 9, 2022 16:44
This includes OR pushdown framework for JDBC connectors, implemented
initially for PostgreSQL.
Along with this, there comes support for comparison expressions to
support a minimal viable usage example for the OR pushdown.
Use `assertTranslationRoundTrips` where possible... i.e. always.
@findepi findepi force-pushed the findepi/sql-or-pushdown branch from 64988d6 to 5b65402 Compare March 9, 2022 15:44
Copy link
Member

@hashhar hashhar left a comment

Choose a reason for hiding this comment

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

LGTM from me.

@findepi findepi merged commit 6b6c938 into trinodb:master Mar 10, 2022
@findepi findepi deleted the findepi/sql-or-pushdown branch March 10, 2022 07:55
@findepi findepi mentioned this pull request Mar 10, 2022
@github-actions github-actions bot added this to the 374 milestone Mar 10, 2022
{
assertThat(query("SELECT * FROM nation WHERE nationkey != 3 OR regionkey = 4")).isFullyPushedDown();
assertThat(query("SELECT * FROM nation WHERE nationkey != 3 OR regionkey != 4")).isFullyPushedDown();
assertThat(query("SELECT * FROM nation WHERE name = 'ALGERIA' OR regionkey = 4")).isFullyPushedDown();
Copy link
Member

@hashhar hashhar Jun 30, 2022

Choose a reason for hiding this comment

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

Does the expression rewrite depend on how predicates are ordered/grouped. I see that if add another case like

assertThat(query("SELECT * FROM nation WHERE (name = 'ALGERIA' AND regionkey != 10) OR (regionkey = 4 AND name != 'FOOBAR')")).isFullyPushedDown();

it fails and we get a ScanFilterNode.

cc: @wendigo

Copy link
Member Author

Choose a reason for hiding this comment

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

That's unrelated to OR. That's because != isn't subsumed:

trino:tpch> EXPLAIN SELECT * FROM nation WHERE name != 'FOOBAR' ;
                                                           Query Plan
--------------------------------------------------------------------------------------------------------------------------------
....

 Fragment 1 [SOURCE]
     Output layout: [nationkey, name, regionkey, comment]
     Output partitioning: SINGLE []
     ScanFilter[table = postgresql:tpch.nation tpch.nation, filterPredicate = ("name" <> CAST('FOOBAR' AS varchar(25)))]
         Layout: [nationkey:bigint, name:varchar(25), regionkey:bigint, comment:varchar(152)]
         Estimates: {rows: 25 (3.13kB), cpu: 3.13k, memory: 0B, network: 0B}/{rows: ? (?), cpu: 6.25k, memory: 0B, network: 0B}
         nationkey := nationkey:bigint:int8
         regionkey := regionkey:bigint:int8
         name := name:varchar(25):varchar
         comment := comment:varchar(152):varchar

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

Successfully merging this pull request may close these issues.

4 participants