37 return ra_exe_unit_in;
40 return ra_exe_unit_in;
43 std::list<std::shared_ptr<Analyzer::Expr>> quals;
44 quals.insert(quals.end(), ra_exe_unit_in.
quals.begin(), ra_exe_unit_in.
quals.end());
47 for (
const auto& join_condition_in : ra_exe_unit_in.
join_quals) {
50 for (
const auto& join_qual_expr_in : join_condition_in.quals) {
52 if (new_overlaps_quals) {
53 const auto& overlaps_quals = *new_overlaps_quals;
56 join_condition.quals.insert(join_condition.quals.end(),
57 overlaps_quals.join_quals.begin(),
58 overlaps_quals.join_quals.end());
61 join_condition.quals.insert(join_condition.quals.end(),
62 overlaps_quals.quals.begin(),
63 overlaps_quals.quals.end());
65 join_condition.quals.push_back(join_qual_expr_in);
68 join_condition_per_nesting_level.push_back(join_condition);
74 join_condition_per_nesting_level,
87 return ra_exe_unit_in;
90 return ra_exe_unit_in;
93 return ra_exe_unit_in;
95 if (ra_exe_unit_in.
quals.size() != 1) {
96 return ra_exe_unit_in;
104 if (!in_vals || in_vals->get_value_list().empty()) {
105 return ra_exe_unit_in;
107 for (
const auto& in_val : in_vals->get_value_list()) {
108 if (!std::dynamic_pointer_cast<Analyzer::Constant>(in_val)) {
112 if (dynamic_cast<const Analyzer::CaseExpr*>(in_vals->get_arg())) {
113 return ra_exe_unit_in;
121 const std::shared_ptr<Analyzer::CaseExpr> case_expr,
123 std::list<std::shared_ptr<Analyzer::Expr>> new_groupby_list;
124 std::vector<Analyzer::Expr*> new_target_exprs;
126 size_t groupby_idx{0};
128 for (
const auto& group_expr : ra_exe_unit_in.
groupby_exprs) {
131 if (*group_expr == *in_vals->
get_arg()) {
137 const size_t range_sz = expr_range.
getIntMax() - expr_range.getIntMin() + 1;
142 new_groupby_list.push_back(case_expr);
145 if (*target == *in_vals->
get_arg()) {
146 auto var_case_expr = makeExpr<Analyzer::Var>(
149 new_target_exprs.push_back(var_case_expr.get());
151 new_target_exprs.push_back(target);
156 new_groupby_list.push_back(group_expr);
161 return ra_exe_unit_in;
166 ra_exe_unit_in.
quals,
177 std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
181 auto case_cond = makeExpr<Analyzer::BinOper>(
183 auto in_val_copy = in_val->deep_copy();
184 auto ti = in_val_copy->get_type_info();
186 ti.set_comp_param(0);
188 in_val_copy->set_type_info(ti);
189 case_expr_list.emplace_back(case_cond, in_val_copy);
193 auto else_expr = case_expr_list.front().second;
194 return makeExpr<Analyzer::CaseExpr>(
195 case_expr_list.front().second->get_type_info(),
false, case_expr_list, else_expr);
204 return string_id > max_valid_int_value<int8_t>();
206 return string_id > max_valid_int_value<int16_t>();
208 return string_id > max_valid_int_value<int32_t>();
224 std::shared_ptr<Analyzer::Expr> column_to_update)
const {
230 throw std::runtime_error(
"Update via join not yet supported for temporary tables.");
233 auto new_column_value = ra_exe_unit_in.
target_exprs.front()->deep_copy();
234 const auto& new_column_ti = new_column_value->get_type_info();
235 if (column_to_update->get_type_info().is_dict_encoded_string()) {
236 CHECK(new_column_ti.is_dict_encoded_string());
237 if (new_column_ti.get_comp_param() > 0 &&
238 new_column_ti.get_comp_param() !=
239 column_to_update->get_type_info().get_comp_param()) {
240 throw std::runtime_error(
241 "Updating a dictionary encoded string using another dictionary encoded string "
242 "column is not yet supported, unless both columns share dictionaries.");
244 if (
auto uoper = dynamic_cast<Analyzer::UOper*>(new_column_value.get())) {
245 if (uoper->get_optype() ==
kCAST &&
247 const auto original_constant_expr =
249 CHECK(original_constant_expr);
250 CHECK(original_constant_expr->get_type_info().is_string());
256 CHECK(column_to_update->get_type_info().is_dict_encoded_string());
257 const auto dict_id = column_to_update->get_type_info().get_comp_param();
258 std::map<int, StringDictionary*> string_dicts;
259 const auto dd = cat->getMetadataForDict(dict_id,
true);
261 auto string_dict = dd->stringDict;
265 string_dict->getOrAdd(*original_constant_expr->get_constval().stringval);
267 throw std::runtime_error(
268 "Ran out of space in dictionary, cannot update column with dictionary "
269 "encoded string value. Dictionary ID: " +
272 if (string_id == inline_int_null_value<int32_t>()) {
281 new std::string(*original_constant_expr->get_constval().stringval);
282 Datum new_string_datum{datum};
285 makeExpr<Analyzer::Constant>(column_to_update->get_type_info(),
286 original_constant_expr->get_is_null(),
290 auto row_set_mem_owner =
executor_->getRowSetMemoryOwner();
291 CHECK(row_set_mem_owner);
292 auto& str_dict_generations = row_set_mem_owner->getStringDictionaryGenerations();
293 if (str_dict_generations.getGeneration(dict_id) > -1) {
294 str_dict_generations.updateGeneration(dict_id,
295 string_dict->storageEntryCount());
299 str_dict_generations.setGeneration(dict_id, string_dict->storageEntryCount());
307 std::shared_ptr<Analyzer::Expr> filter;
308 std::vector<std::shared_ptr<Analyzer::Expr>> filter_exprs;
309 filter_exprs.insert(filter_exprs.end(),
313 filter_exprs.end(), ra_exe_unit_in.
quals.begin(), ra_exe_unit_in.
quals.end());
315 if (filter_exprs.size() > 0) {
316 std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
318 if (filter_exprs.size() == 1) {
319 filter = filter_exprs.front();
322 std::next(filter_exprs.begin()),
324 filter_exprs.front(),
325 [](
const std::shared_ptr<Analyzer::Expr> a,
326 const std::shared_ptr<Analyzer::Expr> b) {
327 CHECK_EQ(a->get_type_info().get_type(), b->get_type_info().get_type());
328 return makeExpr<Analyzer::BinOper>(a->get_type_info().get_type(),
335 auto when_expr = filter;
336 case_expr_list.emplace_back(std::make_pair(when_expr, new_column_value));
339 auto col_to_update_var =
341 CHECK(col_to_update_var);
342 auto col_to_update_desc =
343 std::make_shared<const InputColDescriptor>(col_to_update_var->get_column_id(),
344 col_to_update_var->get_table_id(),
345 col_to_update_var->get_rte_idx());
346 auto existing_col_desc_it = std::find_if(
347 input_col_descs.begin(),
348 input_col_descs.end(),
349 [&col_to_update_desc](
const std::shared_ptr<const InputColDescriptor>& in) {
350 return *in == *col_to_update_desc;
352 if (existing_col_desc_it == input_col_descs.end()) {
353 input_col_descs.push_back(col_to_update_desc);
361 std::vector<Analyzer::Expr*> target_exprs;
379 return rewritten_exe_unit;
388 std::shared_ptr<Analyzer::ColumnVar> delete_column)
const {
395 throw std::runtime_error(
"Delete via join not yet supported for temporary tables.");
400 const auto deleted_constant =
401 makeExpr<Analyzer::Constant>(delete_column->get_type_info(),
false, true_datum);
405 std::shared_ptr<Analyzer::Expr> filter;
406 std::vector<std::shared_ptr<Analyzer::Expr>> filter_exprs;
407 filter_exprs.insert(filter_exprs.end(),
411 filter_exprs.end(), ra_exe_unit_in.
quals.begin(), ra_exe_unit_in.
quals.end());
413 if (filter_exprs.size() > 0) {
414 std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
416 if (filter_exprs.size() == 1) {
417 filter = filter_exprs.front();
420 std::next(filter_exprs.begin()),
422 filter_exprs.front(),
423 [](
const std::shared_ptr<Analyzer::Expr> a,
424 const std::shared_ptr<Analyzer::Expr> b) {
425 CHECK_EQ(a->get_type_info().get_type(), b->get_type_info().get_type());
426 return makeExpr<Analyzer::BinOper>(a->get_type_info().get_type(),
433 std::shared_ptr<Analyzer::Expr> column_to_update{
nullptr};
434 auto when_expr = filter;
435 case_expr_list.emplace_back(std::make_pair(when_expr, deleted_constant));
439 auto delete_col_desc_it = std::find_if(
440 input_col_descs.begin(),
441 input_col_descs.end(),
442 [&delete_column](
const std::shared_ptr<const InputColDescriptor>& in) {
443 return in->getColId() == delete_column->get_column_id();
445 CHECK(delete_col_desc_it == input_col_descs.end());
446 auto delete_col_desc =
447 std::make_shared<const InputColDescriptor>(delete_column->get_column_id(),
448 delete_column->get_table_id(),
449 delete_column->get_rte_idx());
450 input_col_descs.push_back(delete_col_desc);
454 auto delete_col_desc =
455 std::make_shared<const InputColDescriptor>(delete_column->get_column_id(),
456 delete_column->get_table_id(),
457 delete_column->get_rte_idx());
458 input_col_descs.push_back(delete_col_desc);
462 std::vector<Analyzer::Expr*> target_exprs;
480 return rewritten_exe_unit;
std::vector< Analyzer::Expr * > target_exprs
HOST DEVICE int get_size() const
size_t g_constrained_by_in_threshold
const std::optional< bool > union_all
std::vector< InputDescriptor > input_descs
std::vector< JoinCondition > JoinQualsPerNestingLevel
const std::list< std::shared_ptr< Analyzer::Expr > > groupby_exprs
Analyzer::ExpressionPtr rewrite_expr(const Analyzer::Expr *expr)
bool g_enable_overlaps_hashjoin
static std::shared_ptr< Analyzer::Expr > normalize(const std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr >>> &, const std::shared_ptr< Analyzer::Expr >)
Classes representing a parse tree.
RelAlgExecutionUnit rewrite(const RelAlgExecutionUnit &ra_exe_unit_in) const
const JoinQualsPerNestingLevel join_quals
RelAlgExecutionUnit rewriteOverlapsJoin(const RelAlgExecutionUnit &ra_exe_unit_in) const
DEVICE auto accumulate(ARGS &&...args)
boost::optional< OverlapsJoinConjunction > rewrite_overlaps_conjunction(const std::shared_ptr< Analyzer::Expr > expr)
ExpressionRange getExpressionRange(const Analyzer::BinOper *expr, const std::vector< InputTableInfo > &query_infos, const Executor *, boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
const std::shared_ptr< Analyzer::Estimator > estimator
bool check_string_id_overflow(const int32_t string_id, const SQLTypeInfo &ti)
RelAlgExecutionUnit rewriteColumnarUpdate(const RelAlgExecutionUnit &ra_exe_unit_in, std::shared_ptr< Analyzer::Expr > column_to_update) const
const std::list< std::shared_ptr< Analyzer::Expr > > & get_value_list() const
virtual std::shared_ptr< Analyzer::Expr > deep_copy() const =0
const std::vector< InputTableInfo > & query_infos_
std::list< std::shared_ptr< Analyzer::Expr > > quals
int64_t getIntMax() const
int64_t inline_fixed_encoding_null_val(const SQL_TYPE_INFO &ti)
std::shared_ptr< const query_state::QueryState > query_state
std::list< std::shared_ptr< const InputColDescriptor > > input_col_descs
RelAlgExecutionUnit rewriteColumnarDelete(const RelAlgExecutionUnit &ra_exe_unit_in, std::shared_ptr< Analyzer::ColumnVar > delete_column) const
static std::shared_ptr< Analyzer::CaseExpr > generateCaseForDomainValues(const Analyzer::InValues *)
RelAlgExecutionUnit rewriteConstrainedByIn(const RelAlgExecutionUnit &ra_exe_unit_in) const
const Expr * get_arg() const
std::list< std::shared_ptr< Analyzer::Expr > > simple_quals
RelAlgExecutionUnit rewriteConstrainedByInImpl(const RelAlgExecutionUnit &ra_exe_unit_in, const std::shared_ptr< Analyzer::CaseExpr >, const Analyzer::InValues *) const
std::vector< std::shared_ptr< Analyzer::Expr > > target_exprs_owned_