Skip to content

Commit 6ea0701

Browse files
author
Erik Froseth
committed
WL#2241 Implement hash join
Post push fix: Do not copy NULL flags to the row buffer if they are unused. Change-Id: Ib3b3daaa8abc93567f99bf36bd1ef2c7633368a7
1 parent 59cd19e commit 6ea0701

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

sql/hash_join_buffer.cc

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ TableCollection::TableCollection(const std::vector<QEP_TAB *> &tables)
100100
m_has_blob_column(false) {
101101
for (QEP_TAB *qep_tab : tables) {
102102
m_tables_bitmap |= qep_tab->table_ref->map();
103-
m_ref_and_null_bytes_size += qep_tab->table()->s->null_bytes;
104103

105104
// When constructing the iterator tree, we might end up adding a
106105
// WeedoutIterator _after_ a HashJoinIterator has been constructed.
@@ -128,6 +127,12 @@ TableCollection::TableCollection(const std::vector<QEP_TAB *> &tables)
128127
}
129128
}
130129
}
130+
131+
if (qep_tab->used_null_fields || qep_tab->used_uneven_bit_fields) {
132+
m_ref_and_null_bytes_size += qep_tab->table()->s->null_bytes;
133+
table.copy_null_flags = true;
134+
}
135+
131136
m_tables.push_back(table);
132137
}
133138
}
@@ -216,7 +221,7 @@ size_t ComputeRowSizeUpperBound(const TableCollection &tables) {
216221
return total_size;
217222
}
218223

219-
static bool keep_current_rowid(QEP_TAB *qep_tab) {
224+
static bool KeepCurrentRowId(QEP_TAB *qep_tab) {
220225
return qep_tab->keep_current_rowid &&
221226
(qep_tab->copy_current_rowid == nullptr ||
222227
qep_tab->copy_current_rowid->buffer_is_bound());
@@ -242,8 +247,10 @@ bool StoreFromTableBuffers(const TableCollection &tables, String *buffer) {
242247
const TABLE *table = tbl.qep_tab->table();
243248

244249
// Store the NULL flags.
245-
memcpy(dptr, table->null_flags, table->s->null_bytes);
246-
dptr += table->s->null_bytes;
250+
if (tbl.copy_null_flags) {
251+
memcpy(dptr, table->null_flags, table->s->null_bytes);
252+
dptr += table->s->null_bytes;
253+
}
247254

248255
if (tbl.qep_tab->table()->is_nullable()) {
249256
const size_t null_row_size = sizeof(tbl.qep_tab->table()->null_row);
@@ -252,7 +259,7 @@ bool StoreFromTableBuffers(const TableCollection &tables, String *buffer) {
252259
dptr += null_row_size;
253260
}
254261

255-
if (keep_current_rowid(tbl.qep_tab)) {
262+
if (KeepCurrentRowId(tbl.qep_tab)) {
256263
// Store the row ID, since it is needed by weedout.
257264
memcpy(dptr, table->file->ref, table->file->ref_length);
258265
dptr += table->file->ref_length;
@@ -284,7 +291,7 @@ void LoadIntoTableBuffers(const TableCollection &tables, BufferRow row) {
284291
for (const Table &tbl : tables.tables()) {
285292
TABLE *table = tbl.qep_tab->table();
286293

287-
if (table->s->null_bytes > 0) {
294+
if (tbl.copy_null_flags) {
288295
memcpy(table->null_flags, ptr, table->s->null_bytes);
289296
ptr += table->s->null_bytes;
290297
}
@@ -296,7 +303,7 @@ void LoadIntoTableBuffers(const TableCollection &tables, BufferRow row) {
296303
ptr += null_row_size;
297304
}
298305

299-
if (keep_current_rowid(tbl.qep_tab)) {
306+
if (KeepCurrentRowId(tbl.qep_tab)) {
300307
memcpy(table->file->ref, ptr, table->file->ref_length);
301308
ptr += table->file->ref_length;
302309
table->ref_is_set_without_position_call = true;

sql/hash_join_buffer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ struct Table {
107107
// innermost hash join that should call position(). The other hash join
108108
// iterators should rely on the innermost iterator to set the row ID.
109109
bool can_call_position{false};
110+
111+
// Whether to copy the NULL flags or not.
112+
bool copy_null_flags{false};
110113
};
111114

112115
/// A structure that contains a list of tables for the hash join operation,

0 commit comments

Comments
 (0)