You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ka...@apache.org on 2021/05/11 07:37:39 UTC

[iotdb] branch f_index_dev updated: show index, create index without create timeseries

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

kangrong pushed a commit to branch f_index_dev
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/f_index_dev by this push:
     new 2eb0d67  show index, create index without create timeseries
2eb0d67 is described below

commit 2eb0d67c9428661b5bbdc9f207190210898f1d27
Author: kr11 <3095717866.com>
AuthorDate: Tue May 11 15:33:53 2021 +0800

    show index, create index without create timeseries
---
 .../org/apache/iotdb/db/index/IndexManager.java    | 11 ++-
 .../org/apache/iotdb/db/index/IndexProcessor.java  | 24 ++++--
 .../apache/iotdb/db/index/common/IndexInfo.java    |  5 ++
 .../db/index/common/IndexProcessorStruct.java      |  7 +-
 .../apache/iotdb/db/index/common/IndexType.java    | 20 +++--
 .../apache/iotdb/db/index/common/IndexUtils.java   | 15 ++++
 .../iotdb/db/index/router/ProtoIndexRouter.java    | 19 ++---
 .../apache/iotdb/db/index/it/ELBIndexReadIT.java   | 90 +++++++++++++--------
 .../org/apache/iotdb/db/index/it/ELBNoIndexIT.java | 22 ++---
 .../apache/iotdb/db/index/it/MMHHIndexReadIT.java  | 33 +++++---
 .../apache/iotdb/db/index/it/RTreeIndexReadIT.java | 33 +++++---
 .../it/{MMHHIndexReadIT.java => ShowIndexIT.java}  | 94 +++++++++-------------
 .../db/index/router/ProtoIndexRouterTest.java      |  4 +-
 13 files changed, 228 insertions(+), 149 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/index/IndexManager.java b/server/src/main/java/org/apache/iotdb/db/index/IndexManager.java
index 2bd7557..f34039e 100644
--- a/server/src/main/java/org/apache/iotdb/db/index/IndexManager.java
+++ b/server/src/main/java/org/apache/iotdb/db/index/IndexManager.java
@@ -90,7 +90,8 @@ public class IndexManager implements IndexManagerMBean, IService {
         (indexSeries, indexInfoMap) ->
             new IndexProcessor(
                 indexSeries,
-                IndexUtils.removeIllegalStarInDir(indexDataDirPath + File.separator + indexSeries));
+                IndexUtils.removeIllegalStarInDir(indexDataDirPath + File.separator + indexSeries),
+                indexInfoMap);
     router = IIndexRouter.Factory.getIndexRouter(indexRouterDir);
   }
 
@@ -204,7 +205,13 @@ public class IndexManager implements IndexManagerMBean, IService {
     PartialPath queryIndexSeries = paths.get(0);
     IndexProcessorStruct indexProcessorStruct =
         router.startQueryAndCheck(queryIndexSeries, indexType, context);
-    List<StorageGroupProcessor> list = indexProcessorStruct.addMergeLock();
+    List<StorageGroupProcessor> list;
+    try {
+      list = indexProcessorStruct.addMergeLock();
+    } catch (MetadataException e) {
+      e.printStackTrace();
+      throw new QueryIndexException("add merge lock failed");
+    }
     try {
       return indexProcessorStruct.processor.query(indexType, queryProps, context, alignedByTime);
     } finally {
diff --git a/server/src/main/java/org/apache/iotdb/db/index/IndexProcessor.java b/server/src/main/java/org/apache/iotdb/db/index/IndexProcessor.java
index eb4cd39..7b1d965 100644
--- a/server/src/main/java/org/apache/iotdb/db/index/IndexProcessor.java
+++ b/server/src/main/java/org/apache/iotdb/db/index/IndexProcessor.java
@@ -120,7 +120,8 @@ public class IndexProcessor implements Comparable<IndexProcessor> {
   /** The optimizer for the post-processing phase (refinement phase). Unused yet. */
   private final IIndexCandidateOrderOptimize refinePhaseOptimizer;
 
-  public IndexProcessor(PartialPath indexSeries, String indexSeriesDirPath) {
+  public IndexProcessor(
+      PartialPath indexSeries, String indexSeriesDirPath, Map<IndexType, IndexInfo> indexInfoMap) {
     this.indexBuildPoolManager = IndexBuildTaskPoolManager.getInstance();
 
     this.numIndexBuildTasks = new AtomicInteger(0);
@@ -137,7 +138,7 @@ public class IndexProcessor implements Comparable<IndexProcessor> {
     this.usableMap = new EnumMap<>(IndexType.class);
     this.previousDataBufferFile = indexSeriesDirPath + File.separator + "previousBuffer";
     this.usableFile = indexSeriesDirPath + File.separator + "usableMap";
-    this.tsDataType = initSeriesType();
+    this.tsDataType = initSeriesType(indexInfoMap);
     this.refinePhaseOptimizer = IIndexCandidateOrderOptimize.Factory.getOptimize();
     deserializePreviousBuffer();
     deserializeUsable(indexSeries);
@@ -149,7 +150,7 @@ public class IndexProcessor implements Comparable<IndexProcessor> {
    *
    * @return tsDataType of this IndexProcessor
    */
-  private TSDataType initSeriesType() {
+  private TSDataType initSeriesType(Map<IndexType, IndexInfo> indexInfoMap) {
     try {
       if (indexSeries.isFullPath()) {
         return MManager.getInstance().getSeriesType(indexSeries);
@@ -157,13 +158,26 @@ public class IndexProcessor implements Comparable<IndexProcessor> {
         List<PartialPath> list =
             IoTDB.metaManager.getAllTimeseriesPathWithAlias(indexSeries, 1, 0).left;
         if (list.isEmpty()) {
-          throw new IndexRuntimeException("No series in the wildcard path");
+          throw new MetadataException(
+              "not exist any series in " + indexSeries + " cannot determine the index datatype");
+          //          throw new IndexRuntimeException("No series in the wildcard path");
+          // not throw, just return null
+          //          return null;
         } else {
           return MManager.getInstance().getSeriesType(list.get(0));
         }
       }
     } catch (MetadataException e) {
-      throw new IndexRuntimeException("get type failed. ", e);
+      // not throw, just return null
+      if (!indexInfoMap.isEmpty()) {
+        return indexInfoMap.entrySet().stream().findFirst().get().getValue().getRecommendDataType();
+      } else {
+        // not any index, why it's called? warning and find type from MManager
+        logger.warn(
+            "no any type of index when IndexProcessor is created, find DataType from Metadata.");
+        throw new IndexRuntimeException(
+            "cannot find datatype: no data series, no index recommendation. ", e);
+      }
     }
   }
 
diff --git a/server/src/main/java/org/apache/iotdb/db/index/common/IndexInfo.java b/server/src/main/java/org/apache/iotdb/db/index/common/IndexInfo.java
index 3173eb4..239dd49 100644
--- a/server/src/main/java/org/apache/iotdb/db/index/common/IndexInfo.java
+++ b/server/src/main/java/org/apache/iotdb/db/index/common/IndexInfo.java
@@ -19,6 +19,7 @@
 package org.apache.iotdb.db.index.common;
 
 import org.apache.iotdb.db.metadata.MetadataOperationType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
 import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
 
 import java.io.IOException;
@@ -145,4 +146,8 @@ public class IndexInfo implements Cloneable {
   public Object clone() {
     return new IndexInfo(indexType, time, new HashMap<>(props));
   }
+
+  public TSDataType getRecommendDataType() {
+    return indexType.getRecommendDataType();
+  }
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/index/common/IndexProcessorStruct.java b/server/src/main/java/org/apache/iotdb/db/index/common/IndexProcessorStruct.java
index ae3a875..bc3210b 100644
--- a/server/src/main/java/org/apache/iotdb/db/index/common/IndexProcessorStruct.java
+++ b/server/src/main/java/org/apache/iotdb/db/index/common/IndexProcessorStruct.java
@@ -21,6 +21,7 @@ package org.apache.iotdb.db.index.common;
 import org.apache.iotdb.db.engine.StorageEngine;
 import org.apache.iotdb.db.engine.storagegroup.StorageGroupProcessor;
 import org.apache.iotdb.db.exception.StorageEngineException;
+import org.apache.iotdb.db.exception.metadata.MetadataException;
 import org.apache.iotdb.db.index.IndexProcessor;
 import org.apache.iotdb.db.metadata.PartialPath;
 
@@ -41,7 +42,11 @@ public class IndexProcessorStruct {
     this.infos = infos;
   }
 
-  public List<StorageGroupProcessor> addMergeLock() throws StorageEngineException {
+  public List<StorageGroupProcessor> addMergeLock()
+      throws StorageEngineException, MetadataException {
+    if (!representativePath.isFullPath()) {
+      representativePath = IndexUtils.getRepresentativePath(representativePath);
+    }
     return StorageEngine.getInstance().mergeLock(Collections.singletonList(representativePath));
   }
 
diff --git a/server/src/main/java/org/apache/iotdb/db/index/common/IndexType.java b/server/src/main/java/org/apache/iotdb/db/index/common/IndexType.java
index 9de525c..bb605b0 100644
--- a/server/src/main/java/org/apache/iotdb/db/index/common/IndexType.java
+++ b/server/src/main/java/org/apache/iotdb/db/index/common/IndexType.java
@@ -33,11 +33,17 @@ import java.util.HashMap;
 import java.util.Map;
 
 public enum IndexType {
-  NO_INDEX,
-  RTREE_PAA,
-  ELB_INDEX,
-  MMHH,
-  ANY_FOR_QUERY;
+  NO_INDEX(TSDataType.FLOAT),
+  RTREE_PAA(TSDataType.FLOAT),
+  ELB_INDEX(TSDataType.FLOAT),
+  MMHH(TSDataType.FLOAT),
+  ANY_FOR_QUERY(TSDataType.FLOAT);
+
+  private TSDataType recommendDataType;
+
+  IndexType(TSDataType recommendDataType) {
+    this.recommendDataType = recommendDataType;
+  }
 
   /**
    * judge the index type.
@@ -135,4 +141,8 @@ public enum IndexType {
     props.forEach((k, v) -> uppercase.put(k.toUpperCase(), v));
     return uppercase;
   }
+
+  public TSDataType getRecommendDataType() {
+    return recommendDataType;
+  }
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/index/common/IndexUtils.java b/server/src/main/java/org/apache/iotdb/db/index/common/IndexUtils.java
index 6ea57db..f24b78f 100644
--- a/server/src/main/java/org/apache/iotdb/db/index/common/IndexUtils.java
+++ b/server/src/main/java/org/apache/iotdb/db/index/common/IndexUtils.java
@@ -19,6 +19,8 @@ package org.apache.iotdb.db.index.common;
 
 import org.apache.iotdb.db.engine.fileSystem.SystemFileFactory;
 import org.apache.iotdb.db.exception.index.IndexRuntimeException;
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.MManager;
 import org.apache.iotdb.db.metadata.PartialPath;
 import org.apache.iotdb.db.rescon.TVListAllocator;
 import org.apache.iotdb.db.utils.TestOnly;
@@ -27,9 +29,11 @@ import org.apache.iotdb.db.utils.datastructure.primitive.PrimitiveList;
 import org.apache.iotdb.tsfile.exception.NotImplementedException;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
 import org.apache.iotdb.tsfile.read.TimeValuePair;
+import org.apache.iotdb.tsfile.utils.Pair;
 
 import java.io.File;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 
@@ -57,6 +61,17 @@ public class IndexUtils {
     return true;
   }
 
+  public static PartialPath getRepresentativePath(PartialPath wildcardPath)
+      throws MetadataException {
+    Pair<List<PartialPath>, Integer> paths =
+        MManager.getInstance().getAllTimeseriesPathWithAlias(wildcardPath, 1, 0);
+    if (paths.left.isEmpty()) {
+      throw new MetadataException("Please create at least one series before create index");
+    } else {
+      return paths.left.get(0);
+    }
+  }
+
   public static int getDataTypeSize(TVList srcData) {
     return getDataTypeSize(srcData.getDataType());
   }
diff --git a/server/src/main/java/org/apache/iotdb/db/index/router/ProtoIndexRouter.java b/server/src/main/java/org/apache/iotdb/db/index/router/ProtoIndexRouter.java
index 1d962bc..3b55dc7 100644
--- a/server/src/main/java/org/apache/iotdb/db/index/router/ProtoIndexRouter.java
+++ b/server/src/main/java/org/apache/iotdb/db/index/router/ProtoIndexRouter.java
@@ -26,12 +26,12 @@ import org.apache.iotdb.db.index.IndexProcessor;
 import org.apache.iotdb.db.index.common.IndexInfo;
 import org.apache.iotdb.db.index.common.IndexProcessorStruct;
 import org.apache.iotdb.db.index.common.IndexType;
+import org.apache.iotdb.db.index.common.IndexUtils;
 import org.apache.iotdb.db.index.common.func.CreateIndexProcessorFunc;
 import org.apache.iotdb.db.metadata.MManager;
 import org.apache.iotdb.db.metadata.PartialPath;
 import org.apache.iotdb.db.metadata.mnode.StorageGroupMNode;
 import org.apache.iotdb.db.query.context.QueryContext;
-import org.apache.iotdb.tsfile.utils.Pair;
 import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
 
 import org.slf4j.Logger;
@@ -303,7 +303,12 @@ public class ProtoIndexRouter implements IIndexRouter {
           Map<IndexType, IndexInfo> infoMap = new EnumMap<>(IndexType.class);
           infoMap.put(indexType, indexInfo);
           IndexProcessor processor = func.act(partialPath, infoMap);
-          PartialPath representativePath = getRepresentativePath(partialPath);
+          PartialPath representativePath;
+          try {
+            representativePath = IndexUtils.getRepresentativePath(partialPath);
+          } catch (MetadataException e) {
+            representativePath = partialPath;
+          }
           wildCardProcessorMap.put(
               partialPath, new IndexProcessorStruct(processor, representativePath, infoMap));
         } else {
@@ -329,16 +334,6 @@ public class ProtoIndexRouter implements IIndexRouter {
     return true;
   }
 
-  private PartialPath getRepresentativePath(PartialPath wildcardPath) throws MetadataException {
-    Pair<List<PartialPath>, Integer> paths =
-        mManager.getAllTimeseriesPathWithAlias(wildcardPath, 1, 0);
-    if (paths.left.isEmpty()) {
-      throw new MetadataException("Please create at least one series before create index");
-    } else {
-      return paths.left.get(0);
-    }
-  }
-
   @Override
   public boolean removeIndexFromRouter(PartialPath partialPath, IndexType indexType)
       throws MetadataException, IOException {
diff --git a/server/src/test/java/org/apache/iotdb/db/index/it/ELBIndexReadIT.java b/server/src/test/java/org/apache/iotdb/db/index/it/ELBIndexReadIT.java
index df85e78..1e6902d 100644
--- a/server/src/test/java/org/apache/iotdb/db/index/it/ELBIndexReadIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/index/it/ELBIndexReadIT.java
@@ -67,7 +67,6 @@ public class ELBIndexReadIT {
     IoTDBDescriptor.getInstance().getConfig().setEnableIndex(true);
     EnvironmentUtils.closeStatMonitor();
     EnvironmentUtils.envSetUp();
-    insertSQL();
   }
 
   @After
@@ -76,7 +75,7 @@ public class ELBIndexReadIT {
     IoTDBDescriptor.getInstance().getConfig().setEnableIndex(false);
   }
 
-  private static void insertSQL() throws ClassNotFoundException {
+  private static void insertSQL(boolean createTS) throws ClassNotFoundException {
 
     Class.forName(Config.JDBC_DRIVER_NAME);
     try (Connection connection =
@@ -87,17 +86,18 @@ public class ELBIndexReadIT {
       statement.execute(String.format("SET STORAGE GROUP TO %s", storageGroupWhole));
       System.out.println(String.format("SET STORAGE GROUP TO %s", storageGroupSub));
       System.out.println(String.format("SET STORAGE GROUP TO %s", storageGroupWhole));
-      statement.execute(
-          String.format("CREATE TIMESERIES %s WITH DATATYPE=FLOAT,ENCODING=PLAIN", speed1));
-      System.out.println(
-          String.format("CREATE TIMESERIES %s WITH DATATYPE=FLOAT,ENCODING=PLAIN", speed1));
-
-      for (int i = 0; i < wholeSize; i++) {
-        String wholePath = String.format(directionPattern, i);
+      if (createTS) {
         statement.execute(
-            String.format("CREATE TIMESERIES %s WITH DATATYPE=FLOAT,ENCODING=PLAIN", wholePath));
+            String.format("CREATE TIMESERIES %s WITH DATATYPE=FLOAT,ENCODING=PLAIN", speed1));
         System.out.println(
-            String.format("CREATE TIMESERIES %s WITH DATATYPE=FLOAT,ENCODING=PLAIN", wholePath));
+            String.format("CREATE TIMESERIES %s WITH DATATYPE=FLOAT,ENCODING=PLAIN", speed1));
+        for (int i = 0; i < wholeSize; i++) {
+          String wholePath = String.format(directionPattern, i);
+          statement.execute(
+              String.format("CREATE TIMESERIES %s WITH DATATYPE=FLOAT,ENCODING=PLAIN", wholePath));
+          System.out.println(
+              String.format("CREATE TIMESERIES %s WITH DATATYPE=FLOAT,ENCODING=PLAIN", wholePath));
+        }
       }
       statement.execute(
           String.format("CREATE INDEX ON %s WITH INDEX=%s, BLOCK_SIZE=%d", indexSub, ELB_INDEX, 5));
@@ -176,7 +176,17 @@ public class ELBIndexReadIT {
   }
 
   @Test
-  public void checkMultiSeriesTimeAligned() throws ClassNotFoundException {
+  public void checkMultiSeriesTimeAlignedWithCreateTS() throws ClassNotFoundException {
+    checkMultiSeriesTimeAligned(true);
+  }
+
+  @Test
+  public void checkMultiSeriesTimeAlignedWithoutCreateTS() throws ClassNotFoundException {
+    checkMultiSeriesTimeAligned(false);
+  }
+
+  private void checkMultiSeriesTimeAligned(boolean createTS) throws ClassNotFoundException {
+    insertSQL(createTS);
     Class.forName(Config.JDBC_DRIVER_NAME);
     try (Connection connection =
             DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
@@ -191,17 +201,17 @@ public class ELBIndexReadIT {
       boolean hasIndex = statement.execute(querySQL);
       String gt =
           "Time,root.wind1.azq01.speed.17,\n"
-              + "0,170.0,\n"
-              + "1,180.0,\n"
-              + "2,190.0,\n"
-              + "3,250.0,\n"
-              + "4,260.0,\n"
-              + "5,270.0,\n"
-              + "6,280.0,\n"
-              + "7,290.0,\n"
-              + "8,400.0,\n"
-              + "9,410.0,\n"
-              + "10,420.0,\n";
+              + "17,170.0,\n"
+              + "18,180.0,\n"
+              + "19,190.0,\n"
+              + "25,250.0,\n"
+              + "26,260.0,\n"
+              + "27,270.0,\n"
+              + "28,280.0,\n"
+              + "29,290.0,\n"
+              + "40,400.0,\n"
+              + "41,410.0,\n"
+              + "42,420.0,";
       Assert.assertTrue(hasIndex);
       try (ResultSet resultSet = statement.getResultSet()) {
         ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
@@ -226,7 +236,17 @@ public class ELBIndexReadIT {
   }
 
   @Test
-  public void checkRead() throws ClassNotFoundException {
+  public void checkReadWithCreateTS() throws ClassNotFoundException {
+    checkRead(true);
+  }
+
+  @Test
+  public void checkReadWithoutCreateTS() throws ClassNotFoundException {
+    checkRead(false);
+  }
+
+  private void checkRead(boolean createTS) throws ClassNotFoundException {
+    insertSQL(createTS);
     Class.forName(Config.JDBC_DRIVER_NAME);
     try (Connection connection =
             DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
@@ -241,17 +261,17 @@ public class ELBIndexReadIT {
       boolean hasIndex = statement.execute(querySQL);
       String gt =
           "Time,root.wind1.azq01.speed.17,\n"
-              + "0,170.0,\n"
-              + "1,180.0,\n"
-              + "2,190.0,\n"
-              + "3,250.0,\n"
-              + "4,260.0,\n"
-              + "5,270.0,\n"
-              + "6,280.0,\n"
-              + "7,290.0,\n"
-              + "8,400.0,\n"
-              + "9,410.0,\n"
-              + "10,420.0,\n";
+              + "17,170.0,\n"
+              + "18,180.0,\n"
+              + "19,190.0,\n"
+              + "25,250.0,\n"
+              + "26,260.0,\n"
+              + "27,270.0,\n"
+              + "28,280.0,\n"
+              + "29,290.0,\n"
+              + "40,400.0,\n"
+              + "41,410.0,\n"
+              + "42,420.0,\n";
       Assert.assertTrue(hasIndex);
       try (ResultSet resultSet = statement.getResultSet()) {
         ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
diff --git a/server/src/test/java/org/apache/iotdb/db/index/it/ELBNoIndexIT.java b/server/src/test/java/org/apache/iotdb/db/index/it/ELBNoIndexIT.java
index 76f3f94..5b04add3 100644
--- a/server/src/test/java/org/apache/iotdb/db/index/it/ELBNoIndexIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/index/it/ELBNoIndexIT.java
@@ -188,17 +188,17 @@ public class ELBNoIndexIT {
       boolean hasIndex = statement.execute(querySQL);
       String gt =
           "Time,root.wind1.azq01.speed.17,\n"
-              + "0,170.0,\n"
-              + "1,180.0,\n"
-              + "2,190.0,\n"
-              + "3,250.0,\n"
-              + "4,260.0,\n"
-              + "5,270.0,\n"
-              + "6,280.0,\n"
-              + "7,290.0,\n"
-              + "8,400.0,\n"
-              + "9,410.0,\n"
-              + "10,420.0,\n";
+              + "17,170.0,\n"
+              + "18,180.0,\n"
+              + "19,190.0,\n"
+              + "25,250.0,\n"
+              + "26,260.0,\n"
+              + "27,270.0,\n"
+              + "28,280.0,\n"
+              + "29,290.0,\n"
+              + "40,400.0,\n"
+              + "41,410.0,\n"
+              + "42,420.0,\n";
       Assert.assertTrue(hasIndex);
       try (ResultSet resultSet = statement.getResultSet()) {
         ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
diff --git a/server/src/test/java/org/apache/iotdb/db/index/it/MMHHIndexReadIT.java b/server/src/test/java/org/apache/iotdb/db/index/it/MMHHIndexReadIT.java
index ecef093..71d93db 100644
--- a/server/src/test/java/org/apache/iotdb/db/index/it/MMHHIndexReadIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/index/it/MMHHIndexReadIT.java
@@ -62,10 +62,9 @@ public class MMHHIndexReadIT {
     IoTDBDescriptor.getInstance().getConfig().setEnableIndex(true);
     EnvironmentUtils.closeStatMonitor();
     EnvironmentUtils.envSetUp();
-    insertSQL();
   }
 
-  private void insertSQL() throws ClassNotFoundException {
+  private void insertSQL(boolean explicitCreateTS) throws ClassNotFoundException {
     Class.forName(Config.JDBC_DRIVER_NAME);
     //    IoTDBDescriptor.getInstance().getConfig().setEnableIndex(false);
     try (Connection connection =
@@ -74,13 +73,14 @@ public class MMHHIndexReadIT {
         Statement statement = connection.createStatement(); ) {
       statement.execute(String.format("SET STORAGE GROUP TO %s", storageGroupWhole));
       System.out.println(String.format("SET STORAGE GROUP TO %s", storageGroupWhole));
-
-      for (int i = 0; i < 1; i++) {
-        String wholePath = String.format(directionPattern, i);
-        System.out.println(
-            String.format("CREATE TIMESERIES %s WITH DATATYPE=FLOAT,ENCODING=PLAIN", wholePath));
-        statement.execute(
-            String.format("CREATE TIMESERIES %s WITH DATATYPE=FLOAT,ENCODING=PLAIN", wholePath));
+      if (explicitCreateTS) {
+        for (int i = 0; i < 1; i++) {
+          String wholePath = String.format(directionPattern, i);
+          System.out.println(
+              String.format("CREATE TIMESERIES %s WITH DATATYPE=FLOAT,ENCODING=PLAIN", wholePath));
+          statement.execute(
+              String.format("CREATE TIMESERIES %s WITH DATATYPE=FLOAT,ENCODING=PLAIN", wholePath));
+        }
       }
       System.out.println(
           String.format(
@@ -92,7 +92,7 @@ public class MMHHIndexReadIT {
               MODEL_PATH,
               //
               // "\"/Users/kangrong/code/github/deep-learning/hash_journal/TAH_project/src/mmhh.pt\""
-              "\"resources/index/mmhh.pt\""));
+              "\"src/test/resources/index/mmhh.pt\""));
       //      String modelPath =
       // "/Users/kangrong/code/github/deep-learning/hash_journal/TAH_project/src/mmhh.pt";
       String modelPath = "src/test/resources/index/mmhh.pt";
@@ -135,8 +135,18 @@ public class MMHHIndexReadIT {
   }
 
   @Test
-  public void checkRead() throws ClassNotFoundException {
+  public void checkReadWithCreateTS() throws ClassNotFoundException {
+    checkRead(true);
+  }
+
+  @Test
+  public void checkReadWithoutCreateTS() throws ClassNotFoundException {
+    checkRead(false);
+  }
+
+  private void checkRead(boolean explicitCreateTS) throws ClassNotFoundException {
     Class.forName(Config.JDBC_DRIVER_NAME);
+    insertSQL(explicitCreateTS);
     try (Connection connection =
             DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
         Statement statement = connection.createStatement()) {
@@ -147,6 +157,7 @@ public class MMHHIndexReadIT {
               getArrayRange(121, 121 + wholeDim));
 
       System.out.println(querySQL);
+      statement.setQueryTimeout(600);
       boolean hasIndex = statement.execute(querySQL);
       StringBuilder gt = new StringBuilder();
       gt.append("Time,root.wind2.1.direction.(D=0.00),root.wind2.2.direction.(D=1.00),\n");
diff --git a/server/src/test/java/org/apache/iotdb/db/index/it/RTreeIndexReadIT.java b/server/src/test/java/org/apache/iotdb/db/index/it/RTreeIndexReadIT.java
index f44a265..c1ada01 100644
--- a/server/src/test/java/org/apache/iotdb/db/index/it/RTreeIndexReadIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/index/it/RTreeIndexReadIT.java
@@ -65,10 +65,9 @@ public class RTreeIndexReadIT {
     IoTDBDescriptor.getInstance().getConfig().setEnableIndex(true);
     EnvironmentUtils.closeStatMonitor();
     EnvironmentUtils.envSetUp();
-    insertSQL();
   }
 
-  private void insertSQL() throws ClassNotFoundException {
+  private void insertSQL(boolean createTS) throws ClassNotFoundException {
     Class.forName(Config.JDBC_DRIVER_NAME);
     //    IoTDBDescriptor.getInstance().getConfig().setEnableIndex(false);
     try (Connection connection =
@@ -78,14 +77,19 @@ public class RTreeIndexReadIT {
       //      statement.execute(String.format("SET STORAGE GROUP TO %s", storageGroupSub));
       statement.execute(String.format("SET STORAGE GROUP TO %s", storageGroupWhole));
       System.out.println(String.format("SET STORAGE GROUP TO %s", storageGroupWhole));
-
-      for (int i = 0; i < 1; i++) {
-        String wholePath = String.format(directionPattern, i);
-        System.out.println(
-            String.format("CREATE TIMESERIES %s WITH DATATYPE=FLOAT,ENCODING=PLAIN", wholePath));
-        statement.execute(
-            String.format("CREATE TIMESERIES %s WITH DATATYPE=FLOAT,ENCODING=PLAIN", wholePath));
+      if (createTS) {
+        for (int i = 0; i < 1; i++) {
+          String wholePath = String.format(directionPattern, i);
+          System.out.println(
+              String.format("CREATE TIMESERIES %s WITH DATATYPE=FLOAT,ENCODING=PLAIN", wholePath));
+          statement.execute(
+              String.format("CREATE TIMESERIES %s WITH DATATYPE=FLOAT,ENCODING=PLAIN", wholePath));
+        }
       }
+      System.out.println(
+          String.format(
+              "CREATE INDEX ON %s WITH INDEX=%s, SERIES_LENGTH=%d, FEATURE_DIM=%d, MAX_ENTRIES=%d, MIN_ENTRIES=%d",
+              indexWhole, RTREE_PAA, wholeDim, PAA_Dim, 10, 2));
       statement.execute(
           String.format(
               "CREATE INDEX ON %s WITH INDEX=%s, SERIES_LENGTH=%d, FEATURE_DIM=%d, MAX_ENTRIES=%d, MIN_ENTRIES=%d",
@@ -117,8 +121,17 @@ public class RTreeIndexReadIT {
   }
 
   @Test
-  public void checkRead() throws ClassNotFoundException {
+  public void checkReadWithCreateTS() throws ClassNotFoundException {
+    checkRead(true);
+  }
+
+  @Test
+  public void checkReadWithoutCreateTS() throws ClassNotFoundException {
+    checkRead(false);
+  }
 
+  private void checkRead(boolean createTS) throws ClassNotFoundException {
+    insertSQL(createTS);
     Class.forName(Config.JDBC_DRIVER_NAME);
     try (Connection connection =
             DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
diff --git a/server/src/test/java/org/apache/iotdb/db/index/it/MMHHIndexReadIT.java b/server/src/test/java/org/apache/iotdb/db/index/it/ShowIndexIT.java
similarity index 65%
copy from server/src/test/java/org/apache/iotdb/db/index/it/MMHHIndexReadIT.java
copy to server/src/test/java/org/apache/iotdb/db/index/it/ShowIndexIT.java
index ecef093..016d82d 100644
--- a/server/src/test/java/org/apache/iotdb/db/index/it/MMHHIndexReadIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/index/it/ShowIndexIT.java
@@ -19,7 +19,6 @@
 package org.apache.iotdb.db.index.it;
 
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
-import org.apache.iotdb.db.index.IndexManager;
 import org.apache.iotdb.db.utils.EnvironmentUtils;
 import org.apache.iotdb.jdbc.Config;
 
@@ -35,15 +34,15 @@ import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.Statement;
 
-import static org.apache.iotdb.db.index.IndexTestUtils.getArrayRange;
 import static org.apache.iotdb.db.index.common.IndexConstant.MODEL_PATH;
 import static org.apache.iotdb.db.index.common.IndexType.MMHH;
 import static org.junit.Assert.fail;
 
-public class MMHHIndexReadIT {
+public class ShowIndexIT {
 
   private static final String insertPattern = "INSERT INTO %s(timestamp, %s) VALUES (%d, %.3f)";
 
+  private static final String storageGroupSub = "root.wind1";
   private static final String storageGroupWhole = "root.wind2";
 
   private static final String speed1 = "root.wind1.azq01.speed";
@@ -62,66 +61,61 @@ public class MMHHIndexReadIT {
     IoTDBDescriptor.getInstance().getConfig().setEnableIndex(true);
     EnvironmentUtils.closeStatMonitor();
     EnvironmentUtils.envSetUp();
-    insertSQL();
+    //    insertSQL();
   }
 
-  private void insertSQL() throws ClassNotFoundException {
+  @Test
+  public void createIndexBeforeCreateSeries() throws ClassNotFoundException {
     Class.forName(Config.JDBC_DRIVER_NAME);
     //    IoTDBDescriptor.getInstance().getConfig().setEnableIndex(false);
     try (Connection connection =
             DriverManager.getConnection(
                 Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
         Statement statement = connection.createStatement(); ) {
+      statement.execute(String.format("SET STORAGE GROUP TO %s", storageGroupSub));
       statement.execute(String.format("SET STORAGE GROUP TO %s", storageGroupWhole));
+      System.out.println(String.format("SET STORAGE GROUP TO %s", storageGroupSub));
       System.out.println(String.format("SET STORAGE GROUP TO %s", storageGroupWhole));
 
-      for (int i = 0; i < 1; i++) {
-        String wholePath = String.format(directionPattern, i);
-        System.out.println(
-            String.format("CREATE TIMESERIES %s WITH DATATYPE=FLOAT,ENCODING=PLAIN", wholePath));
-        statement.execute(
-            String.format("CREATE TIMESERIES %s WITH DATATYPE=FLOAT,ENCODING=PLAIN", wholePath));
-      }
       System.out.println(
           String.format(
               "CREATE INDEX ON %s WITH INDEX=%s, SERIES_LENGTH=%d, HASH_LENGTH=%d, %s=%s",
-              indexWhole,
-              MMHH,
-              wholeDim,
-              hashLength,
-              MODEL_PATH,
-              //
-              // "\"/Users/kangrong/code/github/deep-learning/hash_journal/TAH_project/src/mmhh.pt\""
-              "\"resources/index/mmhh.pt\""));
-      //      String modelPath =
-      // "/Users/kangrong/code/github/deep-learning/hash_journal/TAH_project/src/mmhh.pt";
+              indexWhole, MMHH, wholeDim, hashLength, MODEL_PATH, "\"resources/index/mmhh.pt\""));
       String modelPath = "src/test/resources/index/mmhh.pt";
       if (!(new File(modelPath).exists())) {
         fail("model file path is not correct!");
       }
       statement.execute(
-          String.format(
-              "CREATE INDEX ON %s WITH INDEX=%s, SERIES_LENGTH=%d, HASH_LENGTH=%d, %s=%s",
-              indexWhole,
-              MMHH,
-              wholeDim,
-              hashLength,
-              MODEL_PATH,
-              String.format("\"%s\"", modelPath)));
-      for (int i = 0; i < wholeSize; i++) {
-        String device = String.format(directionDevicePattern, i);
-        for (int j = 0; j < wholeDim; j++) {
-          String insertSQL =
-              String.format(insertPattern, device, directionSensor, j, (i * wholeDim + j) * 1d);
-          //          System.out.println(insertSQL);
-          statement.execute(insertSQL);
-        }
-      }
+          "CREATE INDEX ON root.wind2.*.direction WITH INDEX=MMHH, SERIES_LENGTH=100, "
+              + "HASH_LENGTH=48, MODEL_PATH=\"src/test/resources/index/mmhh.pt\"");
+      statement.execute(
+          "CREATE INDEX ON root.wind1.azq01.speed WITH INDEX=ELB_INDEX, BLOCK_SIZE=5");
+      statement.execute(
+          "CREATE INDEX ON root.wind2.*.direction WITH INDEX=RTREE_PAA, "
+              + "SERIES_LENGTH=15, FEATURE_DIM=4, MAX_ENTRIES=10, MIN_ENTRIES=2");
       statement.execute("flush");
-      System.out.println(IndexManager.getInstance().getRouter());
+      //      System.out.println(IndexManager.getInstance().getRouter());
       //      IndexManager.getInstance().stop();
       //      IndexManager.getInstance().start();
-
+      checkRead(
+          "SHOW INDEX",
+          "index series,index type,index attribute,\n"
+              + "root.wind1.azq01.speed,ELB_INDEX,BLOCK_SIZE=5,\n"
+              + "root.wind2.*.direction,RTREE_PAA,FEATURE_DIM=4,MIN_ENTRIES=2,SERIES_LENGTH=15,MAX_ENTRIES=10,\n"
+              + "root.wind2.*.direction,MMHH,MODEL_PATH=src/test/resources/index/mmhh.pt,SERIES_LENGTH=100,HASH_LENGTH=48,\n");
+
+      checkRead(
+          "SHOW INDEX FROM root.*",
+          "index series,index type,index attribute,\n"
+              + "root.wind1.azq01.speed,ELB_INDEX,BLOCK_SIZE=5,\n"
+              + "root.wind2.*.direction,RTREE_PAA,FEATURE_DIM=4,MIN_ENTRIES=2,SERIES_LENGTH=15,MAX_ENTRIES=10,\n"
+              + "root.wind2.*.direction,MMHH,MODEL_PATH=src/test/resources/index/mmhh.pt,SERIES_LENGTH=100,HASH_LENGTH=48,\n");
+
+      checkRead(
+          "SHOW INDEX FROM root.wind2.*",
+          "index series,index type,index attribute,\n"
+              + "root.wind2.*.direction,RTREE_PAA,FEATURE_DIM=4,MIN_ENTRIES=2,SERIES_LENGTH=15,MAX_ENTRIES=10,\n"
+              + "root.wind2.*.direction,MMHH,MODEL_PATH=src/test/resources/index/mmhh.pt,SERIES_LENGTH=100,HASH_LENGTH=48,\n");
     } catch (Exception e) {
       e.printStackTrace();
       fail(e.getMessage());
@@ -134,25 +128,13 @@ public class MMHHIndexReadIT {
     IoTDBDescriptor.getInstance().getConfig().setEnableIndex(false);
   }
 
-  @Test
-  public void checkRead() throws ClassNotFoundException {
+  private void checkRead(String SQL, String gt) throws ClassNotFoundException {
     Class.forName(Config.JDBC_DRIVER_NAME);
     try (Connection connection =
             DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
         Statement statement = connection.createStatement()) {
+      boolean hasIndex = statement.execute(SQL);
 
-      String querySQL =
-          String.format(
-              "SELECT TOP 2 direction FROM root.wind2.* WHERE direction LIKE (%s)",
-              getArrayRange(121, 121 + wholeDim));
-
-      System.out.println(querySQL);
-      boolean hasIndex = statement.execute(querySQL);
-      StringBuilder gt = new StringBuilder();
-      gt.append("Time,root.wind2.1.direction.(D=0.00),root.wind2.2.direction.(D=1.00),\n");
-      for (int i = 0; i < 100; i++) {
-        gt.append(String.format("%d,%.1f,%.1f,\n", i, 100f + i, 200f + i));
-      }
       Assert.assertTrue(hasIndex);
       try (ResultSet resultSet = statement.getResultSet()) {
         ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
@@ -168,7 +150,7 @@ public class MMHHIndexReadIT {
           sb.append("\n");
         }
         System.out.println(sb);
-        Assert.assertEquals(gt.toString(), sb.toString());
+        Assert.assertEquals(gt, sb.toString());
       }
     } catch (Exception e) {
       e.printStackTrace();
diff --git a/server/src/test/java/org/apache/iotdb/db/index/router/ProtoIndexRouterTest.java b/server/src/test/java/org/apache/iotdb/db/index/router/ProtoIndexRouterTest.java
index 381aa4e..5322e33 100644
--- a/server/src/test/java/org/apache/iotdb/db/index/router/ProtoIndexRouterTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/index/router/ProtoIndexRouterTest.java
@@ -104,7 +104,9 @@ public class ProtoIndexRouterTest {
     this.fakeCreateFunc =
         (indexSeries, indexInfoMap) ->
             new IndexProcessor(
-                indexSeries, testRouterDir + File.separator + "index_fake_" + indexSeries);
+                indexSeries,
+                testRouterDir + File.separator + "index_fake_" + indexSeries,
+                indexInfoMap);
   }
 
   private static final String testRouterDir = "test_protoIndexRouter";