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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to