Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/duckdb/src/execution/join_hashtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,19 +888,25 @@ idx_t ScanStructure::ResolvePredicates(DataChunk &keys, SelectionVector &match_s
}

// If there is a matcher for the probing side because of non-equality predicates, use it
idx_t result_count;
if (ht.needs_chain_matcher) {
idx_t no_match_count = 0;
auto &matcher = no_match_sel ? ht.row_matcher_probe_no_match_sel : ht.row_matcher_probe;
D_ASSERT(matcher);

// we need to only use the vectors with the indices of the columns that are used in the probe phase, namely
// the non-equality columns
return matcher->Match(keys, key_state.vector_data, match_sel, this->count, pointers, no_match_sel,
no_match_count);
result_count =
matcher->Match(keys, key_state.vector_data, match_sel, this->count, pointers, no_match_sel, no_match_count);
} else {
// no match sel is the opposite of match sel
return this->count;
result_count = this->count;
}

// Update total probe match count
ht.total_probe_matches.fetch_add(result_count, std::memory_order_relaxed);

return result_count;
}

idx_t ScanStructure::ScanInnerJoin(DataChunk &keys, SelectionVector &result_vector) {
Expand Down
5 changes: 5 additions & 0 deletions src/duckdb/src/execution/operator/join/physical_hash_join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ class HashJoinGlobalSinkState : public GlobalSinkState {
}
}

~HashJoinGlobalSinkState() override {
DUCKDB_LOG(context, PhysicalOperatorLogType, op, "PhysicalHashJoin", "GetData",
{{"total_probe_matches", to_string(hash_table->total_probe_matches)}});
}

void ScheduleFinalize(Pipeline &pipeline, Event &event);
void InitializeProbeSpill();

Expand Down
6 changes: 3 additions & 3 deletions src/duckdb/src/function/table/version/pragma_version.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef DUCKDB_PATCH_VERSION
#define DUCKDB_PATCH_VERSION "2-dev279"
#define DUCKDB_PATCH_VERSION "2-dev284"
#endif
#ifndef DUCKDB_MINOR_VERSION
#define DUCKDB_MINOR_VERSION 4
Expand All @@ -8,10 +8,10 @@
#define DUCKDB_MAJOR_VERSION 1
#endif
#ifndef DUCKDB_VERSION
#define DUCKDB_VERSION "v1.4.2-dev279"
#define DUCKDB_VERSION "v1.4.2-dev284"
#endif
#ifndef DUCKDB_SOURCE_ID
#define DUCKDB_SOURCE_ID "783f08ffd8"
#define DUCKDB_SOURCE_ID "7ce99bc041"
#endif
#include "duckdb/function/table/system_functions.hpp"
#include "duckdb/main/database.hpp"
Expand Down
2 changes: 2 additions & 0 deletions src/duckdb/src/include/duckdb/execution/join_hashtable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ class JoinHashTable {
uint64_t bitmask = DConstants::INVALID_INDEX;
//! Whether or not we error on multiple rows found per match in a SINGLE join
bool single_join_error_on_multiple_rows = true;
//! Number of probe matches
atomic<idx_t> total_probe_matches {0};

struct {
mutex mj_lock;
Expand Down
12 changes: 10 additions & 2 deletions src/duckdb/src/include/duckdb/main/relation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,27 @@ class Relation : public enable_shared_from_this<Relation> {

//! Insert the data from this relation into a table
DUCKDB_API shared_ptr<Relation> InsertRel(const string &schema_name, const string &table_name);
DUCKDB_API shared_ptr<Relation> InsertRel(const string &catalog_name, const string &schema_name,
const string &table_name);
DUCKDB_API void Insert(const string &table_name);
DUCKDB_API void Insert(const string &schema_name, const string &table_name);
DUCKDB_API void Insert(const string &catalog_name, const string &schema_name, const string &table_name);
//! Insert a row (i.e.,list of values) into a table
DUCKDB_API void Insert(const vector<vector<Value>> &values);
DUCKDB_API void Insert(vector<vector<unique_ptr<ParsedExpression>>> &&expressions);
DUCKDB_API virtual void Insert(const vector<vector<Value>> &values);
DUCKDB_API virtual void Insert(vector<vector<unique_ptr<ParsedExpression>>> &&expressions);
//! Create a table and insert the data from this relation into that table
DUCKDB_API shared_ptr<Relation> CreateRel(const string &schema_name, const string &table_name,
bool temporary = false,
OnCreateConflict on_conflict = OnCreateConflict::ERROR_ON_CONFLICT);
DUCKDB_API shared_ptr<Relation> CreateRel(const string &catalog_name, const string &schema_name,
const string &table_name, bool temporary = false,
OnCreateConflict on_conflict = OnCreateConflict::ERROR_ON_CONFLICT);
DUCKDB_API void Create(const string &table_name, bool temporary = false,
OnCreateConflict on_conflict = OnCreateConflict::ERROR_ON_CONFLICT);
DUCKDB_API void Create(const string &schema_name, const string &table_name, bool temporary = false,
OnCreateConflict on_conflict = OnCreateConflict::ERROR_ON_CONFLICT);
DUCKDB_API void Create(const string &catalog_name, const string &schema_name, const string &table_name,
bool temporary = false, OnCreateConflict on_conflict = OnCreateConflict::ERROR_ON_CONFLICT);

//! Write a relation to a CSV file
DUCKDB_API shared_ptr<Relation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ class CreateTableRelation : public Relation {
public:
CreateTableRelation(shared_ptr<Relation> child, string schema_name, string table_name, bool temporary,
OnCreateConflict on_conflict);
CreateTableRelation(shared_ptr<Relation> child, string catalog_name, string schema_name, string table_name,
bool temporary, OnCreateConflict on_conflict);

shared_ptr<Relation> child;
string catalog_name;
string schema_name;
string table_name;
vector<ColumnDefinition> columns;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ namespace duckdb {
class InsertRelation : public Relation {
public:
InsertRelation(shared_ptr<Relation> child, string schema_name, string table_name);
InsertRelation(shared_ptr<Relation> child, string catalog_name, string schema_name, string table_name);

shared_ptr<Relation> child;
string catalog_name;
string schema_name;
string table_name;
vector<ColumnDefinition> columns;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class TableRelation : public Relation {

unique_ptr<TableRef> GetTableRef() override;

void Insert(const vector<vector<Value>> &values) override;
void Insert(vector<vector<unique_ptr<ParsedExpression>>> &&expressions) override;
void Update(const string &update, const string &condition = string()) override;
void Update(vector<string> column_names, vector<unique_ptr<ParsedExpression>> &&update,
unique_ptr<ParsedExpression> condition = nullptr) override;
Expand Down
40 changes: 28 additions & 12 deletions src/duckdb/src/main/relation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,24 @@ BoundStatement Relation::Bind(Binder &binder) {
}

shared_ptr<Relation> Relation::InsertRel(const string &schema_name, const string &table_name) {
return make_shared_ptr<InsertRelation>(shared_from_this(), schema_name, table_name);
return InsertRel(INVALID_CATALOG, schema_name, table_name);
}

shared_ptr<Relation> Relation::InsertRel(const string &catalog_name, const string &schema_name,
const string &table_name) {
return make_shared_ptr<InsertRelation>(shared_from_this(), catalog_name, schema_name, table_name);
}

void Relation::Insert(const string &table_name) {
Insert(INVALID_SCHEMA, table_name);
}

void Relation::Insert(const string &schema_name, const string &table_name) {
auto insert = InsertRel(schema_name, table_name);
Insert(INVALID_CATALOG, schema_name, table_name);
}

void Relation::Insert(const string &catalog_name, const string &schema_name, const string &table_name) {
auto insert = InsertRel(catalog_name, schema_name, table_name);
auto res = insert->Execute();
if (res->HasError()) {
const string prepended_message = "Failed to insert into table '" + table_name + "': ";
Expand All @@ -258,30 +267,37 @@ void Relation::Insert(const string &schema_name, const string &table_name) {
}

void Relation::Insert(const vector<vector<Value>> &values) {
vector<string> column_names;
auto rel = make_shared_ptr<ValueRelation>(context->GetContext(), values, std::move(column_names), "values");
rel->Insert(GetAlias());
throw InvalidInputException("INSERT with values can only be used on base tables!");
}

void Relation::Insert(vector<vector<unique_ptr<ParsedExpression>>> &&expressions) {
vector<string> column_names;
auto rel = make_shared_ptr<ValueRelation>(context->GetContext(), std::move(expressions), std::move(column_names),
"values");
rel->Insert(GetAlias());
(void)std::move(expressions);
throw InvalidInputException("INSERT with expressions can only be used on base tables!");
}

shared_ptr<Relation> Relation::CreateRel(const string &schema_name, const string &table_name, bool temporary,
OnCreateConflict on_conflict) {
return make_shared_ptr<CreateTableRelation>(shared_from_this(), schema_name, table_name, temporary, on_conflict);
return CreateRel(INVALID_CATALOG, schema_name, table_name, temporary, on_conflict);
}

shared_ptr<Relation> Relation::CreateRel(const string &catalog_name, const string &schema_name,
const string &table_name, bool temporary, OnCreateConflict on_conflict) {
return make_shared_ptr<CreateTableRelation>(shared_from_this(), catalog_name, schema_name, table_name, temporary,
on_conflict);
}

void Relation::Create(const string &table_name, bool temporary, OnCreateConflict on_conflict) {
Create(INVALID_SCHEMA, table_name, temporary, on_conflict);
Create(INVALID_CATALOG, INVALID_SCHEMA, table_name, temporary, on_conflict);
}

void Relation::Create(const string &schema_name, const string &table_name, bool temporary,
OnCreateConflict on_conflict) {
auto create = CreateRel(schema_name, table_name, temporary, on_conflict);
Create(INVALID_CATALOG, schema_name, table_name, temporary, on_conflict);
}

void Relation::Create(const string &catalog_name, const string &schema_name, const string &table_name, bool temporary,
OnCreateConflict on_conflict) {
auto create = CreateRel(catalog_name, schema_name, table_name, temporary, on_conflict);
auto res = create->Execute();
if (res->HasError()) {
const string prepended_message = "Failed to create table '" + table_name + "': ";
Expand Down
9 changes: 9 additions & 0 deletions src/duckdb/src/main/relation/create_table_relation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@ CreateTableRelation::CreateTableRelation(shared_ptr<Relation> child_p, string sc
TryBindRelation(columns);
}

CreateTableRelation::CreateTableRelation(shared_ptr<Relation> child_p, string catalog_name, string schema_name,
string table_name, bool temporary_p, OnCreateConflict on_conflict)
: Relation(child_p->context, RelationType::CREATE_TABLE_RELATION), child(std::move(child_p)),
catalog_name(std::move(catalog_name)), schema_name(std::move(schema_name)), table_name(std::move(table_name)),
temporary(temporary_p), on_conflict(on_conflict) {
TryBindRelation(columns);
}

BoundStatement CreateTableRelation::Bind(Binder &binder) {
auto select = make_uniq<SelectStatement>();
select->node = child->GetQueryNode();

CreateStatement stmt;
auto info = make_uniq<CreateTableInfo>();
info->catalog = catalog_name;
info->schema = schema_name;
info->table = table_name;
info->query = std::move(select);
Expand Down
7 changes: 7 additions & 0 deletions src/duckdb/src/main/relation/insert_relation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ InsertRelation::InsertRelation(shared_ptr<Relation> child_p, string schema_name,
TryBindRelation(columns);
}

InsertRelation::InsertRelation(shared_ptr<Relation> child_p, string catalog_name, string schema_name, string table_name)
: Relation(child_p->context, RelationType::INSERT_RELATION), child(std::move(child_p)),
catalog_name(std::move(catalog_name)), schema_name(std::move(schema_name)), table_name(std::move(table_name)) {
TryBindRelation(columns);
}

BoundStatement InsertRelation::Bind(Binder &binder) {
InsertStatement stmt;
auto select = make_uniq<SelectStatement>();
select->node = child->GetQueryNode();

stmt.catalog = catalog_name;
stmt.schema = schema_name;
stmt.table = table_name;
stmt.select_statement = std::move(select);
Expand Down
14 changes: 14 additions & 0 deletions src/duckdb/src/main/relation/table_relation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "duckdb/parser/query_node/select_node.hpp"
#include "duckdb/parser/expression/star_expression.hpp"
#include "duckdb/main/relation/delete_relation.hpp"
#include "duckdb/main/relation/value_relation.hpp"
#include "duckdb/main/relation/update_relation.hpp"
#include "duckdb/parser/parser.hpp"
#include "duckdb/main/client_context.hpp"
Expand Down Expand Up @@ -87,4 +88,17 @@ void TableRelation::Delete(const string &condition) {
del->Execute();
}

void TableRelation::Insert(const vector<vector<Value>> &values) {
vector<string> column_names;
auto rel = make_shared_ptr<ValueRelation>(context->GetContext(), values, std::move(column_names), "values");
rel->Insert(description->database, description->schema, description->table);
}

void TableRelation::Insert(vector<vector<unique_ptr<ParsedExpression>>> &&expressions) {
vector<string> column_names;
auto rel = make_shared_ptr<ValueRelation>(context->GetContext(), std::move(expressions), std::move(column_names),
"values");
rel->Insert(description->database, description->schema, description->table);
}

} // namespace duckdb