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

[CALCITE-6586] Some Rules not firing due to RelMdPredicates returning… #3976

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

suibianwanwank
Copy link
Contributor

This PR supports getPredicates(RelSubset) returning getPredicate(stripped) in place of EMPTY as a temporary solution.
But it exceeds the expected range because some rules are re-fire in VolcanoPlanner.
Major Changes:
In SortRemoveConstantKey the constant key in the sort is removed. before this PR the traitset of the sort needs to be consistent with the collation. It would result in the new sort having a different traitset than the original one, it would not be in the same RelSubSet and would not be selected.
So I tried to modify the traitSet assert in sort so that it can be set to RelComposetrait.
For example : order by a,b,c
If we can make sure that b is constant, then the traitSet of the sort can be [[a,b,c],[a,c]]. Also, when collation is empty and there are only offset and fetch, the original input collation traits can be kept in the sort.
There are also a few more changes that I will add comments on. For the Sort changes, we can probably discuss them in Jira if needed. Thanks for the suggestion and review.

Copy link

sonarcloud bot commented Sep 24, 2024

@@ -66,7 +66,7 @@ public class GeodeSort extends Sort implements GeodeRel {

@Override public Sort copy(RelTraitSet traitSet, RelNode input,
RelCollation newCollation, RexNode offset, RexNode fetch) {
return new GeodeSort(getCluster(), traitSet, input, collation, fetch);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use the new traitset in the copy of the sort, and the other sort copies as well.

@@ -96,4 +98,9 @@ public static InnodbFilter create(RelOptCluster cluster, RelTraitSet traitSet,
public RelCollation getImplicitCollation() {
return indexCondition.getImplicitCollation();
}

@Override public RexNode getCondition() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

InnodbFIlter's condition contains both indexed and non-indexed conditions, but only the indexed filter will be executed. This will cause the FilterReduceExpression to produce incorrect results.

@@ -922,10 +922,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[null:BOOLEAN], expr#5=[IS NOT NULL(
EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5])
EnumerableTableScan(table=[[scott, EMP]])
EnumerableLimit(fetch=[1])
EnumerableSort(sort0=[$0], dir0=[DESC])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The changes to sub-query.iq are due to JoinOnUniqueToSemiJoinRule and SortRemoveConstantKeysRule taking effect.

@@ -456,51 +456,23 @@ public Boolean areColumnsUnique(Values rel, RelMetadataQuery mq,
ImmutableBitSet columns, boolean ignoreNulls) {
columns = decorateWithConstantColumnsFromPredicates(columns, rel, mq);
for (RelNode rel2 : rel.getRels()) {
if (rel2 instanceof Aggregate
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 not sure why this restriction was made, but after pullUpPredicate supported RelSubset, columns would union the constant field, And return false due to simplyProject. So I remove the restriction here.

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

Successfully merging this pull request may close these issues.

2 participants