You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2017/05/31 11:53:06 UTC

ignite git commit: IGNITE-5320: Introduced "PUBLIC" SQL schema. This closes #2044.

Repository: ignite
Updated Branches:
  refs/heads/master c71b7c26d -> 738451c16


IGNITE-5320: Introduced "PUBLIC" SQL schema. This closes #2044.


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

Branch: refs/heads/master
Commit: 738451c16ec75b84c36bff7cd9dfbcf094c5b8ee
Parents: c71b7c2
Author: devozerov <vo...@gridgain.com>
Authored: Wed May 31 14:52:47 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Wed May 31 14:52:47 2017 +0300

----------------------------------------------------------------------
 .../ignite/cache/query/SqlFieldsQuery.java      |  24 ++++
 .../configuration/CacheConfiguration.java       |   6 +
 .../configuration/IgniteConfiguration.java      |  28 +++++
 .../ignite/internal/jdbc2/JdbcConnection.java   |  45 ++++---
 .../ignite/internal/jdbc2/JdbcQueryTask.java    |  11 +-
 .../ignite/internal/jdbc2/JdbcResultSet.java    |   5 +-
 .../ignite/internal/jdbc2/JdbcStatement.java    |  12 +-
 .../jdbc2/JdbcStreamedPreparedStatement.java    |   3 +-
 .../processors/query/GridQueryIndexing.java     |  27 +----
 .../processors/query/GridQueryProcessor.java    |  32 ++---
 .../internal/processors/query/QueryUtils.java   |   2 +
 .../processors/query/h2/H2RowDescriptor.java    |  35 ++++--
 .../internal/processors/query/h2/H2Schema.java  |  65 ++++-------
 .../processors/query/h2/H2TableDescriptor.java  |  25 ++--
 .../processors/query/h2/H2TableEngine.java      |   2 +-
 .../internal/processors/query/h2/H2Utils.java   |   2 +-
 .../processors/query/h2/IgniteH2Indexing.java   | 117 ++++++++++---------
 .../query/h2/opt/GridH2RowDescriptor.java       |   5 -
 .../processors/query/h2/opt/GridH2Table.java    |  25 ++--
 .../query/IgniteSqlSchemaIndexingTest.java      |   2 +-
 .../h2/GridIndexingSpiAbstractSelfTest.java     |   7 +-
 21 files changed, 265 insertions(+), 215 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/core/src/main/java/org/apache/ignite/cache/query/SqlFieldsQuery.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/SqlFieldsQuery.java b/modules/core/src/main/java/org/apache/ignite/cache/query/SqlFieldsQuery.java
index 9a7211b..93910dc 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/query/SqlFieldsQuery.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/query/SqlFieldsQuery.java
@@ -74,6 +74,9 @@ public class SqlFieldsQuery extends Query<List<?>> {
     /** Partitions for query */
     private int[] parts;
 
+    /** Schema. */
+    private String schema;
+
     /**
      * Constructs SQL fields query.
      *
@@ -287,6 +290,27 @@ public class SqlFieldsQuery extends Query<List<?>> {
         return this;
     }
 
+    /**
+     * Get schema.
+     *
+     * @return Schema.
+     */
+    @Nullable public String getSchema() {
+        return schema;
+    }
+
+    /**
+     * Set schema.
+     *
+     * @param schema Schema.
+     * @return {@code this} for chaining.
+     */
+    public SqlFieldsQuery setSchema(@Nullable String schema) {
+        this.schema = schema;
+
+        return this;
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(SqlFieldsQuery.class, this);

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
index 7269086..21f2fba 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
@@ -180,6 +180,7 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
     public static final IgnitePredicate<ClusterNode> ALL_NODES = new IgniteAllNodesPredicate();
 
     /** Default timeout after which long query warning will be printed. */
+    @Deprecated
     public static final long DFLT_LONG_QRY_WARN_TIMEOUT = 3000;
 
     /** Default number of queries detail metrics to collect. */
@@ -320,6 +321,7 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
     private Class<?>[] sqlFuncCls;
 
     /** */
+    @Deprecated
     private long longQryWarnTimeout = DFLT_LONG_QRY_WARN_TIMEOUT;
 
     /** */
@@ -1550,7 +1552,9 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      * Gets timeout in milliseconds after which long query warning will be printed.
      *
      * @return Timeout in milliseconds.
+     * @deprecated Use {@link IgniteConfiguration#getLongQueryWarningTimeout()} instead.
      */
+    @Deprecated
     public long getLongQueryWarningTimeout() {
         return longQryWarnTimeout;
     }
@@ -1560,7 +1564,9 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      *
      * @param longQryWarnTimeout Timeout in milliseconds.
      * @return {@code this} for chaining.
+     * @deprecated Use {@link IgniteConfiguration#setLongQueryWarningTimeout(long)} instead.
      */
+    @Deprecated
     public CacheConfiguration<K, V> setLongQueryWarningTimeout(long longQryWarnTimeout) {
         this.longQryWarnTimeout = longQryWarnTimeout;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
index 9f68399..89ab43e 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
@@ -204,6 +204,9 @@ public class IgniteConfiguration {
     @SuppressWarnings("UnnecessaryBoxing")
     public static final Long DFLT_CLIENT_FAILURE_DETECTION_TIMEOUT = new Long(30_000);
 
+    /** Default timeout after which long query warning will be printed. */
+    public static final long DFLT_LONG_QRY_WARN_TIMEOUT = 3000;
+
     /** Optional local Ignite instance name. */
     private String igniteInstanceName;
 
@@ -457,6 +460,9 @@ public class IgniteConfiguration {
     /** Active on start flag. */
     private boolean activeOnStart = DFLT_ACTIVE_ON_START;
 
+    /** */
+    private long longQryWarnTimeout = DFLT_LONG_QRY_WARN_TIMEOUT;
+
     /**
      * Creates valid grid configuration with all default values.
      */
@@ -520,6 +526,7 @@ public class IgniteConfiguration {
         lifecycleBeans = cfg.getLifecycleBeans();
         locHost = cfg.getLocalHost();
         log = cfg.getGridLogger();
+        longQryWarnTimeout = cfg.getLongQueryWarningTimeout();
         lsnrs = cfg.getLocalEventListeners();
         marsh = cfg.getMarshaller();
         marshLocJobs = cfg.isMarshalLocalJobs();
@@ -2714,6 +2721,27 @@ public class IgniteConfiguration {
         return this;
     }
 
+    /**
+     * Gets timeout in milliseconds after which long query warning will be printed.
+     *
+     * @return Timeout in milliseconds.
+     */
+    public long getLongQueryWarningTimeout() {
+        return longQryWarnTimeout;
+    }
+
+    /**
+     * Sets timeout in milliseconds after which long query warning will be printed.
+     *
+     * @param longQryWarnTimeout Timeout in milliseconds.
+     * @return {@code this} for chaining.
+     */
+    public IgniteConfiguration setLongQueryWarningTimeout(long longQryWarnTimeout) {
+        this.longQryWarnTimeout = longQryWarnTimeout;
+
+        return this;
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(IgniteConfiguration.class, this);

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcConnection.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcConnection.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcConnection.java
index 9385d7d..1bf51f2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcConnection.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcConnection.java
@@ -53,19 +53,17 @@ import org.apache.ignite.IgniteJdbcDriver;
 import org.apache.ignite.Ignition;
 import org.apache.ignite.cluster.ClusterGroup;
 import org.apache.ignite.compute.ComputeTaskTimeoutException;
-import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.IgnitionEx;
-import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
+import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor;
 import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode;
 import org.apache.ignite.internal.processors.query.GridQueryIndexing;
 import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.processors.query.QueryUtils;
 import org.apache.ignite.internal.processors.resource.GridSpringResourceContext;
 import org.apache.ignite.internal.util.future.GridFutureAdapter;
 import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiTuple;
 import org.apache.ignite.lang.IgniteCallable;
 import org.apache.ignite.resources.IgniteInstanceResource;
@@ -111,7 +109,10 @@ public class JdbcConnection implements Connection {
     private final String cfg;
 
     /** Cache name. */
-    private String cacheName;
+    private final String cacheName;
+
+    /** Schema name. */
+    private String schemaName;
 
     /** Closed flag. */
     private boolean closed;
@@ -162,6 +163,7 @@ public class JdbcConnection implements Connection {
      * @param props Additional properties.
      * @throws SQLException In case Ignite node failed to start.
      */
+    @SuppressWarnings("unchecked")
     public JdbcConnection(String url, Properties props) throws SQLException {
         assert url != null;
         assert props != null;
@@ -175,6 +177,10 @@ public class JdbcConnection implements Connection {
         txAllowed = Boolean.parseBoolean(props.getProperty(PROP_TX_ALLOWED));
 
         stream = Boolean.parseBoolean(props.getProperty(PROP_STREAMING));
+
+        if (stream && cacheName == null)
+            throw new SQLException("Cache name cannot be null when streaming is enabled.");
+
         streamAllowOverwrite = Boolean.parseBoolean(props.getProperty(PROP_STREAMING_ALLOW_OVERWRITE));
         streamFlushTimeout = Long.parseLong(props.getProperty(PROP_STREAMING_FLUSH_FREQ, "0"));
         streamNodeBufSize = Integer.parseInt(props.getProperty(PROP_STREAMING_PER_NODE_BUF_SIZE,
@@ -196,6 +202,17 @@ public class JdbcConnection implements Connection {
 
             if (!isValid(2))
                 throw new SQLException("Client is invalid. Probably cache name is wrong.");
+
+            if (cacheName != null) {
+                DynamicCacheDescriptor cacheDesc = ignite().context().cache().cacheDescriptor(cacheName);
+
+                if (cacheDesc == null)
+                    throw new SQLException("Cache doesn't exist: " + cacheName);
+
+                schemaName = QueryUtils.normalizeSchemaName(cacheName, cacheDesc.cacheConfiguration().getSqlSchema());
+            }
+            else
+                schemaName = QueryUtils.DFLT_SCHEMA;
         }
         catch (Exception e) {
             close();
@@ -722,18 +739,21 @@ public class JdbcConnection implements Connection {
     }
 
     /** {@inheritDoc} */
-    @Override public void setSchema(String schema) throws SQLException {
-        assert ignite instanceof IgniteEx;
-
-        cacheName = ((IgniteEx)ignite).context().query().cacheName(schema);
+    @Override public void setSchema(String schemaName) throws SQLException {
+        this.schemaName = schemaName;
     }
 
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
     @Override public String getSchema() throws SQLException {
-        String sqlSchema = ignite.cache(cacheName).getConfiguration(CacheConfiguration.class).getSqlSchema();
+        return schemaName;
+    }
 
-        return U.firstNotNull(sqlSchema, cacheName, "");
+    /**
+     * @return Normalized schema name.
+     */
+    public String schemaName() {
+        return F.isEmpty(schemaName) ? QueryUtils.DFLT_SCHEMA : schemaName;
     }
 
     /** {@inheritDoc} */
@@ -830,8 +850,7 @@ public class JdbcConnection implements Connection {
      * @return {@link PreparedStatement} from underlying engine to supply metadata to Prepared - most likely H2.
      */
     PreparedStatement prepareNativeStatement(String sql) throws SQLException {
-        return ((IgniteCacheProxy) ignite().cache(cacheName())).context()
-            .kernalContext().query().prepareNativeStatement(getSchema(), sql);
+        return ignite().context().query().prepareNativeStatement(schemaName(), sql);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcQueryTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcQueryTask.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcQueryTask.java
index 68ea4c2..7ae6ea2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcQueryTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcQueryTask.java
@@ -74,6 +74,9 @@ class JdbcQueryTask implements IgniteCallable<JdbcQueryTask.QueryResult> {
     /** Cache name. */
     private final String cacheName;
 
+    /** Schema name. */
+    private final String schemaName;
+
     /** Sql. */
     private final String sql;
 
@@ -101,6 +104,7 @@ class JdbcQueryTask implements IgniteCallable<JdbcQueryTask.QueryResult> {
     /**
      * @param ignite Ignite.
      * @param cacheName Cache name.
+     * @param schemaName Schema name.
      * @param sql Sql query.
      * @param isQry Operation type flag - query or not - to enforce query type check.
      * @param loc Local execution flag.
@@ -111,13 +115,13 @@ class JdbcQueryTask implements IgniteCallable<JdbcQueryTask.QueryResult> {
      * @param collocatedQry Collocated query flag.
      * @param distributedJoins Distributed joins flag.
      */
-    public JdbcQueryTask(Ignite ignite, String cacheName, String sql,
-                           Boolean isQry, boolean loc, Object[] args, int fetchSize, UUID uuid,
-                           boolean locQry, boolean collocatedQry, boolean distributedJoins) {
+    public JdbcQueryTask(Ignite ignite, String cacheName, String schemaName, String sql, Boolean isQry, boolean loc,
+        Object[] args, int fetchSize, UUID uuid, boolean locQry, boolean collocatedQry, boolean distributedJoins) {
         this.ignite = ignite;
         this.args = args;
         this.uuid = uuid;
         this.cacheName = cacheName;
+        this.schemaName = schemaName;
         this.sql = sql;
         this.isQry = isQry;
         this.fetchSize = fetchSize;
@@ -160,6 +164,7 @@ class JdbcQueryTask implements IgniteCallable<JdbcQueryTask.QueryResult> {
             qry.setLocal(locQry);
             qry.setCollocated(collocatedQry);
             qry.setDistributedJoins(distributedJoins);
+            qry.setSchema(schemaName);
 
             QueryCursorImpl<List<?>> qryCursor = (QueryCursorImpl<List<?>>)cache.withKeepBinary().query(qry);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcResultSet.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcResultSet.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcResultSet.java
index 10cf17a..01c6386 100755
--- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcResultSet.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcResultSet.java
@@ -146,8 +146,9 @@ public class JdbcResultSet implements ResultSet {
             boolean loc = nodeId == null;
 
             // Connections from new clients send queries with new tasks, so we have to continue in the same manner
-            JdbcQueryTask qryTask = new JdbcQueryTask(loc ? ignite : null, conn.cacheName(), null, true, loc, null,
-                fetchSize, uuid, conn.isLocalQuery(), conn.isCollocatedQuery(), conn.isDistributedJoins());
+            JdbcQueryTask qryTask = new JdbcQueryTask(loc ? ignite : null, conn.cacheName(), conn.schemaName(), null,
+                true, loc, null, fetchSize, uuid, conn.isLocalQuery(), conn.isCollocatedQuery(),
+                conn.isDistributedJoins());
 
             try {
                 JdbcQueryTask.QueryResult res =

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcStatement.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcStatement.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcStatement.java
index 81045b8..89a80ca 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcStatement.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcStatement.java
@@ -108,8 +108,8 @@ public class JdbcStatement implements Statement {
 
         boolean loc = nodeId == null;
 
-        JdbcQueryTask qryTask = new JdbcQueryTask(loc ? ignite : null, conn.cacheName(), sql, true, loc, getArgs(),
-            fetchSize, uuid, conn.isLocalQuery(), conn.isCollocatedQuery(), conn.isDistributedJoins());
+        JdbcQueryTask qryTask = new JdbcQueryTask(loc ? ignite : null, conn.cacheName(), conn.schemaName(), sql, true,
+            loc, getArgs(), fetchSize, uuid, conn.isLocalQuery(), conn.isCollocatedQuery(), conn.isDistributedJoins());
 
         try {
             JdbcQueryTask.QueryResult res =
@@ -165,8 +165,8 @@ public class JdbcStatement implements Statement {
         if (!conn.isDmlSupported())
             throw new SQLException("Failed to query Ignite: DML operations are supported in versions 1.8.0 and newer");
 
-        JdbcQueryTask qryTask = new JdbcQueryTask(loc ? ignite : null, conn.cacheName(), sql, false, loc, args,
-            fetchSize, uuid, conn.isLocalQuery(), conn.isCollocatedQuery(), conn.isDistributedJoins());
+        JdbcQueryTask qryTask = new JdbcQueryTask(loc ? ignite : null, conn.cacheName(), conn.schemaName(), sql, false,
+            loc, args, fetchSize, uuid, conn.isLocalQuery(), conn.isCollocatedQuery(), conn.isDistributedJoins());
 
         try {
             JdbcQueryTask.QueryResult qryRes =
@@ -332,8 +332,8 @@ public class JdbcStatement implements Statement {
 
         boolean loc = nodeId == null;
 
-        JdbcQueryTask qryTask = new JdbcQueryTask(loc ? ignite : null, conn.cacheName(), sql, null, loc, getArgs(),
-            fetchSize, uuid, conn.isLocalQuery(), conn.isCollocatedQuery(), conn.isDistributedJoins());
+        JdbcQueryTask qryTask = new JdbcQueryTask(loc ? ignite : null, conn.cacheName(), conn.schemaName(), sql, null,
+            loc, getArgs(), fetchSize, uuid, conn.isLocalQuery(), conn.isCollocatedQuery(), conn.isDistributedJoins());
 
         try {
             JdbcQueryTask.QueryResult res =

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcStreamedPreparedStatement.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcStreamedPreparedStatement.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcStreamedPreparedStatement.java
index 019923f..9f76700 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcStreamedPreparedStatement.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcStreamedPreparedStatement.java
@@ -54,6 +54,7 @@ class JdbcStreamedPreparedStatement extends JdbcPreparedStatement {
 
     /** {@inheritDoc} */
     @Override long doUpdate(String sql, Object[] args) throws SQLException {
-        return ((IgniteEx)conn.ignite()).context().query().streamUpdateQuery(conn.cacheName(), streamer, sql, args);
+        return conn.ignite().context().query().streamUpdateQuery(conn.cacheName(), conn.schemaName(),
+            streamer, sql, args);
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
index 4429058..031b5dd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
@@ -28,7 +28,6 @@ import org.apache.ignite.cache.query.FieldsQueryCursor;
 import org.apache.ignite.cache.query.QueryCursor;
 import org.apache.ignite.cache.query.SqlFieldsQuery;
 import org.apache.ignite.cache.query.SqlQuery;
-import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.CacheObject;
@@ -171,11 +170,10 @@ public interface GridQueryIndexing {
      * @param cacheName Cache name.
      * @param schemaName Schema name.
      * @param cctx Cache context.
-     * @param ccfg Cache configuration.
      * @throws IgniteCheckedException If failed.
      */
-    public void registerCache(String cacheName, String schemaName, GridCacheContext<?,?> cctx,
-        CacheConfiguration<?,?> ccfg) throws IgniteCheckedException;
+    public void registerCache(String cacheName, String schemaName, GridCacheContext<?,?> cctx)
+        throws IgniteCheckedException;
 
     /**
      * Unregisters cache.
@@ -188,21 +186,12 @@ public interface GridQueryIndexing {
     /**
      * Registers type if it was not known before or updates it otherwise.
      *
-     * @param cacheName Cache name.
+     * @param cctx Cache context.
      * @param desc Type descriptor.
      * @throws IgniteCheckedException If failed.
      * @return {@code True} if type was registered, {@code false} if for some reason it was rejected.
      */
-    public boolean registerType(String cacheName, GridQueryTypeDescriptor desc) throws IgniteCheckedException;
-
-    /**
-     * Unregisters type and removes all corresponding data.
-     *
-     * @param schemaName Schema name.
-     * @param typeName Type name.
-     * @throws IgniteCheckedException If failed.
-     */
-    public void unregisterType(String schemaName, String typeName) throws IgniteCheckedException;
+    public boolean registerType(GridCacheContext cctx, GridQueryTypeDescriptor desc) throws IgniteCheckedException;
 
     /**
      * Updates index. Note that key is unique for cache, so if cache contains multiple indexes
@@ -275,14 +264,6 @@ public interface GridQueryIndexing {
     public PreparedStatement prepareNativeStatement(String schemaName, String sql) throws SQLException;
 
     /**
-     * Gets cache name from database schema.
-     *
-     * @param schemaName Schema name. Could not be null. Could be empty.
-     * @return Cache name. Could be null.
-     */
-    public String cacheName(String schemaName);
-
-    /**
      * Collect queries that already running more than specified duration.
      *
      * @param duration Duration to check.

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index 990226e..fef7d4c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -1336,7 +1336,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         Collection<QueryTypeCandidate> cands) throws IgniteCheckedException {
         synchronized (stateMux) {
             if (idx != null)
-                idx.registerCache(cacheName, schemaName, cctx, cctx.config());
+                idx.registerCache(cacheName, schemaName, cctx);
 
             try {
                 for (QueryTypeCandidate cand : cands) {
@@ -1367,7 +1367,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                     }
 
                     if (idx != null)
-                        idx.registerType(cacheName, desc);
+                        idx.registerType(cctx, desc);
                 }
 
                 cacheNames.add(CU.mask(cacheName));
@@ -1732,7 +1732,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             throw new IllegalStateException("Failed to execute query (grid is stopping).");
 
         try {
-            final String schemaName = idx.schema(cctx.name());
+            final String schemaName = qry.getSchema() != null ? qry.getSchema() : idx.schema(cctx.name());
             final int mainCacheId = CU.cacheId(cctx.name());
 
             IgniteOutClosureX<FieldsQueryCursor<List<?>>> clo;
@@ -1782,13 +1782,11 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     /**
      * Query SQL fields without strict dependency on concrete cache.
      *
-     * @param schemaName Schema name.
      * @param qry Query.
      * @param keepBinary Keep binary flag.
-     * @return Cursot.
+     * @return Cursor.
      */
-    public FieldsQueryCursor<List<?>> querySqlFieldsNoCache(final String schemaName, final SqlFieldsQuery qry,
-        final boolean keepBinary) {
+    public FieldsQueryCursor<List<?>> querySqlFieldsNoCache(final SqlFieldsQuery qry, final boolean keepBinary) {
         checkxEnabled();
 
         validateSqlFieldsQuery(qry);
@@ -1796,6 +1794,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         if (qry.isLocal())
             throw new IgniteException("Local query is not supported without specific cache.");
 
+        if (qry.getSchema() == null)
+            throw new IgniteException("Query schema is not set.");
+
         if (!busyLock.enterBusy())
             throw new IllegalStateException("Failed to execute query (grid is stopping).");
 
@@ -1804,7 +1805,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                 @Override public FieldsQueryCursor<List<?>> applyx() throws IgniteCheckedException {
                     GridQueryCancel cancel = new GridQueryCancel();
 
-                    return idx.queryDistributedSqlFields(schemaName, qry, keepBinary, cancel, null);
+                    return idx.queryDistributedSqlFields(qry.getSchema(), qry, keepBinary, cancel, null);
                 }
             };
 
@@ -1833,11 +1834,12 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
     /**
      * @param cacheName Cache name.
+     * @param schemaName Schema name.
      * @param streamer Data streamer.
      * @param qry Query.
      * @return Iterator.
      */
-    public long streamUpdateQuery(@Nullable final String cacheName,
+    public long streamUpdateQuery(@Nullable final String cacheName, final String schemaName,
         final IgniteDataStreamer<?, ?> streamer, final String qry, final Object[] args) {
         assert streamer != null;
 
@@ -1847,8 +1849,6 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         try {
             GridCacheContext cctx = ctx.cache().cache(cacheName).context();
 
-            final String schemaName = idx.schema(cacheName);
-
             return executeQuery(GridCacheQueryType.SQL_FIELDS, qry, cctx, new IgniteOutClosureX<Long>() {
                 @Override public Long applyx() throws IgniteCheckedException {
                     return idx.streamUpdateQuery(schemaName, qry, args, streamer);
@@ -2106,16 +2106,6 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
-     * @param schema Schema name.
-     * @return Cache name from schema name.
-     */
-    public String cacheName(String schema) throws SQLException {
-        checkxEnabled();
-
-        return idx.cacheName(schema);
-    }
-
-    /**
      * @param cacheName Cache name.
      * @param key Key.
      * @throws IgniteCheckedException Thrown in case of any errors.

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
index b4feea4..51648e5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
@@ -63,6 +63,8 @@ import static org.apache.ignite.IgniteSystemProperties.getInteger;
  * Utility methods for queries.
  */
 public class QueryUtils {
+    /** Default schema. */
+    public static final String DFLT_SCHEMA = "PUBLIC";
 
     /** Field name for key. */
     public static final String KEY_FIELD_NAME = "_KEY";

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java
index 327ca14..a9bbd23 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java
@@ -18,7 +18,6 @@
 package org.apache.ignite.internal.processors.query.h2;
 
 import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
@@ -34,6 +33,7 @@ import org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject
 import org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeGuard;
 import org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMemory;
 import org.h2.message.DbException;
+import org.h2.mvstore.cache.CacheLongKeyLIRS;
 import org.h2.result.SearchRow;
 import org.h2.result.SimpleRow;
 import org.h2.value.DataType;
@@ -56,6 +56,7 @@ import org.h2.value.ValueString;
 import org.h2.value.ValueTime;
 import org.h2.value.ValueTimestamp;
 import org.h2.value.ValueUuid;
+import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import java.math.BigDecimal;
@@ -80,6 +81,9 @@ public class H2RowDescriptor implements GridH2RowDescriptor {
     /** Indexing SPI. */
     private final IgniteH2Indexing idx;
 
+    /** Table descriptor. */
+    private final H2TableDescriptor tbl;
+
     /** */
     private final GridQueryTypeDescriptor type;
 
@@ -114,14 +118,19 @@ public class H2RowDescriptor implements GridH2RowDescriptor {
     private final int valueAliasColumnId;
 
     /**
+     * Constructor.
+     *
+     * @param idx Indexing.
+     * @param tbl Table.
      * @param type Type descriptor.
      * @param schema Schema.
      */
-    H2RowDescriptor(IgniteH2Indexing idx, GridQueryTypeDescriptor type, H2Schema schema) {
+    H2RowDescriptor(IgniteH2Indexing idx, H2TableDescriptor tbl, GridQueryTypeDescriptor type, H2Schema schema) {
         assert type != null;
         assert schema != null;
 
         this.idx = idx;
+        this.tbl = tbl;
         this.type = type;
         this.schema = schema;
 
@@ -177,12 +186,7 @@ public class H2RowDescriptor implements GridH2RowDescriptor {
 
     /** {@inheritDoc} */
     @Override public GridCacheContext<?, ?> context() {
-        return schema.cacheContext();
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheConfiguration configuration() {
-        return schema.cacheContext().config();
+        return tbl.cache();
     }
 
     /** {@inheritDoc} */
@@ -196,12 +200,12 @@ public class H2RowDescriptor implements GridH2RowDescriptor {
 
         assert ptr > 0 : ptr;
 
-        schema.rowCache().put(ptr, row);
+        rowCache().put(ptr, row);
     }
 
     /** {@inheritDoc} */
     @Override public void uncache(long ptr) {
-        schema.rowCache().remove(ptr);
+        rowCache().remove(ptr);
     }
 
     /** {@inheritDoc} */
@@ -348,7 +352,7 @@ public class H2RowDescriptor implements GridH2RowDescriptor {
 
     /** {@inheritDoc} */
     @Override public GridH2KeyValueRowOffheap createPointer(long ptr) {
-        GridH2KeyValueRowOffheap row = (GridH2KeyValueRowOffheap)schema.rowCache().get(ptr);
+        GridH2KeyValueRowOffheap row = (GridH2KeyValueRowOffheap)rowCache().get(ptr);
 
         if (row != null) {
             assert row.pointer() == ptr : ptr + " " + row.pointer();
@@ -361,7 +365,7 @@ public class H2RowDescriptor implements GridH2RowDescriptor {
 
     /** {@inheritDoc} */
     @Override public GridH2Row cachedRow(long link) {
-        return schema.rowCache().get(link);
+        return rowCache().get(link);
     }
 
     /** {@inheritDoc} */
@@ -475,4 +479,11 @@ public class H2RowDescriptor implements GridH2RowDescriptor {
 
         return colId;
     }
+
+    /**
+     * @return Row cache.
+     */
+    @NotNull private CacheLongKeyLIRS<GridH2Row> rowCache() {
+        throw new UnsupportedOperationException(); // TODO: Unused for not.
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Schema.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Schema.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Schema.java
index 8dd87c0..deca4b2 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Schema.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Schema.java
@@ -17,10 +17,7 @@
 
 package org.apache.ignite.internal.processors.query.h2;
 
-import org.apache.ignite.internal.processors.cache.GridCacheContext;
-import org.apache.ignite.internal.processors.query.h2.opt.GridH2Row;
 import org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMemory;
-import org.h2.mvstore.cache.CacheLongKeyLIRS;
 import org.jsr166.ConcurrentHashMap8;
 
 import java.util.Collection;
@@ -31,9 +28,6 @@ import java.util.concurrent.ConcurrentMap;
  */
 public class H2Schema {
     /** */
-    private final String cacheName;
-
-    /** */
     private final String schemaName;
 
     /** */
@@ -45,37 +39,13 @@ public class H2Schema {
     /** */
     private final ConcurrentMap<String, H2TableDescriptor> typeToTbl = new ConcurrentHashMap8<>();
 
-    /** Cache for deserialized offheap rows. */
-    private final CacheLongKeyLIRS<GridH2Row> rowCache;
-
-    /** */
-    private final GridCacheContext<?, ?> cctx;
-
     /**
-     * @param cacheName Cache name.
+     * Constructor.
+     *
      * @param schemaName Schema name.
-     * @param cctx Cache context.
      */
-    public H2Schema(String cacheName, String schemaName, GridCacheContext<?, ?> cctx) {
-        this.cacheName = cacheName;
-        this.cctx = cctx;
+    public H2Schema(String schemaName) {
         this.schemaName = schemaName;
-
-        rowCache = null;
-    }
-
-    /**
-     * @return Cache context.
-     */
-    public GridCacheContext cacheContext() {
-        return cctx;
-    }
-
-    /**
-     * @return Cache name.
-     */
-    public String cacheName() {
-        return cacheName;
     }
 
     /**
@@ -93,13 +63,6 @@ public class H2Schema {
     }
 
     /**
-     * @return Row cache.
-     */
-    public CacheLongKeyLIRS<GridH2Row> rowCache() {
-        return rowCache;
-    }
-
-    /**
      * @return Tables.
      */
     public Collection<H2TableDescriptor> tables() {
@@ -138,14 +101,30 @@ public class H2Schema {
      */
     public void remove(H2TableDescriptor tbl) {
         tbls.remove(tbl.tableName());
+
+        typeToTbl.remove(tbl.typeName());
+    }
+
+    /**
+     * Drop table.
+     *
+     * @param tbl Table to be removed.
+     */
+    public void drop(H2TableDescriptor tbl) {
+        tbl.onDrop();
+
+        tbls.remove(tbl.tableName());
         typeToTbl.remove(tbl.typeName());
     }
 
     /**
      * Called after the schema was dropped.
      */
-    public void onDrop() {
-        for (H2TableDescriptor tblDesc : tbls.values())
-            tblDesc.onDrop();
+    public void dropAll() {
+        for (H2TableDescriptor tbl : tbls.values())
+            tbl.onDrop();
+
+        tbls.clear();
+        typeToTbl.clear();
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableDescriptor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableDescriptor.java
index eedfc3a..589f90e 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableDescriptor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableDescriptor.java
@@ -59,8 +59,8 @@ public class H2TableDescriptor implements GridH2SystemIndexFactory {
     /** */
     private final H2Schema schema;
 
-    /** Cache name. */
-    private final String cacheName;
+    /** Cache context. */
+    private final GridCacheContext cctx;
 
     /** */
     private GridH2Table tbl;
@@ -77,13 +77,14 @@ public class H2TableDescriptor implements GridH2SystemIndexFactory {
      * @param idx Indexing.
      * @param schema Schema.
      * @param type Type descriptor.
-     * @param cacheName Cache name.
+     * @param cctx Cache context.
      */
-    H2TableDescriptor(IgniteH2Indexing idx, H2Schema schema, GridQueryTypeDescriptor type, String cacheName) {
+    public H2TableDescriptor(IgniteH2Indexing idx, H2Schema schema, GridQueryTypeDescriptor type,
+        GridCacheContext cctx) {
         this.idx = idx;
         this.type = type;
         this.schema = schema;
-        this.cacheName = cacheName;
+        this.cctx = cctx;
 
         fullTblName = H2Utils.withQuotes(schema.schemaName()) + "." + H2Utils.withQuotes(type.tableName());
     }
@@ -145,10 +146,10 @@ public class H2TableDescriptor implements GridH2SystemIndexFactory {
     }
 
     /**
-     * @return Cache name.
+     * @return Cache context.
      */
-    String cacheName() {
-        return cacheName;
+    GridCacheContext cache() {
+        return cctx;
     }
 
     /**
@@ -177,8 +178,6 @@ public class H2TableDescriptor implements GridH2SystemIndexFactory {
      * @return H2 row factory.
      */
     H2RowFactory rowFactory(GridH2RowDescriptor rowDesc) {
-        GridCacheContext cctx = schema.cacheContext();
-
         if (cctx.affinityNode())
             return new H2RowFactory(rowDesc, cctx);
 
@@ -198,7 +197,6 @@ public class H2TableDescriptor implements GridH2SystemIndexFactory {
         GridH2RowDescriptor desc = tbl.rowDescriptor();
 
         Index hashIdx = createHashIndex(
-            schema,
             tbl,
             "_key_PK_hash",
             H2Utils.treeIndexColumns(desc, new ArrayList<IndexColumn>(2), keyCol, affCol)
@@ -322,15 +320,12 @@ public class H2TableDescriptor implements GridH2SystemIndexFactory {
     /**
      * Create hash index.
      *
-     * @param schema Schema.
      * @param tbl Table.
      * @param idxName Index name.
      * @param cols Columns.
      * @return Index.
      */
-    private Index createHashIndex(H2Schema schema, GridH2Table tbl, String idxName, List<IndexColumn> cols) {
-        GridCacheContext cctx = schema.cacheContext();
-
+    private Index createHashIndex(GridH2Table tbl, String idxName, List<IndexColumn> cols) {
         if (cctx.affinityNode()) {
             assert pkHashIdx == null : pkHashIdx;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableEngine.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableEngine.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableEngine.java
index db34064..57b7ba0 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableEngine.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2TableEngine.java
@@ -82,7 +82,7 @@ public class H2TableEngine implements TableEngine {
 
     /** {@inheritDoc} */
     @Override public TableBase createTable(CreateTableData createTblData) {
-        resTbl0 = new GridH2Table(createTblData, rowDesc0, rowFactory0, tblDesc0, tblDesc0.cacheName());
+        resTbl0 = new GridH2Table(createTblData, rowDesc0, rowFactory0, tblDesc0, tblDesc0.cache());
 
         return resTbl0;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Utils.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Utils.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Utils.java
index a4fdb53..ee88acf 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Utils.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Utils.java
@@ -173,7 +173,7 @@ public class H2Utils {
             if (!ctor.isAccessible())
                 ctor.setAccessible(true);
 
-            final int segments = tbl.rowDescriptor().configuration().getQueryParallelism();
+            final int segments = tbl.rowDescriptor().context().config().getQueryParallelism();
 
             return (GridH2IndexBase)ctor.newInstance(tbl, idxName, segments, cols);
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/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 bd611f6..e192008 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
@@ -54,7 +54,6 @@ import org.apache.ignite.cache.query.SqlFieldsQuery;
 import org.apache.ignite.cache.query.SqlQuery;
 import org.apache.ignite.cache.query.annotations.QuerySqlFunction;
 import org.apache.ignite.cluster.ClusterNode;
-import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.GridTopic;
 import org.apache.ignite.internal.IgniteInternalFuture;
@@ -90,6 +89,7 @@ import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor;
 import org.apache.ignite.internal.processors.query.GridRunningQueryInfo;
 import org.apache.ignite.internal.processors.query.IgniteSQLException;
 import org.apache.ignite.internal.processors.query.QueryIndexDescriptorImpl;
+import org.apache.ignite.internal.processors.query.QueryUtils;
 import org.apache.ignite.internal.processors.query.h2.ddl.DdlStatementsProcessor;
 import org.apache.ignite.internal.processors.query.h2.opt.DistributedJoinMode;
 import org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex;
@@ -581,7 +581,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
      * @param tbl Table to unregister.
      * @throws IgniteCheckedException If failed to unregister.
      */
-    private void removeTable(H2TableDescriptor tbl) throws IgniteCheckedException {
+    private void dropTable(H2TableDescriptor tbl) throws IgniteCheckedException {
         assert tbl != null;
 
         if (log.isDebugEnabled())
@@ -614,10 +614,6 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         finally {
             U.close(stmt, log);
         }
-
-        tbl.onDrop();
-
-        tbl.schema().remove(tbl);
     }
 
     /**
@@ -743,12 +739,12 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     public GridH2IndexBase createSortedIndex(H2Schema schema, String name, GridH2Table tbl, boolean pk,
         List<IndexColumn> cols, int inlineSize) {
         try {
-            GridCacheContext cctx = schema.cacheContext();
+            GridCacheContext cctx = tbl.cache();
 
             if (log.isDebugEnabled())
                 log.debug("Creating cache index [cacheId=" + cctx.cacheId() + ", idxName=" + name + ']');
 
-            final int segments = tbl.rowDescriptor().configuration().getQueryParallelism();
+            final int segments = tbl.rowDescriptor().context().config().getQueryParallelism();
 
             return new H2TreeIndex(cctx, tbl, name, pk, cols, inlineSize, segments);
         }
@@ -779,15 +775,6 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         return new GridEmptyCloseableIterator<>();
     }
 
-    /** {@inheritDoc} */
-    @Override public void unregisterType(String schemaName, String typeName)
-        throws IgniteCheckedException {
-        H2TableDescriptor tbl = tableDescriptor(schemaName, typeName);
-
-        if (tbl != null)
-            removeTable(tbl);
-    }
-
     /**
      * Queries individual fields (generally used by JDBC drivers).
      *
@@ -1001,7 +988,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
             long time = U.currentTimeMillis() - start;
 
-            long longQryExecTimeout = schemas.get(schema).cacheContext().config().getLongQueryWarningTimeout();
+            long longQryExecTimeout = ctx.config().getLongQueryWarningTimeout();
 
             if (time > longQryExecTimeout) {
                 String msg = "Query execution is too long (" + time + " ms): " + sql;
@@ -1519,15 +1506,15 @@ public class IgniteH2Indexing implements GridQueryIndexing {
      * @param type Type description.
      * @throws IgniteCheckedException In case of error.
      */
-    @Override public boolean registerType(String cacheName, GridQueryTypeDescriptor type)
+    @Override public boolean registerType(GridCacheContext cctx, GridQueryTypeDescriptor type)
         throws IgniteCheckedException {
         validateTypeDescriptor(type);
 
-        String schemaName = schema(cacheName);
+        String schemaName = schema(cctx.name());
 
         H2Schema schema = schemas.get(schemaName);
 
-        H2TableDescriptor tbl = new H2TableDescriptor(this, schema, type, cacheName);
+        H2TableDescriptor tbl = new H2TableDescriptor(this, schema, type, cctx);
 
         try {
             Connection conn = connectionForThread(schemaName);
@@ -1609,7 +1596,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         if (log.isDebugEnabled())
             log.debug("Creating DB table with SQL: " + sql);
 
-        GridH2RowDescriptor rowDesc = new H2RowDescriptor(this, tbl.type(), schema);
+        GridH2RowDescriptor rowDesc = new H2RowDescriptor(this, tbl, tbl.type(), schema);
 
         H2RowFactory rowFactory = tbl.rowFactory(rowDesc);
 
@@ -1732,17 +1719,6 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     }
 
     /** {@inheritDoc} */
-    @Override public String cacheName(String schemaName) {
-        assert schemaName != null;
-
-        H2Schema schema = schemas.get(schemaName);
-
-        assert schema != null;
-
-        return schema.cacheName();
-    }
-
-    /** {@inheritDoc} */
     @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
     @Override public void rebuildIndexesFromHash(GridCacheContext cctx, String schemaName, String typeName)
         throws IgniteCheckedException {
@@ -1886,6 +1862,8 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         else {
             this.ctx = ctx;
 
+            schemas.put(QueryUtils.DFLT_SCHEMA, new H2Schema(QueryUtils.DFLT_SCHEMA));
+
             valCtx = new CacheQueryObjectValueContext(ctx);
 
             nodeId = ctx.localNodeId();
@@ -2081,7 +2059,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 //        unregisterMBean(); TODO https://issues.apache.org/jira/browse/IGNITE-2139
         if (ctx != null && !ctx.cache().context().database().persistenceEnabled()) {
             for (H2Schema schema : schemas.values())
-                schema.onDrop();
+                schema.dropAll();
         }
 
         for (Connection c : conns)
@@ -2091,8 +2069,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         schemas.clear();
         cacheName2schema.clear();
 
-        try (Connection c = DriverManager.getConnection(dbUrl);
-             Statement s = c.createStatement()) {
+        try (Connection c = DriverManager.getConnection(dbUrl); Statement s = c.createStatement()) {
             s.execute("SHUTDOWN");
         }
         catch (SQLException e) {
@@ -2108,41 +2085,75 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             log.debug("Cache query index stopped.");
     }
 
+    /**
+     * Whether this is default schema.
+     *
+     * @param schemaName Schema name.
+     * @return {@code True} if default.
+     */
+    private boolean isDefaultSchema(String schemaName) {
+        return F.eq(schemaName, QueryUtils.DFLT_SCHEMA);
+    }
+
     /** {@inheritDoc} */
-    @Override public void registerCache(String cacheName, String schemaName, GridCacheContext<?, ?> cctx,
-        CacheConfiguration<?, ?> ccfg) throws IgniteCheckedException {
-        if (schemas.putIfAbsent(schemaName, new H2Schema(cacheName, schemaName, cctx)) != null)
-            throw new IgniteCheckedException("Cache already registered: " + U.maskName(cacheName));
+    @Override public void registerCache(String cacheName, String schemaName, GridCacheContext<?, ?> cctx)
+        throws IgniteCheckedException {
+        if (!isDefaultSchema(schemaName)) {
+            if (schemas.putIfAbsent(schemaName, new H2Schema(schemaName)) != null)
+                throw new IgniteCheckedException("Schema already registered: " + U.maskName(schemaName));
 
-        cacheName2schema.put(cacheName, schemaName);
+            createSchema(schemaName);
+        }
 
-        createSchema(schemaName);
+        cacheName2schema.put(cacheName, schemaName);
 
-        createSqlFunctions(schemaName, ccfg.getSqlFunctionClasses());
+        createSqlFunctions(schemaName, cctx.config().getSqlFunctionClasses());
     }
 
     /** {@inheritDoc} */
     @Override public void unregisterCache(String cacheName) {
-        String schema = schema(cacheName);
-        H2Schema rmv = schemas.remove(schema);
+        String schemaName = schema(cacheName);
 
-        if (rmv != null) {
+        boolean dflt = isDefaultSchema(schemaName);
+
+        H2Schema schema = dflt ? schemas.get(schemaName) : schemas.remove(schemaName);
+
+        if (schema != null) {
             cacheName2schema.remove(cacheName);
             mapQryExec.onCacheStop(cacheName);
             dmlProc.onCacheStop(cacheName);
 
-            rmv.onDrop();
+            // Drop tables.
+            Collection<H2TableDescriptor> rmvTbls = new HashSet<>();
 
-            try {
-                dropSchema(schema);
+            for (H2TableDescriptor tbl : schema.tables()) {
+                if (F.eq(tbl.cache().name(), cacheName)) {
+                    try {
+                        dropTable(tbl);
+                    }
+                    catch (IgniteCheckedException e) {
+                        U.error(log, "Failed to drop table on cache stop (will ignore): " + tbl.fullTableName(), e);
+                    }
+
+                    schema.drop(tbl);
+
+                    rmvTbls.add(tbl);
+                }
             }
-            catch (IgniteCheckedException e) {
-                U.error(log, "Failed to drop schema on cache stop (will ignore): " + cacheName, e);
+
+            if (!dflt) {
+                try {
+                    dropSchema(schemaName);
+                }
+                catch (IgniteCheckedException e) {
+                    U.error(log, "Failed to drop schema on cache stop (will ignore): " + cacheName, e);
+                }
             }
 
-            for (H2TableDescriptor tblDesc : rmv.tables())
-                for (Index idx : tblDesc.table().getIndexes())
+            for (H2TableDescriptor tbl : rmvTbls) {
+                for (Index idx : tbl.table().getIndexes())
                     idx.close(null);
+            }
 
             int cacheId = CU.cacheId(cacheName);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java
index 778ebfb..ce73010 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java
@@ -58,11 +58,6 @@ public interface GridH2RowDescriptor extends GridOffHeapSmartPointerFactory<Grid
     public GridCacheContext<?, ?> context();
 
     /**
-     * @return Cache configuration.
-     */
-    public CacheConfiguration configuration();
-
-    /**
      * Creates new row.
      *
      * @param key Key.

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
index a85cd93..d656cc3 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
@@ -64,8 +64,8 @@ import static org.apache.ignite.internal.processors.query.h2.opt.GridH2QueryType
  * H2 Table implementation.
  */
 public class GridH2Table extends TableBase {
-    /** */
-    private final String cacheName;
+    /** Cache context. */
+    private final GridCacheContext cctx;
 
     /** */
     private final GridH2RowDescriptor desc;
@@ -119,16 +119,16 @@ public class GridH2Table extends TableBase {
      * @param desc Row descriptor.
      * @param rowFactory Row factory.
      * @param idxsFactory Indexes factory.
-     * @param cacheName Cache name.
+     * @param cctx Cache context.
      */
     public GridH2Table(CreateTableData createTblData, @Nullable GridH2RowDescriptor desc, H2RowFactory rowFactory,
-        GridH2SystemIndexFactory idxsFactory, String cacheName) {
+        GridH2SystemIndexFactory idxsFactory, GridCacheContext cctx) {
         super(createTblData);
 
         assert idxsFactory != null;
 
         this.desc = desc;
-        this.cacheName = cacheName;
+        this.cctx = cctx;
 
         if (desc != null && desc.context() != null && !desc.context().customAffinityMapper()) {
             boolean affinityColExists = true;
@@ -184,7 +184,7 @@ public class GridH2Table extends TableBase {
 
         pkIndexPos = hasHashIndex ? 2 : 1;
 
-        final int segments = desc != null ? desc.configuration().getQueryParallelism() :
+        final int segments = desc != null ? desc.context().config().getQueryParallelism() :
             // Get index segments count from PK index. Null desc can be passed from tests.
             index(pkIndexPos).segmentsCount();
 
@@ -197,7 +197,7 @@ public class GridH2Table extends TableBase {
      * @return {@code true} If this is a partitioned table.
      */
     public boolean isPartitioned() {
-        return desc != null && desc.configuration().getCacheMode() == PARTITIONED;
+        return desc != null && desc.context().config().getCacheMode() == PARTITIONED;
     }
 
     /**
@@ -222,8 +222,15 @@ public class GridH2Table extends TableBase {
     /**
      * @return Cache name.
      */
-    @Nullable public String cacheName() {
-        return cacheName;
+    public String cacheName() {
+        return cctx.name();
+    }
+
+    /**
+     * @return Cache context.
+     */
+    public GridCacheContext cache() {
+        return cctx;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java
index 3d994c2..3cecbc8 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java
@@ -105,7 +105,7 @@ public class IgniteSqlSchemaIndexingTest extends GridCommonAbstractTest {
 
                 return null;
             }
-        }, IgniteException.class, "Cache already registered: ");
+        }, IgniteException.class, "Schema already registered: ");
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/738451c1/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
index 7b0cbf8..99246eb 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
@@ -367,11 +367,6 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
         // Remove
         cacheA.remove(2);
         cacheB.remove(1);
-
-        // Unregister.
-        spi.unregisterType(spi.schema(typeAA.cacheName()), typeAA.name());
-        spi.unregisterType(spi.schema(typeAB.cacheName()), typeAB.name());
-        spi.unregisterType(spi.schema(typeBA.cacheName()), typeBA.name());
     }
 
     /**
@@ -384,7 +379,7 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
 
         ignite0.createCache(cacheACfg());
 
-        long longQryExecTime = CacheConfiguration.DFLT_LONG_QRY_WARN_TIMEOUT;
+        long longQryExecTime = IgniteConfiguration.DFLT_LONG_QRY_WARN_TIMEOUT;
 
         GridStringLogger log = new GridStringLogger(false, this.log);