Commit 7512f30
[opt](staticstis) use count(1) for rowCount when scan full table (#58153)
### What problem does this PR solve?
when do sample, it will use table.getRowCount() as rowsCount, but the
table.getRowCount() may be stale because it depend on BE's report, then
it may occur rowsCount < ndv.
Then when if 10 * rowsCount < ndv, the analyze sql will fail.
Then the regression test statistics/analyze_stats.groovy is not stable,
and cause error:
```
Exception:
java.sql.SQLException: errCode = 2, detailMessage = Failed to analyze following columns:[id] Reasons: java.lang.RuntimeException: ColStatsData is invalid, skip analyzing. ('1763112020393--1-id',0,1763112019723,1763112020393,-1,'id',null,1,16,0,'1','201',64,'2025-11-14 17:41:14','105 :0.06 ;104 :0.06 ;103 :0.06 ;102 :0.06 ;101 :0.06 ;10 :0.06 ;9 :0.06 ;8 :0.06 ;7 :0.06 ;6 :0.06')
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:371)
at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
at org.apache.doris.regression.util.JdbcUtils$_executeToList_closure1.doCall(JdbcUtils.groovy:47)
at sun.reflect.GeneratedMethodAccessor33.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:343)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:328)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:279)
```
so when do sample and scan whole table, we use count(1) to represent
rowsCount.
Notice that this replace will not increase the excute cost, because the
staticstic sql has contained `count(1)`.1 parent 1d63c19 commit 7512f30
File tree
2 files changed
+7
-0
lines changed- fe/fe-core/src
- main/java/org/apache/doris/statistics
- test/java/org/apache/doris/statistics
2 files changed
+7
-0
lines changedLines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
| 274 | + | |
| 275 | + | |
274 | 276 | | |
275 | 277 | | |
276 | 278 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
375 | 375 | | |
376 | 376 | | |
377 | 377 | | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
378 | 383 | | |
379 | 384 | | |
380 | 385 | | |
| |||
0 commit comments