Skip to content

Commit

Permalink
[fix](stats) Fix analyze failed when there are thousands of partition…
Browse files Browse the repository at this point in the history
…s. (#24521)

It's caused by we used same query id for multiple queries of same olap analyze task, but many structures related to query execution depends on query id.
  • Loading branch information
Kikyou1997 authored Sep 18, 2023
1 parent dcabc06 commit 67e8951
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2571,6 +2571,9 @@ public StatementBase setParsedStmt(StatementBase parsedStmt) {

public List<ResultRow> executeInternalQuery() {
LOG.debug("INTERNAL QUERY: " + originStmt.toString());
UUID uuid = UUID.randomUUID();
TUniqueId queryId = new TUniqueId(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
context.setQueryId(queryId);
try {
List<ResultRow> resultRows = new ArrayList<>();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
import org.apache.doris.statistics.StatisticConstants;
import org.apache.doris.system.Frontend;
import org.apache.doris.system.SystemInfoService;
import org.apache.doris.thrift.TUniqueId;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -105,7 +104,6 @@
import java.util.Optional;
import java.util.Set;
import java.util.StringJoiner;
import java.util.UUID;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -188,9 +186,6 @@ public static AutoCloseConnectContext buildConnectContext(boolean limitScan) {
connectContext.setDatabase(FeConstants.INTERNAL_DB_NAME);
connectContext.setQualifiedUser(UserIdentity.ROOT.getQualifiedUser());
connectContext.setCurrentUserIdentity(UserIdentity.ROOT);
UUID uuid = UUID.randomUUID();
TUniqueId queryId = new TUniqueId(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
connectContext.setQueryId(queryId);
connectContext.setStartTime();
connectContext.setCluster(SystemInfoService.DEFAULT_CLUSTER);
return new AutoCloseConnectContext(connectContext);
Expand Down
21 changes: 21 additions & 0 deletions regression-test/suites/statistics/analyze_stats.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1035,5 +1035,26 @@ PARTITION `p599` VALUES IN (599)
SELECT * FROM analyze_test_with_schema_update;
"""

sql """
DROP TABLE IF EXISTS two_thousand_partition_table_test
"""

sql """
CREATE TABLE two_thousand_partition_table_test (col1 int(11451) not null)
DUPLICATE KEY(col1)
PARTITION BY RANGE(`col1`)
(
from (0) to (1000001) INTERVAL 500
)
DISTRIBUTED BY HASH(col1)
BUCKETS 3
PROPERTIES(
"replication_num"="1"
);
"""

sql """
ANALYZE TABLE two_thousand_partition_table_test WITH SYNC;
"""

}

0 comments on commit 67e8951

Please sign in to comment.