You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "LikemeXY (via GitHub)" <gi...@apache.org> on 2025/08/22 05:10:52 UTC

[I] [Bug] SessionPool数据查询很慢 [iotdb]

LikemeXY opened a new issue, #16235:
URL: https://github.com/apache/iotdb/issues/16235

   ### Search before asking
   
   - [x] I searched in the [issues](https://github.com/apache/iotdb/issues) and found nothing similar.
   
   
   ### Version
   
   版本2.0.4
   
   ### Describe the bug and provide the minimal reproduce step
   
   代码如下
   @Slf4j
   @Component
   public class IoTDBTemplate {
       @Resource
       private IoTDBConfig config;
   
       public static final String TIMESTAMP = "timestamp";
   
       public static final String TIME = "Time";
   
       public static final String ID = "ID";
   
       private static SessionPool session;
   
       @PostConstruct
       private void init() {
           if (session != null) {
               return;
           }
           try {
               session = config.getSession();
           } catch (Exception e) {
               log.error("iotdb初始化失败: {}", e.getMessage());
           }
       }
       public IPage<Map<String, Object>> page(IotDBSearchModel model) throws IoTDBConnectionException, StatementExecutionException {
           IPage<Map<String, Object>> page = new PageDTO<>();
           String sql = this.getPageSql(model);
           long t1 = System.currentTimeMillis();
           SessionDataSetWrapper sessionDataSetWrapper = this.executeQueryStatement(sql);
           long t2 = System.currentTimeMillis();
           page.setRecords(this.packageData(sessionDataSetWrapper));
           long t3 = System.currentTimeMillis();
   
           log.info("查询时间:{}", t2 - t1);
           log.info("解析时间:{}", t3 - t2);
           page.setTotal(this.findAll(model).size());
           page.setPages(model.getPageSize());
           page.setCurrent(model.getPageNumber());
           return page;
       }
      /**
        * 执行sql查询
        * 使用完SessionDataSetWrapper之后需要session.closeResultSet(wrapper)
        *
        * @param sql
        * @return
        */
       private SessionDataSetWrapper executeQueryStatement(String sql) {
           SessionDataSetWrapper wrapper;
           try {
               wrapper = session.executeQueryStatement(sql);
           } catch (Exception e) {
               log.error("IoTDBSql执行错误:{{}}", sql);
               log.error(e.getMessage());
               throw new RuntimeException(e);
           }
           return wrapper;
       }
   /**
        * 解析封装数据
        *
        * @param wrapper
        * @return
        * @throws StatementExecutionException
        * @throws IoTDBConnectionException
        */
       private List<Map<String, Object>> packageData(SessionDataSetWrapper wrapper) throws StatementExecutionException, IoTDBConnectionException {
           List<Map<String, Object>> items;
           try {
               items = new ArrayList<>();
               SessionDataSet.DataIterator dataIterator = wrapper.iterator();
               while (dataIterator.next()) {
                   Map<String, Object> map = new HashMap<>();
                   for (String columnName : wrapper.getColumnNames()) {
   
                       if (TIME.equals(columnName)) {
                           map.put("ID", dataIterator.getString(columnName));
                       } else {
                           String[] split = columnName.split("\\.");
                           map.put(split[split.length - 1], dataIterator.getString(columnName));
                       }
                   }
                   items.add(map);
               }
           } finally {
               if (session != null && wrapper != null) {
                   session.closeResultSet(wrapper);
               } else {
                   log.error("关闭sessionPool和wrapper失败!!!");
               }
           }
           return items;
       }
   }
   
   
   
   ### What did you expect to see?
   
   使用1.3.x的SessionPool没有问题
   
   ### What did you see instead?
   
   每一次查询时间过长
   <img width="1030" height="696" alt="Image" src="https://github.com/user-attachments/assets/eb9376a5-5b4a-4515-9374-5d05ee4e2ccc" />
   
   <img width="1384" height="201" alt="Image" src="https://github.com/user-attachments/assets/85a9afbd-e8b6-4ed7-8288-b1946fd0b9da" />
   
   ### Anything else?
   
   _No response_
   
   ### Are you willing to submit a PR?
   
   - [x] I'm willing to submit a PR!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] SessionPool数据查询很慢 [iotdb]

Posted by "LikemeXY (via GitHub)" <gi...@apache.org>.
LikemeXY commented on issue #16235:
URL: https://github.com/apache/iotdb/issues/16235#issuecomment-3222649472

   > 说明一下看时间是0.039s。 只有在代码中查询时慢吗?
   
   是的,我把sessionPool版本降到1.3.3,没有问题


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] SessionPool数据查询很慢 [iotdb]

Posted by "LikemeXY (via GitHub)" <gi...@apache.org>.
LikemeXY closed issue #16235: [Bug] SessionPool数据查询很慢
URL: https://github.com/apache/iotdb/issues/16235


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] SessionPool数据查询很慢 [iotdb]

Posted by "CritasWang (via GitHub)" <gi...@apache.org>.
CritasWang commented on issue #16235:
URL: https://github.com/apache/iotdb/issues/16235#issuecomment-3256801886

   有个属性 enableAutoFecth 设置为 false 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] SessionPool数据查询很慢 [iotdb]

Posted by "CritasWang (via GitHub)" <gi...@apache.org>.
CritasWang commented on issue #16235:
URL: https://github.com/apache/iotdb/issues/16235#issuecomment-3218981238

   图中 explain 看 时间是 0.039s。
   只有在 代码中查询时慢吗


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] SessionPool数据查询很慢 [iotdb]

Posted by "LikemeXY (via GitHub)" <gi...@apache.org>.
LikemeXY commented on issue #16235:
URL: https://github.com/apache/iotdb/issues/16235#issuecomment-3213078796

   [IoTDBTemplate.java](https://github.com/user-attachments/files/21930589/IoTDBTemplate.java)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org