Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
[Bench] Reduce input cols number for fetch
Browse files Browse the repository at this point in the history
To estimate output size of result query to allocate buffer we are
running `count*` before some actual queries. This estimation requires
only query body argumnets without `select` arguments, so this commit
changes input_cols for `count*` query.

Resolves: #574

Signed-off-by: Dmitrii Makarenko <[email protected]>
  • Loading branch information
Devjiu committed Jul 20, 2023
1 parent ae22e1a commit 46afee5
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
46 changes: 45 additions & 1 deletion omniscidb/QueryEngine/CardinalityEstimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "ErrorHandling.h"
#include "ExpressionRewrite.h"
#include "RelAlgExecutor.h"
#include "Visitors/InputColumnsCollector.h"

size_t RelAlgExecutor::getNDVEstimation(const WorkUnit& work_unit,
const int64_t range,
Expand Down Expand Up @@ -101,8 +102,51 @@ RelAlgExecutionUnit create_ndv_execution_unit(const RelAlgExecutionUnit& ra_exe_
RelAlgExecutionUnit create_count_all_execution_unit(
const RelAlgExecutionUnit& ra_exe_unit,
hdk::ir::ExprPtr replacement_target) {
InputColumnsCollector input_columns_collector;
for (const auto& join_condition : ra_exe_unit.join_quals) {
for (const auto& q : join_condition.quals) {
input_columns_collector.visit(q.get());
}
}

for (const auto& q : ra_exe_unit.quals) {
input_columns_collector.visit(q.get());
}

for (const auto& q : ra_exe_unit.simple_quals) {
input_columns_collector.visit(q.get());
}

for (const auto& q : ra_exe_unit.groupby_exprs) {
if (!q)
break;
input_columns_collector.visit(q.get());
}

std::list<std::shared_ptr<const InputColDescriptor>> join_input_col_descs;
auto& input_column_descriptors = input_columns_collector.result();
for (auto& col_var : input_column_descriptors) {
for (auto& icol : ra_exe_unit.input_col_descs) {
if (icol->getColId() == col_var.getColId() &&
icol->getTableId() == col_var.getTableId()) {
join_input_col_descs.emplace_back(icol);
}
}
}

if (join_input_col_descs.empty()) {
join_input_col_descs.insert(join_input_col_descs.end(),
ra_exe_unit.input_col_descs.begin(),
ra_exe_unit.input_col_descs.end());
}

LOG(DEBUG1) << "Generating count* WU with following Input Columns ";
LOG(DEBUG1) << " [Only Join] Table/Col/Levels: ";
for (const auto& input_col_desc : join_input_col_descs) {
LOG(DEBUG1) << " " << input_col_desc->toString();
}
return {ra_exe_unit.input_descs,
ra_exe_unit.input_col_descs,
join_input_col_descs,
ra_exe_unit.simple_quals,
ra_exe_unit.quals,
ra_exe_unit.join_quals,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ void QueryFragmentDescriptor::buildFragmentPerKernelForTable(
}

ExecutionKernelDescriptor execution_kernel_desc{
device_id, {}, fragment.getNumTuples()};
/*device_id*/ device_id,
/*fragments*/ {},
/*outer_tuple_count*/ fragment.getNumTuples()};
if (table_desc_offset) {
const auto frag_ids =
executor->getTableFragmentIndices(ra_exe_unit,
Expand Down
10 changes: 1 addition & 9 deletions omniscidb/QueryEngine/JoinFilterPushDown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "IR/ExprCollector.h"
#include "IR/ExprRewriter.h"
#include "RelAlgExecutor.h"
#include "Visitors/InputColumnsCollector.h"

namespace {

Expand All @@ -27,15 +28,6 @@ class BindFilterToOutermostVisitor : public hdk::ir::ExprRewriter {
}
};

class InputColumnsCollector
: public hdk::ir::ExprCollector<std::unordered_set<InputColDescriptor>,
InputColumnsCollector> {
protected:
void visitColumnVar(const hdk::ir::ColumnVar* col_var) override {
result_.insert(InputColDescriptor(col_var->columnInfo(), 0));
}
};

} // namespace

/**
Expand Down
13 changes: 13 additions & 0 deletions omniscidb/QueryEngine/Visitors/InputColumnsCollector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <unordered_set>
#include "IR/ExprCollector.h"

class InputColumnsCollector
: public hdk::ir::ExprCollector<std::unordered_set<InputColDescriptor>,
InputColumnsCollector> {
protected:
void visitColumnVar(const hdk::ir::ColumnVar* col_var) override {
result_.insert(InputColDescriptor(col_var->columnInfo(), 0));
}
};

0 comments on commit 46afee5

Please sign in to comment.