duckdb 0.3.3-dev1401.0 → 0.3.3-dev1404.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
- "version": "0.3.3-dev1401.0",
4
+ "version": "0.3.3-dev1404.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -155796,6 +155796,7 @@ public:
155796
155796
 
155797
155797
 
155798
155798
 
155799
+
155799
155800
  namespace duckdb {
155800
155801
 
155801
155802
  SchemaCatalogEntry *Binder::BindSchema(CreateInfo &info) {
@@ -156010,10 +156011,18 @@ BoundStatement Binder::Bind(CreateStatement &stmt) {
156010
156011
  for (auto &keyname : fk.pk_columns) {
156011
156012
  auto entry = pk_table_entry_ptr->name_map.find(keyname);
156012
156013
  if (entry == pk_table_entry_ptr->name_map.end()) {
156013
- throw ParserException("column \"%s\" named in key does not exist", keyname);
156014
+ throw BinderException("column \"%s\" named in key does not exist", keyname);
156014
156015
  }
156015
156016
  fk.info.pk_keys.push_back(entry->second);
156016
156017
  }
156018
+ auto index = pk_table_entry_ptr->storage->info->indexes.FindForeignKeyIndex(
156019
+ fk.info.pk_keys, ForeignKeyType::FK_TYPE_PRIMARY_KEY_TABLE);
156020
+ if (!index) {
156021
+ auto fk_column_names = StringUtil::Join(fk.pk_columns, ",");
156022
+ throw BinderException("Failed to create foreign key on %s(%s): no UNIQUE or PRIMARY KEY constraint "
156023
+ "present on these columns",
156024
+ pk_table_entry_ptr->name, fk_column_names);
156025
+ }
156017
156026
  }
156018
156027
  }
156019
156028
  // We first check if there are any user types, if yes we check to which custom types they refer.
@@ -156196,7 +156205,7 @@ static void BindConstraints(Binder &binder, BoundCreateTableInfo &info) {
156196
156205
  for (auto &keyname : fk.pk_columns) {
156197
156206
  auto entry = info.name_map.find(keyname);
156198
156207
  if (entry == info.name_map.end()) {
156199
- throw ParserException("column \"%s\" named in key does not exist", keyname);
156208
+ throw BinderException("column \"%s\" named in key does not exist", keyname);
156200
156209
  }
156201
156210
  fk.info.pk_keys.push_back(entry->second);
156202
156211
  }
@@ -156205,7 +156214,7 @@ static void BindConstraints(Binder &binder, BoundCreateTableInfo &info) {
156205
156214
  for (auto &keyname : fk.fk_columns) {
156206
156215
  auto entry = info.name_map.find(keyname);
156207
156216
  if (entry == info.name_map.end()) {
156208
- throw ParserException("column \"%s\" named in key does not exist", keyname);
156217
+ throw BinderException("column \"%s\" named in key does not exist", keyname);
156209
156218
  }
156210
156219
  fk.info.fk_keys.push_back(entry->second);
156211
156220
  }
@@ -170374,11 +170383,17 @@ static void VerifyCheckConstraint(TableCatalogEntry &table, Expression &expr, Da
170374
170383
  }
170375
170384
  }
170376
170385
 
170377
- static bool FindColumnIndex(const vector<idx_t> *keys_ptr, const vector<column_t> &index_column_ids) {
170378
- for (idx_t i = 0; i < keys_ptr->size(); i++) {
170386
+ static bool IsForeignKeyIndex(const vector<idx_t> &fk_keys, Index &index, ForeignKeyType fk_type) {
170387
+ if (fk_type == ForeignKeyType::FK_TYPE_PRIMARY_KEY_TABLE ? !index.IsUnique() : !index.IsForeign()) {
170388
+ return false;
170389
+ }
170390
+ if (fk_keys.size() != index.column_ids.size()) {
170391
+ return false;
170392
+ }
170393
+ for (auto &fk_key : fk_keys) {
170379
170394
  bool is_found = false;
170380
- for (idx_t j = 0; j < index_column_ids.size(); j++) {
170381
- if ((*keys_ptr)[i] == index_column_ids[j]) {
170395
+ for (auto &index_key : index.column_ids) {
170396
+ if (fk_key == index_key) {
170382
170397
  is_found = true;
170383
170398
  break;
170384
170399
  }
@@ -170387,10 +170402,20 @@ static bool FindColumnIndex(const vector<idx_t> *keys_ptr, const vector<column_t
170387
170402
  return false;
170388
170403
  }
170389
170404
  }
170390
-
170391
170405
  return true;
170392
170406
  }
170393
170407
 
170408
+ Index *TableIndexList::FindForeignKeyIndex(const vector<idx_t> &fk_keys, ForeignKeyType fk_type) {
170409
+ Index *result = nullptr;
170410
+ Scan([&](Index &index) {
170411
+ if (IsForeignKeyIndex(fk_keys, index, fk_type)) {
170412
+ result = &index;
170413
+ }
170414
+ return false;
170415
+ });
170416
+ return result;
170417
+ }
170418
+
170394
170419
  static void VerifyForeignKeyConstraint(const BoundForeignKeyConstraint &bfk, ClientContext &context, DataChunk &chunk,
170395
170420
  bool is_append) {
170396
170421
  const vector<idx_t> *src_keys_ptr = &bfk.info.fk_keys;
@@ -170429,26 +170454,24 @@ static void VerifyForeignKeyConstraint(const BoundForeignKeyConstraint &bfk, Cli
170429
170454
  err_msgs.resize(count);
170430
170455
  tran_err_msgs.resize(count);
170431
170456
 
170457
+ auto fk_type = is_append ? ForeignKeyType::FK_TYPE_PRIMARY_KEY_TABLE : ForeignKeyType::FK_TYPE_FOREIGN_KEY_TABLE;
170432
170458
  // check whether or not the chunk can be inserted or deleted into the referenced table' storage
170433
- TableIndexList &table_indices = data_table->info->indexes;
170434
- table_indices.Scan([&](Index &index) {
170435
- if (FindColumnIndex(dst_keys_ptr, index.column_ids)) {
170436
- if (is_append) {
170437
- index.VerifyAppendForeignKey(dst_chunk, err_msgs.data());
170438
- } else {
170439
- index.VerifyDeleteForeignKey(dst_chunk, err_msgs.data());
170440
- }
170441
- }
170442
- return false;
170443
- });
170444
-
170459
+ auto index = data_table->info->indexes.FindForeignKeyIndex(*dst_keys_ptr, fk_type);
170460
+ if (!index) {
170461
+ throw InternalException("Internal Foreign Key error: could not find index to verify...");
170462
+ }
170463
+ if (is_append) {
170464
+ index->VerifyAppendForeignKey(dst_chunk, err_msgs.data());
170465
+ } else {
170466
+ index->VerifyDeleteForeignKey(dst_chunk, err_msgs.data());
170467
+ }
170445
170468
  // check whether or not the chunk can be inserted or deleted into the referenced table' transaction local storage
170446
170469
  auto &transaction = Transaction::GetTransaction(context);
170447
170470
  bool transaction_check = transaction.storage.Find(data_table);
170448
170471
  if (transaction_check) {
170449
170472
  vector<unique_ptr<Index>> &transact_index_vec = transaction.storage.GetIndexes(data_table);
170450
170473
  for (idx_t i = 0; i < transact_index_vec.size(); i++) {
170451
- if (FindColumnIndex(dst_keys_ptr, transact_index_vec[i]->column_ids)) {
170474
+ if (IsForeignKeyIndex(*dst_keys_ptr, *transact_index_vec[i], fk_type)) {
170452
170475
  if (is_append) {
170453
170476
  transact_index_vec[i]->VerifyAppendForeignKey(dst_chunk, tran_err_msgs.data());
170454
170477
  } else {
package/src/duckdb.hpp CHANGED
@@ -11,8 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
11
11
  #pragma once
12
12
  #define DUCKDB_AMALGAMATION 1
13
13
  #define DUCKDB_AMALGAMATION_EXTENDED 1
14
- #define DUCKDB_SOURCE_ID "29c1379da"
15
- #define DUCKDB_VERSION "v0.3.3-dev1401"
14
+ #define DUCKDB_SOURCE_ID "514748429"
15
+ #define DUCKDB_VERSION "v0.3.3-dev1404"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //
@@ -20947,6 +20947,8 @@ public:
20947
20947
  return indexes.size();
20948
20948
  }
20949
20949
 
20950
+ Index *FindForeignKeyIndex(const vector<idx_t> &fk_keys, ForeignKeyType fk_type);
20951
+
20950
20952
  private:
20951
20953
  //! Indexes associated with the current table
20952
20954
  mutex indexes_lock;