You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2020/01/09 17:20:50 UTC
[GitHub] [calcite] vlsi opened a new pull request #1740: [CALCITE-3713]
Remove column names from Project#digest
vlsi opened a new pull request #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740
Projects that differ with column names only are equivalent,
so the planning space can be reduced if field names
do not participate in relation matching.
For instance, `Project(input=rel#1,empid=$0)` and `Project(input=rel#1,deptno=$0)` are equivalent under the new digest approach.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] hsyuan commented on issue #1740: [CALCITE-3713] Remove
column names from Project#digest
Posted by GitBox <gi...@apache.org>.
hsyuan commented on issue #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#issuecomment-583559444
@vlsi It turns out this patch causes 20~30% overhead for HepPlanner. Because the hash map lookup in belongsToDag becomes much slower. The hashcode and equals for the list is not as efficient as the simple RelDataType.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] vlsi commented on issue #1740: [CALCITE-3713] Remove
column names from Project#digest
Posted by GitBox <gi...@apache.org>.
vlsi commented on issue #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#issuecomment-583565364
@hsyuan , do you have async-profiler or JFR snapshots?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] vlsi commented on a change in pull request #1740:
[CALCITE-3713] Remove column names from Project#digest
Posted by GitBox <gi...@apache.org>.
vlsi commented on a change in pull request #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#discussion_r365115741
##########
File path: core/src/main/java/org/apache/calcite/rex/RexCall.java
##########
@@ -127,11 +137,83 @@ protected final StringBuilder appendOperands(StringBuilder sb) {
includeType = RexDigestIncludeType.NO_TYPE;
}
}
- sb.append(((RexLiteral) operand).computeDigest(includeType));
+ operandDigests.add(((RexLiteral) operand).computeDigest(includeType));
+ }
+ int totalLength = (operandDigests.size() - 1) * 2; // commas
+ for (String s : operandDigests) {
+ totalLength += s.length();
+ }
+ sb.ensureCapacity(sb.length() + totalLength);
+ sortOperandsIfNeeded(sb, operands, operandDigests);
+ for (int i = 0; i < operandDigests.size(); i++) {
+ String op = operandDigests.get(i);
+ if (i != 0) {
+ sb.append(", ");
+ }
+ sb.append(op);
}
return sb;
}
+ private void sortOperandsIfNeeded(StringBuilder sb,
+ List<RexNode> operands, List<String> operandDigests) {
+ if (operands.isEmpty() || !needNormalize()) {
+ return;
+ }
+ final SqlKind kind = op.getKind();
+ if (SqlKind.SYMMETRICAL_SAME_ARG_TYPE.contains(kind)) {
+ final RelDataType firstType = operands.get(0).getType();
+ for (int i = 1; i < operands.size(); i++) {
+ if (!equalSansNullability(firstType, operands.get(i).getType())) {
+ // Arguments have different type, thus they must not be sorted
Review comment:
Do we want to support strict floating-point non-associativity here?
Technically speaking, `PLUS` for FLOATs is not associative :(
https://stackoverflow.com/a/10371890/1261287
>i means to support more reordering for PLUS and TIMES even their operands types are differen
I wanted the first iteration to be as simple as it could be.
Proper cost estimates are more interesting for me than spending time on `DECIMAL(3,0) + DECIMAL(5,0)` normalization.
Reordering of `DECIMAL(3,0) + DECIMAL(5,0)` might be tricky, especially if it is nested: `DECIMAL(3,0) + DECIMAL(3,0) + DECIMAL(5,0)` might probably return different result than `DECIMAL(5,0) + DECIMAL(3,0) + DECIMAL(3,0)`, so I don't want to spend time on exploring those scenarios as they are quite rare for me.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] danny0405 commented on a change in pull request #1740:
[CALCITE-3713] Remove column names from Project#digest
Posted by GitBox <gi...@apache.org>.
danny0405 commented on a change in pull request #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#discussion_r365069324
##########
File path: core/src/main/java/org/apache/calcite/rex/RexCall.java
##########
@@ -127,11 +137,83 @@ protected final StringBuilder appendOperands(StringBuilder sb) {
includeType = RexDigestIncludeType.NO_TYPE;
}
}
- sb.append(((RexLiteral) operand).computeDigest(includeType));
+ operandDigests.add(((RexLiteral) operand).computeDigest(includeType));
+ }
+ int totalLength = (operandDigests.size() - 1) * 2; // commas
+ for (String s : operandDigests) {
+ totalLength += s.length();
+ }
+ sb.ensureCapacity(sb.length() + totalLength);
+ sortOperandsIfNeeded(sb, operands, operandDigests);
+ for (int i = 0; i < operandDigests.size(); i++) {
+ String op = operandDigests.get(i);
+ if (i != 0) {
+ sb.append(", ");
+ }
+ sb.append(op);
}
return sb;
}
+ private void sortOperandsIfNeeded(StringBuilder sb,
+ List<RexNode> operands, List<String> operandDigests) {
+ if (operands.isEmpty() || !needNormalize()) {
+ return;
+ }
+ final SqlKind kind = op.getKind();
+ if (SqlKind.SYMMETRICAL_SAME_ARG_TYPE.contains(kind)) {
+ final RelDataType firstType = operands.get(0).getType();
+ for (int i = 1; i < operands.size(); i++) {
+ if (!equalSansNullability(firstType, operands.get(i).getType())) {
+ // Arguments have different type, thus they must not be sorted
+ return;
+ }
+ }
+ // fall through: order arguments below
+ } else if (!SqlKind.SYMMETRICAL.contains(kind)
+ && (kind == kind.reverse()
+ || !op.getName().equals(kind.sql)
+ || sb.length() < 2 || sb.charAt(sb.length() - 1) != '(')) {
+ // The operations have to be either symmetrical or reversible
Review comment:
I'm confused with the code snippet
```java
&& (kind == kind.reverse()
|| !op.getName().equals(kind.sql)
|| sb.length() < 2 || sb.charAt(sb.length() - 1) != '(')
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] xndai edited a comment on issue #1740: [CALCITE-3713]
Remove column names from Project#digest
Posted by GitBox <gi...@apache.org>.
xndai edited a comment on issue #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#issuecomment-584911960
>Every time we create a new RelType we build stings.
Every time we create RelNode we build strings.
Every time we create RexNode we build strings.
Yes, but if not string, you would be creating something else.
I am fine with the initial overhead. But we cannot afford recomputing hash code every time when access the map. Unfortunately this is what `List<RelDataType>` does with your change.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] vlsi commented on issue #1740: [CALCITE-3713] Remove
column names from Project#digest
Posted by GitBox <gi...@apache.org>.
vlsi commented on issue #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#issuecomment-584548560
@xndai , I just thought removal of column name from `RelRecordType::generateTypeString` might have non-trivial side effects for Calcite consumers.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] vlsi commented on a change in pull request #1740:
[CALCITE-3713] Remove column names from Project#digest
Posted by GitBox <gi...@apache.org>.
vlsi commented on a change in pull request #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#discussion_r365118346
##########
File path: core/src/main/java/org/apache/calcite/rex/RexCall.java
##########
@@ -127,11 +137,83 @@ protected final StringBuilder appendOperands(StringBuilder sb) {
includeType = RexDigestIncludeType.NO_TYPE;
}
}
- sb.append(((RexLiteral) operand).computeDigest(includeType));
+ operandDigests.add(((RexLiteral) operand).computeDigest(includeType));
+ }
+ int totalLength = (operandDigests.size() - 1) * 2; // commas
+ for (String s : operandDigests) {
+ totalLength += s.length();
+ }
+ sb.ensureCapacity(sb.length() + totalLength);
+ sortOperandsIfNeeded(sb, operands, operandDigests);
+ for (int i = 0; i < operandDigests.size(); i++) {
+ String op = operandDigests.get(i);
+ if (i != 0) {
+ sb.append(", ");
+ }
+ sb.append(op);
}
return sb;
}
+ private void sortOperandsIfNeeded(StringBuilder sb,
+ List<RexNode> operands, List<String> operandDigests) {
+ if (operands.isEmpty() || !needNormalize()) {
+ return;
+ }
+ final SqlKind kind = op.getKind();
+ if (SqlKind.SYMMETRICAL_SAME_ARG_TYPE.contains(kind)) {
+ final RelDataType firstType = operands.get(0).getType();
+ for (int i = 1; i < operands.size(); i++) {
+ if (!equalSansNullability(firstType, operands.get(i).getType())) {
+ // Arguments have different type, thus they must not be sorted
Review comment:
I've no idea. We could probably add a logger or counter to so it would count the number of times the normalization was skipped for + / *.
If you have production-like queries/test-cases, it would be nice if you could add them.
However, I still think refining cost estimates and uniqueness metadata (see https://github.com/apache/calcite/pull/1702 ) has better benefits than enhanced + * normalization.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] xndai commented on issue #1740: [CALCITE-3713] Remove
column names from Project#digest
Posted by GitBox <gi...@apache.org>.
xndai commented on issue #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#issuecomment-584839764
> I would rather add a method to RelDataType that computes the digest without taking column names to the consideration.
That would work. Then mapDigestToRel key would be Pair<String, String> where the second string is the new digest without column name. It won't solve the memory growth problem though.
> here we build strings again and again, and it might help if we would be able to skip building strings.
Not sure what you mean. RelNode caches digest until recomputeDigest() is called. We don't build strings over and over. There might be a better abstraction to represent digest, but I think string serves the purpose currently. It would be a big change to use something else, and I don't see clear benefits.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] vlsi merged pull request #1740: [CALCITE-3713] Remove
column names from Project#digest
Posted by GitBox <gi...@apache.org>.
vlsi merged pull request #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] vlsi commented on issue #1740: [CALCITE-3713] Remove
column names from Project#digest
Posted by GitBox <gi...@apache.org>.
vlsi commented on issue #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#issuecomment-584799605
@xndai , I would rather add a method to `RelDataType` that computes the digest without taking column names to the consideration.
Note: we add an opaque `Digest` interface (or even `Object`), so it does not tie to `String`.
It looks like we have similar issues with `RexNode` digest, and `RelNode` digest. There we build strings again and again, and it might help if we would be able to skip building strings.
I don't insist that adding `Digestable` interface is the only way to go here, however, I think it is a nice opportunity, and it might be helpful for other digests as well.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] danny0405 commented on a change in pull request #1740:
[CALCITE-3713] Remove column names from Project#digest
Posted by GitBox <gi...@apache.org>.
danny0405 commented on a change in pull request #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#discussion_r365093897
##########
File path: core/src/main/java/org/apache/calcite/rex/RexCall.java
##########
@@ -127,11 +137,83 @@ protected final StringBuilder appendOperands(StringBuilder sb) {
includeType = RexDigestIncludeType.NO_TYPE;
}
}
- sb.append(((RexLiteral) operand).computeDigest(includeType));
+ operandDigests.add(((RexLiteral) operand).computeDigest(includeType));
+ }
+ int totalLength = (operandDigests.size() - 1) * 2; // commas
+ for (String s : operandDigests) {
+ totalLength += s.length();
+ }
+ sb.ensureCapacity(sb.length() + totalLength);
+ sortOperandsIfNeeded(sb, operands, operandDigests);
+ for (int i = 0; i < operandDigests.size(); i++) {
+ String op = operandDigests.get(i);
+ if (i != 0) {
+ sb.append(", ");
+ }
+ sb.append(op);
}
return sb;
}
+ private void sortOperandsIfNeeded(StringBuilder sb,
+ List<RexNode> operands, List<String> operandDigests) {
+ if (operands.isEmpty() || !needNormalize()) {
+ return;
+ }
+ final SqlKind kind = op.getKind();
+ if (SqlKind.SYMMETRICAL_SAME_ARG_TYPE.contains(kind)) {
+ final RelDataType firstType = operands.get(0).getType();
+ for (int i = 1; i < operands.size(); i++) {
+ if (!equalSansNullability(firstType, operands.get(i).getType())) {
+ // Arguments have different type, thus they must not be sorted
Review comment:
Because of the return type inference, see `RetirnTypes.NULLABLE_SUM` and `ReturnTypes.PRODUCT_NULLABLE`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] danny0405 commented on a change in pull request #1740:
[CALCITE-3713] Remove column names from Project#digest
Posted by GitBox <gi...@apache.org>.
danny0405 commented on a change in pull request #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#discussion_r365108780
##########
File path: core/src/main/java/org/apache/calcite/rex/RexCall.java
##########
@@ -127,11 +137,83 @@ protected final StringBuilder appendOperands(StringBuilder sb) {
includeType = RexDigestIncludeType.NO_TYPE;
}
}
- sb.append(((RexLiteral) operand).computeDigest(includeType));
+ operandDigests.add(((RexLiteral) operand).computeDigest(includeType));
+ }
+ int totalLength = (operandDigests.size() - 1) * 2; // commas
+ for (String s : operandDigests) {
+ totalLength += s.length();
+ }
+ sb.ensureCapacity(sb.length() + totalLength);
+ sortOperandsIfNeeded(sb, operands, operandDigests);
+ for (int i = 0; i < operandDigests.size(); i++) {
+ String op = operandDigests.get(i);
+ if (i != 0) {
+ sb.append(", ");
+ }
+ sb.append(op);
}
return sb;
}
+ private void sortOperandsIfNeeded(StringBuilder sb,
+ List<RexNode> operands, List<String> operandDigests) {
+ if (operands.isEmpty() || !needNormalize()) {
+ return;
+ }
+ final SqlKind kind = op.getKind();
+ if (SqlKind.SYMMETRICAL_SAME_ARG_TYPE.contains(kind)) {
+ final RelDataType firstType = operands.get(0).getType();
+ for (int i = 1; i < operands.size(); i++) {
+ if (!equalSansNullability(firstType, operands.get(i).getType())) {
+ // Arguments have different type, thus they must not be sorted
Review comment:
Oh, you mis-understood what i mean, i means to support more reordering for `PLUS` and `TIMES` even their operands types are different. For example, `DECIMAL(3,0) + DECIMAL(5,0)` can also be reordered.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] xndai commented on issue #1740: [CALCITE-3713] Remove
column names from Project#digest
Posted by GitBox <gi...@apache.org>.
xndai commented on issue #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#issuecomment-584414573
@vlsi I wonder why we couldn't just remove the column name in RelRecordType::generateTypeString()? We wouldn't have perf regression if it had been done this way. Had this idea been brought up during review? What prevented us from doing that? Thanks.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] vlsi commented on issue #1740: [CALCITE-3713] Remove
column names from Project#digest
Posted by GitBox <gi...@apache.org>.
vlsi commented on issue #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#issuecomment-584754624
Just in case. Removal of the field names from `RelRecordType::generateTypeString` produces extreme amount of test failures: https://github.com/apache/calcite/pull/1797
So it does not look like we can make such a change.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] vlsi commented on a change in pull request #1740:
[CALCITE-3713] Remove column names from Project#digest
Posted by GitBox <gi...@apache.org>.
vlsi commented on a change in pull request #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#discussion_r365095837
##########
File path: core/src/main/java/org/apache/calcite/rex/RexCall.java
##########
@@ -127,11 +137,83 @@ protected final StringBuilder appendOperands(StringBuilder sb) {
includeType = RexDigestIncludeType.NO_TYPE;
}
}
- sb.append(((RexLiteral) operand).computeDigest(includeType));
+ operandDigests.add(((RexLiteral) operand).computeDigest(includeType));
+ }
+ int totalLength = (operandDigests.size() - 1) * 2; // commas
+ for (String s : operandDigests) {
+ totalLength += s.length();
+ }
+ sb.ensureCapacity(sb.length() + totalLength);
+ sortOperandsIfNeeded(sb, operands, operandDigests);
+ for (int i = 0; i < operandDigests.size(); i++) {
+ String op = operandDigests.get(i);
+ if (i != 0) {
+ sb.append(", ");
+ }
+ sb.append(op);
}
return sb;
}
+ private void sortOperandsIfNeeded(StringBuilder sb,
+ List<RexNode> operands, List<String> operandDigests) {
+ if (operands.isEmpty() || !needNormalize()) {
+ return;
+ }
+ final SqlKind kind = op.getKind();
+ if (SqlKind.SYMMETRICAL_SAME_ARG_TYPE.contains(kind)) {
+ final RelDataType firstType = operands.get(0).getType();
+ for (int i = 1; i < operands.size(); i++) {
+ if (!equalSansNullability(firstType, operands.get(i).getType())) {
+ // Arguments have different type, thus they must not be sorted
Review comment:
I do not follow you.
I ensure the operands have to be of the same type, so I don't see why we should reject reordering in `DECIMAL(5,0) + DECIMAL(5,0)`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] hsyuan commented on issue #1740: [CALCITE-3713] Remove
column names from Project#digest
Posted by GitBox <gi...@apache.org>.
hsyuan commented on issue #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#issuecomment-583657873
Without this patch:

With this patch:

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] vlsi commented on a change in pull request #1740:
[CALCITE-3713] Remove column names from Project#digest
Posted by GitBox <gi...@apache.org>.
vlsi commented on a change in pull request #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#discussion_r365316717
##########
File path: core/src/main/java/org/apache/calcite/rex/RexCall.java
##########
@@ -127,11 +137,83 @@ protected final StringBuilder appendOperands(StringBuilder sb) {
includeType = RexDigestIncludeType.NO_TYPE;
}
}
- sb.append(((RexLiteral) operand).computeDigest(includeType));
+ operandDigests.add(((RexLiteral) operand).computeDigest(includeType));
+ }
+ int totalLength = (operandDigests.size() - 1) * 2; // commas
+ for (String s : operandDigests) {
+ totalLength += s.length();
+ }
+ sb.ensureCapacity(sb.length() + totalLength);
+ sortOperandsIfNeeded(sb, operands, operandDigests);
+ for (int i = 0; i < operandDigests.size(); i++) {
+ String op = operandDigests.get(i);
+ if (i != 0) {
+ sb.append(", ");
+ }
+ sb.append(op);
}
return sb;
}
+ private void sortOperandsIfNeeded(StringBuilder sb,
+ List<RexNode> operands, List<String> operandDigests) {
+ if (operands.isEmpty() || !needNormalize()) {
+ return;
+ }
+ final SqlKind kind = op.getKind();
+ if (SqlKind.SYMMETRICAL_SAME_ARG_TYPE.contains(kind)) {
+ final RelDataType firstType = operands.get(0).getType();
+ for (int i = 1; i < operands.size(); i++) {
+ if (!equalSansNullability(firstType, operands.get(i).getType())) {
+ // Arguments have different type, thus they must not be sorted
Review comment:
In production the types will be the same: https://twitter.com/pysailor_de/status/1213126545642065920 :)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] julianhyde commented on issue #1740: [CALCITE-3713]
Remove column names from Project#digest
Posted by GitBox <gi...@apache.org>.
julianhyde commented on issue #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#issuecomment-584933425
Can we move the discussion to JIRA? I never look at closed pull requests, so we're shouting into the void.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] vlsi commented on issue #1740: [CALCITE-3713] Remove
column names from Project#digest
Posted by GitBox <gi...@apache.org>.
vlsi commented on issue #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#issuecomment-584851082
I wonder what @julianhyde and @zabetak think of https://github.com/apache/calcite/pull/1740#issuecomment-584848797
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] zabetak commented on issue #1740: [CALCITE-3713] Remove
column names from Project#digest
Posted by GitBox <gi...@apache.org>.
zabetak commented on issue #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#issuecomment-585133377
Since https://issues.apache.org/jira/browse/CALCITE-3785 was logged for this purpose, I guess we should continue the discussion there.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] vlsi commented on issue #1740: [CALCITE-3713] Remove
column names from Project#digest
Posted by GitBox <gi...@apache.org>.
vlsi commented on issue #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#issuecomment-584848797
> second string is the new digest
The use of stings for digests is unfortunate. It takes time to build a string, however in practice we don't need that as a single object.
What I mean is something behind the lines of
```java
class RelDataType {
Digest digest;
Digest getDigestsSansFieldNames() {
Digest digest = this.digset;
if (digest != null) return digest;
this.digest = digest = ...;
return digest;
}
}
class Digest {
final int hashCode;
final Object[] contents;
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] danny0405 commented on a change in pull request #1740:
[CALCITE-3713] Remove column names from Project#digest
Posted by GitBox <gi...@apache.org>.
danny0405 commented on a change in pull request #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#discussion_r365116823
##########
File path: core/src/main/java/org/apache/calcite/rex/RexCall.java
##########
@@ -127,11 +137,83 @@ protected final StringBuilder appendOperands(StringBuilder sb) {
includeType = RexDigestIncludeType.NO_TYPE;
}
}
- sb.append(((RexLiteral) operand).computeDigest(includeType));
+ operandDigests.add(((RexLiteral) operand).computeDigest(includeType));
+ }
+ int totalLength = (operandDigests.size() - 1) * 2; // commas
+ for (String s : operandDigests) {
+ totalLength += s.length();
+ }
+ sb.ensureCapacity(sb.length() + totalLength);
+ sortOperandsIfNeeded(sb, operands, operandDigests);
+ for (int i = 0; i < operandDigests.size(); i++) {
+ String op = operandDigests.get(i);
+ if (i != 0) {
+ sb.append(", ");
+ }
+ sb.append(op);
}
return sb;
}
+ private void sortOperandsIfNeeded(StringBuilder sb,
+ List<RexNode> operands, List<String> operandDigests) {
+ if (operands.isEmpty() || !needNormalize()) {
+ return;
+ }
+ final SqlKind kind = op.getKind();
+ if (SqlKind.SYMMETRICAL_SAME_ARG_TYPE.contains(kind)) {
+ final RelDataType firstType = operands.get(0).getType();
+ for (int i = 1; i < operands.size(); i++) {
+ if (!equalSansNullability(firstType, operands.get(i).getType())) {
+ // Arguments have different type, thus they must not be sorted
Review comment:
I agree for the first iteration, we can keep it as simple as possible.
Why do you think `PLUS` for different data types are rare cases, i believe there would be many cases in production ~
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] vlsi commented on issue #1740: [CALCITE-3713] Remove
column names from Project#digest
Posted by GitBox <gi...@apache.org>.
vlsi commented on issue #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#issuecomment-584850203
> We don't build strings over and over
Every time we create a new RelType we build stings.
Every time we create RelNode we build strings.
Every time we create RexNode we build strings.
This is relevant: https://issues.apache.org/jira/browse/CALCITE-3784
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] danny0405 commented on a change in pull request #1740:
[CALCITE-3713] Remove column names from Project#digest
Posted by GitBox <gi...@apache.org>.
danny0405 commented on a change in pull request #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#discussion_r365070061
##########
File path: core/src/main/java/org/apache/calcite/rex/RexCall.java
##########
@@ -127,11 +137,83 @@ protected final StringBuilder appendOperands(StringBuilder sb) {
includeType = RexDigestIncludeType.NO_TYPE;
}
}
- sb.append(((RexLiteral) operand).computeDigest(includeType));
+ operandDigests.add(((RexLiteral) operand).computeDigest(includeType));
+ }
+ int totalLength = (operandDigests.size() - 1) * 2; // commas
+ for (String s : operandDigests) {
+ totalLength += s.length();
+ }
+ sb.ensureCapacity(sb.length() + totalLength);
+ sortOperandsIfNeeded(sb, operands, operandDigests);
+ for (int i = 0; i < operandDigests.size(); i++) {
+ String op = operandDigests.get(i);
+ if (i != 0) {
+ sb.append(", ");
+ }
+ sb.append(op);
}
return sb;
}
+ private void sortOperandsIfNeeded(StringBuilder sb,
+ List<RexNode> operands, List<String> operandDigests) {
+ if (operands.isEmpty() || !needNormalize()) {
+ return;
+ }
+ final SqlKind kind = op.getKind();
+ if (SqlKind.SYMMETRICAL_SAME_ARG_TYPE.contains(kind)) {
+ final RelDataType firstType = operands.get(0).getType();
+ for (int i = 1; i < operands.size(); i++) {
+ if (!equalSansNullability(firstType, operands.get(i).getType())) {
+ // Arguments have different type, thus they must not be sorted
Review comment:
We can make a sort if:
1. There is no decimals in the `PLUS`
2. There is no `INTERVAL`s in `TIMES`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] xndai commented on issue #1740: [CALCITE-3713] Remove
column names from Project#digest
Posted by GitBox <gi...@apache.org>.
xndai commented on issue #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#issuecomment-584911960
>Every time we create a new RelType we build stings.
Every time we create RelNode we build strings.
Every time we create RexNode we build strings.
Yes, but if not string, you would be creating something else.
I am fine with the initial overhead. But we cannot afford recomputing hash code every time when access the map. Unfortunately this is what List<RelDataType> does with your change.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] vlsi commented on issue #1740: [CALCITE-3713] Remove
column names from Project#digest
Posted by GitBox <gi...@apache.org>.
vlsi commented on issue #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#issuecomment-585166370
I've created https://issues.apache.org/jira/browse/CALCITE-3786 for Digest.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] xndai commented on issue #1740: [CALCITE-3713] Remove
column names from Project#digest
Posted by GitBox <gi...@apache.org>.
xndai commented on issue #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#issuecomment-584783530
Now the problem is every time when we access mapDigestToRel, we would have to recompute the hash code of List<RelDataType>, which is a considerable overhead. It not only affects Hep planner, but also VolcanoPlanner.
We could have another member variable in RelRecordType for digest without column name. Then somehow expose it as the hash string for a wrapper class on top of RelRecordType. Then mapToDigest would become Map<Pair<String, RelRecordTypeWrapper>, HepRelVertex>. This will solve the problem of re-hasing, but it increase the memory usage by having an additional digest member.
I think the best way would be removing column name from RelRecordType digest. I understand it breaks the UT currently, but we should spend time understanding why if we believe this's the right solution.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] vlsi commented on a change in pull request #1740:
[CALCITE-3713] Remove column names from Project#digest
Posted by GitBox <gi...@apache.org>.
vlsi commented on a change in pull request #1740: [CALCITE-3713] Remove column names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#discussion_r365091952
##########
File path: core/src/main/java/org/apache/calcite/rex/RexCall.java
##########
@@ -127,11 +137,83 @@ protected final StringBuilder appendOperands(StringBuilder sb) {
includeType = RexDigestIncludeType.NO_TYPE;
}
}
- sb.append(((RexLiteral) operand).computeDigest(includeType));
+ operandDigests.add(((RexLiteral) operand).computeDigest(includeType));
+ }
+ int totalLength = (operandDigests.size() - 1) * 2; // commas
+ for (String s : operandDigests) {
+ totalLength += s.length();
+ }
+ sb.ensureCapacity(sb.length() + totalLength);
+ sortOperandsIfNeeded(sb, operands, operandDigests);
+ for (int i = 0; i < operandDigests.size(); i++) {
+ String op = operandDigests.get(i);
+ if (i != 0) {
+ sb.append(", ");
+ }
+ sb.append(op);
}
return sb;
}
+ private void sortOperandsIfNeeded(StringBuilder sb,
+ List<RexNode> operands, List<String> operandDigests) {
+ if (operands.isEmpty() || !needNormalize()) {
+ return;
+ }
+ final SqlKind kind = op.getKind();
+ if (SqlKind.SYMMETRICAL_SAME_ARG_TYPE.contains(kind)) {
+ final RelDataType firstType = operands.get(0).getType();
+ for (int i = 1; i < operands.size(); i++) {
+ if (!equalSansNullability(firstType, operands.get(i).getType())) {
+ // Arguments have different type, thus they must not be sorted
Review comment:
Why drop decimals?
Why drop INTERVAL?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services