diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java index 4a7b540d120b4d..24e0e7cba37392 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java @@ -1802,6 +1802,14 @@ private void handleQueryStmt() throws Exception { return; } + if (parsedStmt instanceof LogicalPlanAdapter) { + LogicalPlanAdapter logicalPlanAdapter = (LogicalPlanAdapter) parsedStmt; + LogicalPlan logicalPlan = logicalPlanAdapter.getLogicalPlan(); + if (logicalPlan instanceof org.apache.doris.nereids.trees.plans.algebra.SqlCache) { + isCached = true; + } + } + // handle selects that fe can do without be, so we can make sql tools happy, especially the setup step. // TODO FE not support doris field type conversion to arrow field type. if (!context.getConnectType().equals(ConnectType.ARROW_FLIGHT_SQL) diff --git a/regression-test/suites/nereids_p0/cache/parse_sql_from_sql_cache.groovy b/regression-test/suites/nereids_p0/cache/parse_sql_from_sql_cache.groovy index 8284873693693d..6aeeeed0ead602 100644 --- a/regression-test/suites/nereids_p0/cache/parse_sql_from_sql_cache.groovy +++ b/regression-test/suites/nereids_p0/cache/parse_sql_from_sql_cache.groovy @@ -784,6 +784,42 @@ suite("parse_sql_from_sql_cache") { sql "select /*+SET_VAR(disable_nereids_rules='')*/ /*comment1*/ * from test_use_plan_cache22 order by 1, 2" assertHasCache "select /*+SET_VAR(disable_nereids_rules='')*/ /*comment2*/ * from test_use_plan_cache22 order by 1, 2" + }), + extraThread("is_cache_profile", { + createTestTable "test_use_plan_cache23" + + // after partition changed 10s, the sql cache can be used + sleep(10000) + + sql "set enable_nereids_planner=true" + sql "set enable_fallback_to_original_planner=false" + sql "set enable_sql_cache=true" + + int randomInt = Math.random() * 2000000000 + sql "select ${randomInt} from test_use_plan_cache23" + profile("sql_cache_23_${randomInt}") { + run { + sql "/* sql_cache_23_${randomInt} */ select ${randomInt} from test_use_plan_cache23" + } + + check { profileString, exception -> + log.info(profileString) + assertTrue(profileString.contains("Is Cached: Yes")) + } + } + + randomInt = Math.random() * 2000000000 + sql "select * from (select $randomInt as id)a" + profile("sql_cache_23_${randomInt}_2") { + run { + sql "/* sql_cache_23_${randomInt}_2 */ select * from (select $randomInt as id)a" + } + + check { profileString, exception -> + log.info(profileString) + assertTrue(profileString.contains("Is Cached: Yes")) + } + } }) ).get() }