Skip to content

Commit 50547ea

Browse files
committed
BUG#38380978: Regression for TPC-DS Q1 with statistics cache
Problem: Stats were being exchanged between table scan and eq_ref paths, exchanging stats here lead to issues, because table scan and index lookups have different output rows, and should not be exchanged. Change-Id: Ifa672a761442c579ba576158c118914eb09000b6
1 parent 73ee6c6 commit 50547ea

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

sql/join_optimizer/join_optimizer.cc

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6494,6 +6494,19 @@ void CostingReceiver::CommitBitsetsToHeap(AccessPath *path) const {
64946494
return all_ok;
64956495
}
64966496

6497+
bool IsAccessPathRefType(AccessPath *path) {
6498+
return path->type == AccessPath::REF || path->type == AccessPath::EQ_REF;
6499+
}
6500+
/*
6501+
* This function returns true when 2 equivalent paths representing a Subgraph
6502+
* pair should not exchange their statistics from statistics cache, because due
6503+
* to actual execution characteristics the statistics could indeed be quite
6504+
* different.
6505+
*/
6506+
bool ArePathsStatsExchangeIneligible(AccessPath *path, AccessPath *other_path) {
6507+
return IsAccessPathRefType(path) || IsAccessPathRefType(other_path);
6508+
}
6509+
64976510
/**
64986511
Propose the given access path as an alternative to the existing access paths
64996512
for the same task (assuming any exist at all), and hold a “tournament” to find
@@ -6612,16 +6625,18 @@ AccessPath *CostingReceiver::ProposeAccessPath(
66126625
secondary_engine_nrows_params.access_path = path;
66136626
bool cur_use_sc =
66146627
ApplySecondaryEngineNrowsHook(secondary_engine_nrows_params);
6615-
/* we equalise Nrows for other similar paths, but not for REF's cause
6616-
* lookup and scan can have different Nrows. */
6617-
if (was_other_used_sc && path->type != AccessPath::REF) {
6628+
/* we equalise Nrows for other similar paths, but not for access paths
6629+
* where it might not make sense due to different execution
6630+
* characteristics. */
6631+
if (was_other_used_sc &&
6632+
!ArePathsStatsExchangeIneligible(path, other_path)) {
66186633
path->set_num_output_rows(other_path->num_output_rows());
66196634
if (path->num_output_rows_before_filter < path->num_output_rows()) {
66206635
path->num_output_rows_before_filter = path->num_output_rows();
66216636
}
66226637

66236638
} else if (!was_other_used_sc && cur_use_sc &&
6624-
other_path->type != AccessPath::REF) {
6639+
!ArePathsStatsExchangeIneligible(path, other_path)) {
66256640
other_path->set_num_output_rows(path->num_output_rows());
66266641
if (other_path->num_output_rows_before_filter <
66276642
other_path->num_output_rows()) {

0 commit comments

Comments
 (0)