StarRocks / starrocks

StarRocks, a Linux Foundation project, is a next-generation sub-second MPP OLAP database for full analytics scenarios, including multi-dimensional analytics, real-time analytics, and ad-hoc queries.
https://starrocks.io
Apache License 2.0
8.67k stars 1.75k forks source link

JDBC大查询找不到profile信息 #47516

Closed 871765337 closed 2 months ago

871765337 commented 2 months ago

sr版本:3.2.3 MySQL jdbc版本:8.0.29 springboot版本:3.2.3 问题描述:

  1. 通过jdbc多次提交执行sql,执行时间大于设置的大查询时长20s时,只有少数查询被profile记录
  2. 偶尔会出现长时间执行结果不返回也不报错的情况,看资源占用情况sql已经结束 sr设置:big_query_profile_threshold=20s

连接代码:


import com.alibaba.druid.pool.DruidDataSource;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

@Configuration
@Slf4j
@MapperScan(basePackages = "com.xxx.dao.data", sqlSessionFactoryRef = "srSqlSessionFactory")
public class SrDataSourceConfig {

    @Resource
    private MybatisPlusInterceptor mybatisPlusInterceptor;

    @Bean(name = "srDataSource")
    @ConfigurationProperties("spring.datasource.sr")
    public DruidDataSource srDataSource() {
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setSocketTimeout(15 * 60 * 1000);
        return druidDataSource;
    }

    @Bean(name = "srSqlSessionFactory")
    public SqlSessionFactory sqlSessionFactory() throws Exception {
        MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean();
        factoryBean.setDataSource(srDataSource());
        factoryBean.setPlugins(mybatisPlusInterceptor);
        factoryBean.setTypeAliasesPackage("com.xxx.entity");
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        factoryBean.setMapperLocations(resolver.getResources("classpath*:data_mapper/*.xml"));
        MybatisConfiguration mybatisConfiguration = new MybatisConfiguration();
        mybatisConfiguration.setDefaultStatementTimeout(60 * 15);
        factoryBean.setConfiguration(mybatisConfiguration);
        return factoryBean.getObject();
    }

    @Bean(name = "srDataSqlSessionTemplate")
    public SqlSessionTemplate testSqlSessionTemplate() throws Exception {
        return new SqlSessionTemplate(sqlSessionFactory());
    }
}

sql执行代码,多次执行指的是多次调用executeSelect方法

@Component
@Slf4j
public class SrSelector implements ISrSelector {

    @Resource(name = "srDataSource")
    private DruidDataSource dataSource;

    @Override
    public ResultSet executeSelect(String sql)  throws SQLException {
        ResultSet rs = null;
        log.debug("执行SR 查询 {}", sql);
        try (
                Connection connection = dataSource.getConnection();
                PreparedStatement ps = connection.prepareStatement(sql)) {
          rs = ps.executeQuery();
            return rs;
        } catch (SQLException e) {
            throw e;
        } 
    }
871765337 commented 2 months ago

升级到3.3之后暂时没有遇到该问题