Skip to content

Commit

Permalink
[Fix](statistics)Fix update cached column stats bug (#23049)
Browse files Browse the repository at this point in the history
`show column cached stats` sometimes show wrong min/max value:
```
mysql> show column cached stats hive.tpch100.region;
+-------------+-------+------+----------+-----------+---------------+------+------+--------------+
| column_name | count | ndv  | num_null | data_size | avg_size_byte | min  | max  | updated_time |
+-------------+-------+------+----------+-----------+---------------+------+------+--------------+
| r_regionkey | 5.0   | 5.0  | 0.0      | 24.0      | 4.0           | N/A  | N/A  | null         |
| r_comment   | 5.0   | 5.0  | 0.0      | 396.0     | 66.0          | N/A  | N/A  | null         |
| r_name      | 5.0   | 5.0  | 0.0      | 40.8      | 6.8           | N/A  | N/A  | null         |
+-------------+-------+------+----------+-----------+---------------+------+------+--------------+
```
This pr is to fix this bug. It is because while transferring ColumnStatistic object to JSON, it doesn't contain the minExpr and maxExpr attribute.
  • Loading branch information
Jibing-Li authored Aug 17, 2023
1 parent d59c2f7 commit 3fe419e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
import org.apache.doris.qe.QueryState;
import org.apache.doris.qe.StmtExecutor;
import org.apache.doris.qe.VariableMgr;
import org.apache.doris.statistics.ColumnStatistic;
import org.apache.doris.statistics.StatisticsCacheKey;
import org.apache.doris.statistics.query.QueryStats;
import org.apache.doris.system.Backend;
Expand Down Expand Up @@ -2943,8 +2942,13 @@ private TGetBinlogLagResult getBinlogLagImpl(TGetBinlogRequest request, String c
@Override
public TStatus updateStatsCache(TUpdateFollowerStatsCacheRequest request) throws TException {
StatisticsCacheKey key = GsonUtils.GSON.fromJson(request.key, StatisticsCacheKey.class);
ColumnStatistic columnStatistic = GsonUtils.GSON.fromJson(request.colStats, ColumnStatistic.class);
Env.getCurrentEnv().getStatisticsCache().putCache(key, columnStatistic);
/*
TODO: Need to handle minExpr and maxExpr, so that we can generate the columnStatistic
here and use putCache to update cached directly.
ColumnStatistic columnStatistic = GsonUtils.GSON.fromJson(request.colStats, ColumnStatistic.class);
Env.getCurrentEnv().getStatisticsCache().putCache(key, columnStatistic);
*/
Env.getCurrentEnv().getStatisticsCache().refreshColStatsSync(key.tableId, key.idxId, key.colName);
return new TStatus(TStatusCode.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ public void syncLoadColStats(long tableId, long idxId, String colName) {
updateFollowerStatsCacheRequest.key = GsonUtils.GSON.toJson(k);
updateFollowerStatsCacheRequest.colStats = GsonUtils.GSON.toJson(c);
for (Frontend frontend : Env.getCurrentEnv().getFrontends(FrontendNodeType.FOLLOWER)) {
if (frontend.getHost().equals(Env.getCurrentEnv().getSelfNode().getHost())) {
// Doesn't need to send request to current node.
continue;
}
TNetworkAddress address = new TNetworkAddress(frontend.getHost(),
frontend.getRpcPort());
FrontendService.Client client = null;
Expand Down

0 comments on commit 3fe419e

Please sign in to comment.