ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [9/9] ignite git commit: Skip merge table query.
Date Tue, 24 Nov 2015 14:53:24 GMT
Skip merge table query.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f495cba8
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f495cba8
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f495cba8

Branch: refs/heads/ignite-sql-cache-stmt
Commit: f495cba81ecaeb7164af942973888fdbab724439
Parents: 8a3770e
Author: sboikov <sboikov@gridgain.com>
Authored: Tue Nov 24 17:53:04 2015 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Tue Nov 24 17:53:04 2015 +0300

----------------------------------------------------------------------
 .../cache/query/GridCacheSqlQuery.java          | 20 --------
 .../cache/query/GridCacheTwoStepQuery.java      | 25 ++++++++--
 .../processors/query/h2/IgniteH2Indexing.java   | 52 ++++++--------------
 .../query/h2/sql/GridSqlQuerySplitter.java      | 40 ++-------------
 .../processors/query/h2/sql/GridSqlSelect.java  | 35 +++++++++++++
 .../h2/twostep/GridReduceQueryExecutor.java     |  2 +-
 6 files changed, 77 insertions(+), 97 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f495cba8/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlQuery.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlQuery.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlQuery.java
index 49a926a..e56e445 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlQuery.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlQuery.java
@@ -70,10 +70,6 @@ public class GridCacheSqlQuery implements Message {
     /** Field kept for backward compatibility. */
     private String alias;
 
-    /** */
-    @GridDirectTransient
-    private boolean skipMergeTbl;
-
     /**
      * For {@link Message}.
      */
@@ -246,21 +242,6 @@ public class GridCacheSqlQuery implements Message {
     }
 
     /**
-     * @return {@code True} if reduce query can skip merge table creation and get data directly
from merge index.
-     */
-    public boolean skipMergeTable() {
-        return skipMergeTbl;
-    }
-
-    /**
-     * @param skipMergeTbl {@code True} if reduce query can skip merge table creation and
get
-     *      data directly from merge index.
-     */
-    public void skipMergeTable(boolean skipMergeTbl) {
-        this.skipMergeTbl = skipMergeTbl;
-    }
-
-    /**
      * @param args Arguments.
      * @return Copy.
      */
@@ -271,7 +252,6 @@ public class GridCacheSqlQuery implements Message {
         cp.cols = cols;
         cp.paramIdxs = paramIdxs;
         cp.paramsSize = paramsSize;
-        cp.skipMergeTbl = skipMergeTbl;
 
         if (F.isEmpty(args))
             cp.params = EMPTY_PARAMS;

http://git-wip-us.apache.org/repos/asf/ignite/blob/f495cba8/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java
index 1946a4c..e500fa1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java
@@ -47,16 +47,35 @@ public class GridCacheTwoStepQuery {
     /** */
     private Set<String> spaces;
 
+    /** */
+    private boolean skipMergeTbl;
+
     /**
      * @param spaces All spaces accessed in query.
      * @param rdc Reduce query.
+     * @param skipMergeTbl {@code True} if reduce query can skip merge table creation and
+     *      get data directly from merge index.
      */
-    public GridCacheTwoStepQuery(Set<String> spaces, GridCacheSqlQuery rdc) {
+    public GridCacheTwoStepQuery(Set<String> spaces, GridCacheSqlQuery rdc, boolean
skipMergeTbl) {
         assert rdc != null;
 
         this.spaces = spaces;
-
         this.rdc = rdc;
+        this.skipMergeTbl = skipMergeTbl;
+    }
+    /**
+     * @return {@code True} if reduce query can skip merge table creation and get data directly
from merge index.
+     */
+    public boolean skipMergeTable() {
+        return skipMergeTbl;
+    }
+
+    /**
+     * @param skipMergeTbl {@code True} if reduce query can skip merge table creation and
get
+     *      data directly from merge index.
+     */
+    public void skipMergeTable(boolean skipMergeTbl) {
+        this.skipMergeTbl = skipMergeTbl;
     }
 
     /**
@@ -132,7 +151,7 @@ public class GridCacheTwoStepQuery {
     public GridCacheTwoStepQuery copy(Object[] args) {
         assert !explain;
 
-        GridCacheTwoStepQuery cp = new GridCacheTwoStepQuery(spaces, rdc.copy(args));
+        GridCacheTwoStepQuery cp = new GridCacheTwoStepQuery(spaces, rdc.copy(args), skipMergeTbl);
         cp.pageSize = pageSize;
         for (int i = 0; i < mapQrys.size(); i++)
             cp.mapQrys.add(mapQrys.get(i).copy(args));

http://git-wip-us.apache.org/repos/asf/ignite/blob/f495cba8/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
index 96409f6..76e538f 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
@@ -100,7 +100,6 @@ import org.apache.ignite.internal.util.lang.GridCloseableIterator;
 import org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeGuard;
 import org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMemory;
 import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.T2;
 import org.apache.ignite.internal.util.typedef.T3;
 import org.apache.ignite.internal.util.typedef.internal.LT;
 import org.apache.ignite.internal.util.typedef.internal.S;
@@ -199,6 +198,8 @@ public class IgniteH2Indexing implements GridQueryIndexing {
      */
     static {
         try {
+            System.setProperty("h2.objectCache", "false");
+
             COMMAND_FIELD = JdbcPreparedStatement.class.getDeclaredField("command");
 
             COMMAND_FIELD.setAccessible(true);
@@ -251,6 +252,8 @@ public class IgniteH2Indexing implements GridQueryIndexing {
                 c = initialValue();
 
                 set(c);
+
+                stmtCache.get().clear();
             }
 
             return c;
@@ -276,12 +279,11 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     private volatile GridKernalContext ctx;
 
     /** */
-    private final ThreadLocal<StatementCache<String, PreparedStatement>> stmtCache
=
-        new ThreadLocal<StatementCache<String, PreparedStatement>>() {
-            @Override protected StatementCache<String, PreparedStatement> initialValue()
{
-                return new StatementCache<>(PREPARED_STMT_CACHE_SIZE);
-            }
-        };
+    private final ThreadLocal<StatementCache> stmtCache = new ThreadLocal<StatementCache>()
{
+        @Override protected StatementCache initialValue() {
+            return new StatementCache(PREPARED_STMT_CACHE_SIZE);
+        }
+    };
 
     /** */
     private final GridBoundedConcurrentLinkedHashMap<T3<String, String, Boolean>,
TwoStepCachedQuery> twoStepCache =
@@ -309,7 +311,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
      */
     private PreparedStatement prepareStatement(Connection c, String sql, boolean useStmtCache)
throws SQLException {
         if (useStmtCache) {
-            StatementCache<String, PreparedStatement> cache = stmtCache.get();
+            StatementCache cache = stmtCache.get();
 
             PreparedStatement stmt = cache.get(sql);
 
@@ -323,11 +325,6 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
             cache.put(sql, stmt);
 
-            PreparedStatement rmvd = cache.getAndClearRemoved();
-
-            if (rmvd != null)
-                U.closeQuiet(rmvd);
-
             return stmt;
         }
         else
@@ -2400,13 +2397,10 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     /**
      *
      */
-    private static class StatementCache<K, V> extends LinkedHashMap<K, V> {
+    private static class StatementCache extends LinkedHashMap<String, PreparedStatement>
{
         /** */
         private int size;
 
-        /** */
-        private V rmvd;
-
         /**
          * @param size Size.
          */
@@ -2417,30 +2411,16 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         }
 
         /** {@inheritDoc} */
-        @Override protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
-            assert rmvd == null;
-
+        @Override protected boolean removeEldestEntry(Map.Entry<String, PreparedStatement>
eldest) {
             boolean rmv = size() > size;
 
-            if (rmv)
-                this.rmvd = eldest.getValue();
-
-            return rmv;
-        }
-
-        /**
-         * @return Removed value.
-         */
-        @Nullable V getAndClearRemoved() {
-            if (rmvd != null) {
-                V ret = rmvd;
-
-                rmvd = null;
+            if (rmv) {
+                PreparedStatement stmt = eldest.getValue();
 
-                return ret;
+                U.closeQuiet(stmt);
             }
 
-            return null;
+            return rmv;
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/f495cba8/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
index 04d469b..0c9c8fe 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
@@ -173,46 +173,22 @@ public class GridSqlQuerySplitter {
         for (GridSqlElement exp : mapExps) // Add all map expressions as visible.
             mapQry.addColumn(exp, true);
 
-        boolean rdcSimpleQry = true;
-
-        for (GridSqlElement rdcExp : rdcExps) { // Add corresponding visible reduce columns.
+        for (GridSqlElement rdcExp : rdcExps) // Add corresponding visible reduce columns.
             rdcQry.addColumn(rdcExp, true);
 
-            if (rdcSimpleQry) {
-                if (rdcExp instanceof GridSqlColumn || rdcExp instanceof GridSqlConst)
-                    continue;
-
-                if (rdcExp instanceof GridSqlAlias) {
-                    if (rdcExp.size() == 1) {
-                        GridSqlElement child = rdcExp.child();
-
-                        if (child instanceof GridSqlColumn || child instanceof GridSqlConst)
-                            continue;
-                    }
-                }
-
-                rdcSimpleQry = false;
-            }
-        }
-
         for (int i = rdcExps.length; i < mapExps.size(); i++)  // Add all extra map columns
as invisible reduce columns.
             rdcQry.addColumn(column(((GridSqlAlias)mapExps.get(i)).alias()), false);
 
         // -- GROUP BY
-        if (mapQry.groupColumns() != null && !collocated) {
+        if (mapQry.groupColumns() != null && !collocated)
             rdcQry.groupColumns(mapQry.groupColumns());
 
-            rdcSimpleQry = false;
-        }
-
         // -- HAVING
         if (mapQry.havingColumn() >= 0 && !collocated) {
             // TODO IGNITE-1140 - Find aggregate functions in HAVING clause or rewrite query
to put all aggregates to SELECT clause.
             rdcQry.whereAnd(column(columnName(mapQry.havingColumn())));
 
             mapQry.havingColumn(-1);
-
-            rdcSimpleQry = false;
         }
 
         // -- ORDER BY
@@ -223,8 +199,6 @@ public class GridSqlQuerySplitter {
             if (aggregateFound) // Ordering over aggregates does not make sense.
                 mapQry.clearSort(); // Otherwise map sort will be used by offset-limit.
             // TODO IGNITE-1141 - Check if sorting is done over aggregated expression, otherwise
we can sort and use offset-limit.
-
-            rdcSimpleQry = false;
         }
 
         // -- LIMIT
@@ -233,8 +207,6 @@ public class GridSqlQuerySplitter {
 
             if (aggregateFound)
                 mapQry.limit(null);
-
-            rdcSimpleQry = false;
         }
 
         // -- OFFSET
@@ -245,16 +217,12 @@ public class GridSqlQuerySplitter {
                 mapQry.limit(op(GridSqlOperationType.PLUS, mapQry.offset(), mapQry.limit()));
 
             mapQry.offset(null);
-
-            rdcSimpleQry = false;
         }
 
         // -- DISTINCT
         if (mapQry.distinct()) {
             mapQry.distinct(!aggregateFound && mapQry.groupColumns() == null &&
mapQry.havingColumn() < 0);
             rdcQry.distinct(true);
-
-            rdcSimpleQry = false;
         }
 
         IntArray paramIdxs = new IntArray(params.length);
@@ -262,8 +230,6 @@ public class GridSqlQuerySplitter {
         GridCacheSqlQuery rdc = new GridCacheSqlQuery(rdcQry.getSQL(),
             findParams(rdcQry, params, new ArrayList<>(), paramIdxs).toArray());
 
-        rdc.skipMergeTable(rdcSimpleQry && paramIdxs.size() == 0);
-
         rdc.parameterIndexes(toIntArray(paramIdxs));
 
         paramIdxs = new IntArray(params.length);
@@ -275,7 +241,7 @@ public class GridSqlQuerySplitter {
         map.parameterIndexes(toIntArray(paramIdxs));
 
         // Build resulting two step query.
-        GridCacheTwoStepQuery res = new GridCacheTwoStepQuery(spaces, rdc).addMapQuery(map);
+        GridCacheTwoStepQuery res = new GridCacheTwoStepQuery(spaces, rdc, rdcQry.simpleQuery()).addMapQuery(map);
 
         res.explain(explain);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/f495cba8/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java
index e537ace..ff57362 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java
@@ -103,6 +103,41 @@ public class GridSqlSelect extends GridSqlQuery {
     }
 
     /**
+     * @return {@code True} if this simple select.
+     */
+    public boolean simpleQuery() {
+        boolean simple = !distinct &&
+            where == null &&
+            grpCols == null &&
+            havingCol < 0 &&
+            sort.isEmpty() &&
+            limit == null &&
+            offset == null;
+
+        if (simple) {
+            for (GridSqlElement expression : columns(true)) {
+                if (expression instanceof GridSqlColumn)
+                    continue;
+
+                if (expression instanceof GridSqlAlias) {
+                    if (expression.size() == 1) {
+                        GridSqlElement child = expression.child();
+
+                        if (child instanceof GridSqlColumn)
+                            continue;
+                    }
+                }
+
+                simple = false;
+
+                break;
+            }
+        }
+
+        return simple;
+    }
+
+    /**
      * @param buff Statement builder.
      * @param expression Alias expression.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/f495cba8/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
index a57366d..bab88a7 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
@@ -512,7 +512,7 @@ public class GridReduceQueryExecutor {
 
             int tblIdx = 0;
 
-            final boolean skipMergeTbl = !qry.explain() && qry.reduceQuery().skipMergeTable();
+            final boolean skipMergeTbl = !qry.explain() && qry.skipMergeTable();
 
             for (GridCacheSqlQuery mapQry : qry.mapQueries()) {
                 GridMergeIndex idx;


Mime
View raw message