Skip to content

Commit 9219e8d

Browse files
committed
Bug#34122706: Remove use_order flag from eq_ref path and iterator
Since eq_ref never returns more than one row, ordering it does not make sense. The eq_ref access path is always created with the use_order flag set to false, either hard-coded or implicitly by calling QEP_TAB::use_order() which returns false for eq_ref. There are also asserts in the eq ref iterator that check that the flag is set to false. Since the flag serves no purpose, we remove it from the eq_ref access path and the corresponding iterator class. Change-Id: I7b8b3b4922f0aa9865e5b080929739cb52fd93b2
1 parent 83f688b commit 9219e8d

File tree

6 files changed

+6
-15
lines changed

6 files changed

+6
-15
lines changed

sql/iterators/ref_row_iterators.cc

+2-4
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,9 @@ int ConstIterator::Read() {
109109
}
110110

111111
EQRefIterator::EQRefIterator(THD *thd, TABLE *table, TABLE_REF *ref,
112-
bool use_order, ha_rows *examined_rows)
112+
ha_rows *examined_rows)
113113
: TableRowIterator(thd, table),
114114
m_ref(ref),
115-
m_use_order(use_order),
116115
m_examined_rows(examined_rows) {}
117116

118117
/**
@@ -134,8 +133,7 @@ EQRefIterator::EQRefIterator(THD *thd, TABLE *table, TABLE_REF *ref,
134133

135134
bool EQRefIterator::Init() {
136135
if (!table()->file->inited) {
137-
assert(!m_use_order); // Don't expect sort req. for single row.
138-
int error = table()->file->ha_index_init(m_ref->key, m_use_order);
136+
int error = table()->file->ha_index_init(m_ref->key, /*sorted=*/false);
139137
if (error) {
140138
PrintError(error);
141139
return true;

sql/iterators/ref_row_iterators.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ class RefOrNullIterator final : public TableRowIterator {
100100
class EQRefIterator final : public TableRowIterator {
101101
public:
102102
// "examined_rows", if not nullptr, is incremented for each successful Read().
103-
EQRefIterator(THD *thd, TABLE *table, TABLE_REF *ref, bool use_order,
104-
ha_rows *examined_rows);
103+
EQRefIterator(THD *thd, TABLE *table, TABLE_REF *ref, ha_rows *examined_rows);
105104

106105
bool Init() override;
107106
int Read() override;
@@ -117,7 +116,6 @@ class EQRefIterator final : public TableRowIterator {
117116

118117
private:
119118
TABLE_REF *const m_ref;
120-
const bool m_use_order;
121119
bool m_first_record_since_init;
122120
ha_rows *const m_examined_rows;
123121
};

sql/join_optimizer/access_path.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,8 @@ unique_ptr_destroy_only<RowIterator> CreateIteratorFromAccessPath(
415415
}
416416
case AccessPath::EQ_REF: {
417417
const auto &param = path->eq_ref();
418-
iterator =
419-
NewIterator<EQRefIterator>(thd, mem_root, param.table, param.ref,
420-
param.use_order, examined_rows);
418+
iterator = NewIterator<EQRefIterator>(thd, mem_root, param.table,
419+
param.ref, examined_rows);
421420
break;
422421
}
423422
case AccessPath::PUSHED_JOIN_REF: {

sql/join_optimizer/access_path.h

-3
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,6 @@ struct AccessPath {
870870
struct {
871871
TABLE *table;
872872
TABLE_REF *ref;
873-
bool use_order;
874873
} eq_ref;
875874
struct {
876875
TABLE *table;
@@ -1270,14 +1269,12 @@ inline AccessPath *NewRefOrNullAccessPath(THD *thd, TABLE *table,
12701269
}
12711270

12721271
inline AccessPath *NewEQRefAccessPath(THD *thd, TABLE *table, TABLE_REF *ref,
1273-
bool use_order,
12741272
bool count_examined_rows) {
12751273
AccessPath *path = new (thd->mem_root) AccessPath;
12761274
path->type = AccessPath::EQ_REF;
12771275
path->count_examined_rows = count_examined_rows;
12781276
path->eq_ref().table = table;
12791277
path->eq_ref().ref = ref;
1280-
path->eq_ref().use_order = use_order;
12811278
return path;
12821279
}
12831280

sql/join_optimizer/join_optimizer.cc

-1
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,6 @@ bool CostingReceiver::ProposeRefAccess(
19691969
path.type = AccessPath::EQ_REF;
19701970
path.eq_ref().table = table;
19711971
path.eq_ref().ref = ref;
1972-
path.eq_ref().use_order = false;
19731972

19741973
// We could set really any ordering here if we wanted to.
19751974
// It's very rare that it should matter, though.

sql/sql_executor.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3599,7 +3599,7 @@ AccessPath *QEP_TAB::access_path() {
35993599

36003600
case JT_EQ_REF:
36013601
// May later change to a PushedJoinRefAccessPath if 'pushed'
3602-
path = NewEQRefAccessPath(join()->thd, table(), &ref(), use_order(),
3602+
path = NewEQRefAccessPath(join()->thd, table(), &ref(),
36033603
/*count_examined_rows=*/true);
36043604
used_ref = &ref();
36053605
break;

0 commit comments

Comments
 (0)