Skip to content

Unwrap year in comparison also for IN predicate#18092

Merged
findepi merged 1 commit intotrinodb:masterfrom
kabunchi:unwrap-in
Jul 5, 2023
Merged

Unwrap year in comparison also for IN predicate#18092
findepi merged 1 commit intotrinodb:masterfrom
kabunchi:unwrap-in

Conversation

@kabunchi
Copy link
Copy Markdown

@kabunchi kabunchi commented Jun 29, 2023

Description

Additional context and related issues

Release notes

(*) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

# Section
* Improve query performance for queries involving `year` function within `IN` predicate.

@cla-bot cla-bot bot added the cla-signed label Jun 29, 2023
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@ebyhr I am not sure I need this line. please advise.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i think it would be better to default-rewrite (recursive) first, then to extract the attributes, just in case they got rewritten or simplified (don't think it matters currently, matter of style/future-proofing)

 InPredicate inPredicate = treeRewriter.defaultRewrite(node, null);
            Expression value = inPredicate.getValue();
            Expression valueList = inPredicate.getValueList();

@ebyhr ebyhr requested review from ebyhr and findepi July 3, 2023 08:44
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we probably want similar change for UnwrapDateTruncInComparison and UnwrapCastInComparison?

cc @martint @alexjo2144

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Follow-up #18138

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

use ImmutableList.Builder

(per style, but also to avoid copy when creating new LogicalExpression)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i think it would be better to default-rewrite (recursive) first, then to extract the attributes, just in case they got rewritten or simplified (don't think it matters currently, matter of style/future-proofing)

 InPredicate inPredicate = treeRewriter.defaultRewrite(node, null);
            Expression value = inPredicate.getValue();
            Expression valueList = inPredicate.getValueList();

@findepi
Copy link
Copy Markdown
Member

findepi commented Jul 4, 2023

force-pushed the unwrap-in branch from dc30ccf to 600dba1
8 minutes ago

please avoid mixing changes with rebase. it's hard to notice what chaned.

Comment on lines 136 to 137
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Expression value = node.getValue();
Expression valueList = node.getValueList();
Expression value = inPredicate.getValue();
Expression valueList = inPredicate.getValueList();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done. I wasn't sure that the returned expression from defaultRewriter must be an InPredicate so I also added a validation.

Comment on lines 148 to 150
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  • avoid abbreviations ("curr")
  • comparisonExpressionsListBuilder is a long name and the fact it's listbuilder is known from its type
  • expressionsList can be inlined
Suggested change
List<Expression> expressionsList = inListExpression.getValues();
ImmutableList.Builder<Expression> comparisonExpressionsListBuilder = ImmutableList.builder();
for (Expression currExpression : expressionsList) {
ImmutableList.Builder<Expression> comparisonExpressions = ImmutableList.builderWithExpectedSize(inListExpression.getValues().size());
for (Expression rightExpression : inListExpression.getValues()) {
ComparisonExpression comparisonExpression = new ComparisonExpression(EQUAL, value, rightExpression);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done.

@findepi
Copy link
Copy Markdown
Member

findepi commented Jul 5, 2023

@kabunchi thanks, will merge when the build passes
can you please follow-up with https://github.com/trinodb/trino/pull/18092/files#r1252095563 ?

@findepi findepi merged commit d3f55cb into trinodb:master Jul 5, 2023
@github-actions github-actions bot added this to the 421 milestone Jul 5, 2023
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