This is an automated email from the ASF dual-hosted git repository.

NSAmelchev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 138ce5e2822 IGNITE-29331 SQL Calcite: Do not build a digest of 
expressions on every execution of a cached plan (#13868)
138ce5e2822 is described below

commit 138ce5e28223397fab2442f8d69832c0f6662bb4
Author: Nikita Amelchev <[email protected]>
AuthorDate: Mon Nov 23 10:26:21 2026 +0300

    IGNITE-29331 SQL Calcite: Do not build a digest of expressions on every 
execution of a cached plan (#13868)
---
 .../calcite/exec/exp/ExpressionFactoryImpl.java    | 60 ++++++++++++++++++++--
 1 file changed, 55 insertions(+), 5 deletions(-)

diff --git 
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ExpressionFactoryImpl.java
 
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ExpressionFactoryImpl.java
index 35e05df36d6..93ce23bacec 100644
--- 
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ExpressionFactoryImpl.java
+++ 
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ExpressionFactoryImpl.java
@@ -29,6 +29,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.function.BiPredicate;
 import java.util.function.Function;
 import java.util.function.Predicate;
@@ -93,6 +94,9 @@ public class ExpressionFactoryImpl<Row> implements 
ExpressionFactory<Row> {
     /** */
     private static final Map<String, Scalar> SCALAR_CACHE = new 
GridBoundedConcurrentLinkedHashMap<>(1024);
 
+    /** Saves building a digest for expressions of a cached plan: they are the 
same instances on every execution. */
+    private static final Map<ExpressionsKey, Scalar> 
SCALAR_BY_EXPRESSIONS_CACHE = new GridBoundedConcurrentLinkedHashMap<>(1024);
+
     /** Placeholder for lowest possible value in range bound. This placeholder 
is only reqired to compare ranges. */
     private static final Object LOWEST_VALUE = new Object();
 
@@ -494,8 +498,7 @@ public class ExpressionFactoryImpl<Row> implements 
ExpressionFactory<Row> {
      * @return SingleScalar.
      */
     private SingleScalar scalar(List<RexNode> nodes, RelDataType type) {
-        return (SingleScalar)SCALAR_CACHE.computeIfAbsent(digest(nodes, type, 
false),
-            k -> compile(nodes, type, false));
+        return (SingleScalar)scalar(nodes, type, false);
     }
 
     /**
@@ -506,10 +509,13 @@ public class ExpressionFactoryImpl<Row> implements 
ExpressionFactory<Row> {
      * @return BiScalar.
      */
     private BiScalar biScalar(RexNode node, RelDataType type) {
-        ImmutableList<RexNode> nodes = ImmutableList.of(node);
+        return (BiScalar)scalar(ImmutableList.of(node), type, true);
+    }
 
-        return (BiScalar)SCALAR_CACHE.computeIfAbsent(digest(nodes, type, 
true),
-            k -> compile(nodes, type, true));
+    /** */
+    private Scalar scalar(List<RexNode> nodes, RelDataType type, boolean 
biInParams) {
+        return SCALAR_BY_EXPRESSIONS_CACHE.computeIfAbsent(new 
ExpressionsKey(nodes, type, biInParams),
+            k -> SCALAR_CACHE.computeIfAbsent(digest(nodes, type, biInParams), 
d -> compile(nodes, type, biInParams)));
     }
 
     /** */
@@ -1192,4 +1198,48 @@ public class ExpressionFactoryImpl<Row> implements 
ExpressionFactory<Row> {
             return variable;
         }
     }
+
+    /** */
+    private static class ExpressionsKey {
+        /** */
+        private final RexNode[] nodes;
+
+        /** */
+        private final RelDataType type;
+
+        /** */
+        private final boolean biInParams;
+
+        /** */
+        private ExpressionsKey(List<RexNode> nodes, RelDataType type, boolean 
biInParams) {
+            this.nodes = nodes.toArray(new RexNode[0]);
+            this.type = type;
+            this.biInParams = biInParams;
+        }
+
+        /** Expressions are compared by identity: equal ones can differ in 
details taken into account by the digest. */
+        @Override public boolean equals(Object o) {
+            ExpressionsKey key = (ExpressionsKey)o;
+
+            if (biInParams != key.biInParams || nodes.length != 
key.nodes.length || !Objects.equals(type, key.type))
+                return false;
+
+            for (int i = 0; i < nodes.length; i++) {
+                if (nodes[i] != key.nodes[i])
+                    return false;
+            }
+
+            return true;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            int res = 31 * Objects.hashCode(type) + 
Boolean.hashCode(biInParams);
+
+            for (RexNode node : nodes)
+                res = 31 * res + System.identityHashCode(node);
+
+            return res;
+        }
+    }
 }

Reply via email to