duckdb 0.3.2-dev521.0 → 0.3.2-dev569.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 +1 -1
- package/src/duckdb.cpp +609 -3322
- package/src/duckdb.hpp +3514 -398
package/src/duckdb.cpp
CHANGED
|
@@ -292,121 +292,6 @@ enum class IndexType {
|
|
|
292
292
|
|
|
293
293
|
|
|
294
294
|
|
|
295
|
-
//===----------------------------------------------------------------------===//
|
|
296
|
-
// DuckDB
|
|
297
|
-
//
|
|
298
|
-
// duckdb/parser/tableref.hpp
|
|
299
|
-
//
|
|
300
|
-
//
|
|
301
|
-
//===----------------------------------------------------------------------===//
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
//===----------------------------------------------------------------------===//
|
|
307
|
-
// DuckDB
|
|
308
|
-
//
|
|
309
|
-
// duckdb/common/enums/tableref_type.hpp
|
|
310
|
-
//
|
|
311
|
-
//
|
|
312
|
-
//===----------------------------------------------------------------------===//
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
namespace duckdb {
|
|
319
|
-
|
|
320
|
-
//===--------------------------------------------------------------------===//
|
|
321
|
-
// Table Reference Types
|
|
322
|
-
//===--------------------------------------------------------------------===//
|
|
323
|
-
enum class TableReferenceType : uint8_t {
|
|
324
|
-
INVALID = 0, // invalid table reference type
|
|
325
|
-
BASE_TABLE = 1, // base table reference
|
|
326
|
-
SUBQUERY = 2, // output of a subquery
|
|
327
|
-
JOIN = 3, // output of join
|
|
328
|
-
CROSS_PRODUCT = 4, // out of cartesian product
|
|
329
|
-
TABLE_FUNCTION = 5, // table producing function
|
|
330
|
-
EXPRESSION_LIST = 6, // expression list
|
|
331
|
-
CTE = 7, // Recursive CTE
|
|
332
|
-
EMPTY = 8 // placeholder for empty FROM
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
} // namespace duckdb
|
|
336
|
-
|
|
337
|
-
//===----------------------------------------------------------------------===//
|
|
338
|
-
// DuckDB
|
|
339
|
-
//
|
|
340
|
-
// duckdb/parser/parsed_data/sample_options.hpp
|
|
341
|
-
//
|
|
342
|
-
//
|
|
343
|
-
//===----------------------------------------------------------------------===//
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
namespace duckdb {
|
|
353
|
-
|
|
354
|
-
enum class SampleMethod : uint8_t { SYSTEM_SAMPLE = 0, BERNOULLI_SAMPLE = 1, RESERVOIR_SAMPLE = 2 };
|
|
355
|
-
|
|
356
|
-
string SampleMethodToString(SampleMethod method);
|
|
357
|
-
|
|
358
|
-
struct SampleOptions {
|
|
359
|
-
Value sample_size;
|
|
360
|
-
bool is_percentage;
|
|
361
|
-
SampleMethod method;
|
|
362
|
-
int64_t seed = -1;
|
|
363
|
-
|
|
364
|
-
unique_ptr<SampleOptions> Copy();
|
|
365
|
-
void Serialize(Serializer &serializer);
|
|
366
|
-
static unique_ptr<SampleOptions> Deserialize(Deserializer &source);
|
|
367
|
-
static bool Equals(SampleOptions *a, SampleOptions *b);
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
} // namespace duckdb
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
namespace duckdb {
|
|
374
|
-
class Deserializer;
|
|
375
|
-
class Serializer;
|
|
376
|
-
|
|
377
|
-
//! Represents a generic expression that returns a table.
|
|
378
|
-
class TableRef {
|
|
379
|
-
public:
|
|
380
|
-
explicit TableRef(TableReferenceType type) : type(type) {
|
|
381
|
-
}
|
|
382
|
-
virtual ~TableRef() {
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
TableReferenceType type;
|
|
386
|
-
string alias;
|
|
387
|
-
//! Sample options (if any)
|
|
388
|
-
unique_ptr<SampleOptions> sample;
|
|
389
|
-
//! The location in the query (if any)
|
|
390
|
-
idx_t query_location = DConstants::INVALID_INDEX;
|
|
391
|
-
|
|
392
|
-
public:
|
|
393
|
-
//! Convert the object to a string
|
|
394
|
-
virtual string ToString() const;
|
|
395
|
-
void Print();
|
|
396
|
-
|
|
397
|
-
virtual bool Equals(const TableRef *other) const;
|
|
398
|
-
|
|
399
|
-
virtual unique_ptr<TableRef> Copy() = 0;
|
|
400
|
-
|
|
401
|
-
//! Serializes a TableRef to a stand-alone binary blob
|
|
402
|
-
virtual void Serialize(Serializer &serializer);
|
|
403
|
-
//! Deserializes a blob back into a TableRef
|
|
404
|
-
static unique_ptr<TableRef> Deserialize(Deserializer &source);
|
|
405
|
-
|
|
406
|
-
//! Copy the properties of this table ref to the target
|
|
407
|
-
void CopyProperties(TableRef &target) const;
|
|
408
|
-
};
|
|
409
|
-
} // namespace duckdb
|
|
410
295
|
|
|
411
296
|
|
|
412
297
|
|
|
@@ -520,1097 +405,6 @@ public:
|
|
|
520
405
|
|
|
521
406
|
|
|
522
407
|
|
|
523
|
-
//===----------------------------------------------------------------------===//
|
|
524
|
-
// DuckDB
|
|
525
|
-
//
|
|
526
|
-
// duckdb/planner/binder.hpp
|
|
527
|
-
//
|
|
528
|
-
//
|
|
529
|
-
//===----------------------------------------------------------------------===//
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
//===----------------------------------------------------------------------===//
|
|
536
|
-
// DuckDB
|
|
537
|
-
//
|
|
538
|
-
// duckdb/parser/tokens.hpp
|
|
539
|
-
//
|
|
540
|
-
//
|
|
541
|
-
//===----------------------------------------------------------------------===//
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
namespace duckdb {
|
|
546
|
-
|
|
547
|
-
//===--------------------------------------------------------------------===//
|
|
548
|
-
// Statements
|
|
549
|
-
//===--------------------------------------------------------------------===//
|
|
550
|
-
class SQLStatement;
|
|
551
|
-
|
|
552
|
-
class AlterStatement;
|
|
553
|
-
class CallStatement;
|
|
554
|
-
class CopyStatement;
|
|
555
|
-
class CreateStatement;
|
|
556
|
-
class DeleteStatement;
|
|
557
|
-
class DropStatement;
|
|
558
|
-
class InsertStatement;
|
|
559
|
-
class SelectStatement;
|
|
560
|
-
class TransactionStatement;
|
|
561
|
-
class UpdateStatement;
|
|
562
|
-
class PrepareStatement;
|
|
563
|
-
class ExecuteStatement;
|
|
564
|
-
class PragmaStatement;
|
|
565
|
-
class ShowStatement;
|
|
566
|
-
class ExplainStatement;
|
|
567
|
-
class ExportStatement;
|
|
568
|
-
class VacuumStatement;
|
|
569
|
-
class RelationStatement;
|
|
570
|
-
class SetStatement;
|
|
571
|
-
class LoadStatement;
|
|
572
|
-
|
|
573
|
-
//===--------------------------------------------------------------------===//
|
|
574
|
-
// Query Node
|
|
575
|
-
//===--------------------------------------------------------------------===//
|
|
576
|
-
class QueryNode;
|
|
577
|
-
class SelectNode;
|
|
578
|
-
class SetOperationNode;
|
|
579
|
-
class RecursiveCTENode;
|
|
580
|
-
|
|
581
|
-
//===--------------------------------------------------------------------===//
|
|
582
|
-
// Expressions
|
|
583
|
-
//===--------------------------------------------------------------------===//
|
|
584
|
-
class ParsedExpression;
|
|
585
|
-
|
|
586
|
-
class BetweenExpression;
|
|
587
|
-
class CaseExpression;
|
|
588
|
-
class CastExpression;
|
|
589
|
-
class CollateExpression;
|
|
590
|
-
class ColumnRefExpression;
|
|
591
|
-
class ComparisonExpression;
|
|
592
|
-
class ConjunctionExpression;
|
|
593
|
-
class ConstantExpression;
|
|
594
|
-
class DefaultExpression;
|
|
595
|
-
class FunctionExpression;
|
|
596
|
-
class LambdaExpression;
|
|
597
|
-
class OperatorExpression;
|
|
598
|
-
class ParameterExpression;
|
|
599
|
-
class PositionalReferenceExpression;
|
|
600
|
-
class StarExpression;
|
|
601
|
-
class SubqueryExpression;
|
|
602
|
-
class WindowExpression;
|
|
603
|
-
|
|
604
|
-
//===--------------------------------------------------------------------===//
|
|
605
|
-
// Constraints
|
|
606
|
-
//===--------------------------------------------------------------------===//
|
|
607
|
-
class Constraint;
|
|
608
|
-
|
|
609
|
-
class NotNullConstraint;
|
|
610
|
-
class CheckConstraint;
|
|
611
|
-
class UniqueConstraint;
|
|
612
|
-
|
|
613
|
-
//===--------------------------------------------------------------------===//
|
|
614
|
-
// TableRefs
|
|
615
|
-
//===--------------------------------------------------------------------===//
|
|
616
|
-
class TableRef;
|
|
617
|
-
|
|
618
|
-
class BaseTableRef;
|
|
619
|
-
class CrossProductRef;
|
|
620
|
-
class JoinRef;
|
|
621
|
-
class SubqueryRef;
|
|
622
|
-
class TableFunctionRef;
|
|
623
|
-
class EmptyTableRef;
|
|
624
|
-
class ExpressionListRef;
|
|
625
|
-
|
|
626
|
-
//===--------------------------------------------------------------------===//
|
|
627
|
-
// Other
|
|
628
|
-
//===--------------------------------------------------------------------===//
|
|
629
|
-
struct SampleOptions;
|
|
630
|
-
|
|
631
|
-
} // namespace duckdb
|
|
632
|
-
|
|
633
|
-
//===----------------------------------------------------------------------===//
|
|
634
|
-
// DuckDB
|
|
635
|
-
//
|
|
636
|
-
// duckdb/planner/bind_context.hpp
|
|
637
|
-
//
|
|
638
|
-
//
|
|
639
|
-
//===----------------------------------------------------------------------===//
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
//===----------------------------------------------------------------------===//
|
|
646
|
-
// DuckDB
|
|
647
|
-
//
|
|
648
|
-
// duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp
|
|
649
|
-
//
|
|
650
|
-
//
|
|
651
|
-
//===----------------------------------------------------------------------===//
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
namespace duckdb {
|
|
660
|
-
|
|
661
|
-
class Catalog;
|
|
662
|
-
class Constraint;
|
|
663
|
-
|
|
664
|
-
struct CreateTableFunctionInfo;
|
|
665
|
-
|
|
666
|
-
//! A table function in the catalog
|
|
667
|
-
class TableFunctionCatalogEntry : public StandardEntry {
|
|
668
|
-
public:
|
|
669
|
-
TableFunctionCatalogEntry(Catalog *catalog, SchemaCatalogEntry *schema, CreateTableFunctionInfo *info);
|
|
670
|
-
|
|
671
|
-
//! The table function
|
|
672
|
-
vector<TableFunction> functions;
|
|
673
|
-
};
|
|
674
|
-
} // namespace duckdb
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
//===----------------------------------------------------------------------===//
|
|
680
|
-
// DuckDB
|
|
681
|
-
//
|
|
682
|
-
// duckdb/parser/expression/columnref_expression.hpp
|
|
683
|
-
//
|
|
684
|
-
//
|
|
685
|
-
//===----------------------------------------------------------------------===//
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
namespace duckdb {
|
|
693
|
-
|
|
694
|
-
//! Represents a reference to a column from either the FROM clause or from an
|
|
695
|
-
//! alias
|
|
696
|
-
class ColumnRefExpression : public ParsedExpression {
|
|
697
|
-
public:
|
|
698
|
-
//! Specify both the column and table name
|
|
699
|
-
ColumnRefExpression(string column_name, string table_name);
|
|
700
|
-
//! Only specify the column name, the table name will be derived later
|
|
701
|
-
explicit ColumnRefExpression(string column_name);
|
|
702
|
-
//! Specify a set of names
|
|
703
|
-
explicit ColumnRefExpression(vector<string> column_names);
|
|
704
|
-
|
|
705
|
-
//! The stack of names in order of which they appear (column_names[0].column_names[1].column_names[2]....)
|
|
706
|
-
vector<string> column_names;
|
|
707
|
-
|
|
708
|
-
public:
|
|
709
|
-
bool IsQualified() const;
|
|
710
|
-
const string &GetColumnName() const;
|
|
711
|
-
const string &GetTableName() const;
|
|
712
|
-
bool IsScalar() const override {
|
|
713
|
-
return false;
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
string GetName() const override;
|
|
717
|
-
string ToString() const override;
|
|
718
|
-
|
|
719
|
-
static bool Equals(const ColumnRefExpression *a, const ColumnRefExpression *b);
|
|
720
|
-
hash_t Hash() const override;
|
|
721
|
-
|
|
722
|
-
unique_ptr<ParsedExpression> Copy() const override;
|
|
723
|
-
|
|
724
|
-
void Serialize(Serializer &serializer) override;
|
|
725
|
-
static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
|
|
726
|
-
};
|
|
727
|
-
} // namespace duckdb
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
//===----------------------------------------------------------------------===//
|
|
731
|
-
// DuckDB
|
|
732
|
-
//
|
|
733
|
-
// duckdb/parser/qualified_name_set.hpp
|
|
734
|
-
//
|
|
735
|
-
//
|
|
736
|
-
//===----------------------------------------------------------------------===//
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
//===----------------------------------------------------------------------===//
|
|
741
|
-
// DuckDB
|
|
742
|
-
//
|
|
743
|
-
// duckdb/parser/qualified_name.hpp
|
|
744
|
-
//
|
|
745
|
-
//
|
|
746
|
-
//===----------------------------------------------------------------------===//
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
namespace duckdb {
|
|
754
|
-
|
|
755
|
-
struct QualifiedName {
|
|
756
|
-
string schema;
|
|
757
|
-
string name;
|
|
758
|
-
|
|
759
|
-
//! Parse the (optional) schema and a name from a string in the format of e.g. "schema"."table"; if there is no dot
|
|
760
|
-
//! the schema will be set to INVALID_SCHEMA
|
|
761
|
-
static QualifiedName Parse(string input) {
|
|
762
|
-
string schema;
|
|
763
|
-
string name;
|
|
764
|
-
idx_t idx = 0;
|
|
765
|
-
vector<string> entries;
|
|
766
|
-
string entry;
|
|
767
|
-
normal:
|
|
768
|
-
//! quote
|
|
769
|
-
for (; idx < input.size(); idx++) {
|
|
770
|
-
if (input[idx] == '"') {
|
|
771
|
-
idx++;
|
|
772
|
-
goto quoted;
|
|
773
|
-
} else if (input[idx] == '.') {
|
|
774
|
-
goto separator;
|
|
775
|
-
}
|
|
776
|
-
entry += input[idx];
|
|
777
|
-
}
|
|
778
|
-
goto end;
|
|
779
|
-
separator:
|
|
780
|
-
entries.push_back(entry);
|
|
781
|
-
entry = "";
|
|
782
|
-
idx++;
|
|
783
|
-
goto normal;
|
|
784
|
-
quoted:
|
|
785
|
-
//! look for another quote
|
|
786
|
-
for (; idx < input.size(); idx++) {
|
|
787
|
-
if (input[idx] == '"') {
|
|
788
|
-
//! unquote
|
|
789
|
-
idx++;
|
|
790
|
-
goto normal;
|
|
791
|
-
}
|
|
792
|
-
entry += input[idx];
|
|
793
|
-
}
|
|
794
|
-
throw ParserException("Unterminated quote in qualified name!");
|
|
795
|
-
end:
|
|
796
|
-
if (entries.empty()) {
|
|
797
|
-
schema = INVALID_SCHEMA;
|
|
798
|
-
name = entry;
|
|
799
|
-
} else if (entries.size() == 1) {
|
|
800
|
-
schema = entries[0];
|
|
801
|
-
name = entry;
|
|
802
|
-
} else {
|
|
803
|
-
throw ParserException("Expected schema.entry or entry: too many entries found");
|
|
804
|
-
}
|
|
805
|
-
return QualifiedName {schema, name};
|
|
806
|
-
}
|
|
807
|
-
};
|
|
808
|
-
|
|
809
|
-
struct QualifiedColumnName {
|
|
810
|
-
QualifiedColumnName() {
|
|
811
|
-
}
|
|
812
|
-
QualifiedColumnName(string table_p, string column_p) : table(move(table_p)), column(move(column_p)) {
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
string schema;
|
|
816
|
-
string table;
|
|
817
|
-
string column;
|
|
818
|
-
};
|
|
819
|
-
|
|
820
|
-
} // namespace duckdb
|
|
821
|
-
|
|
822
|
-
//===----------------------------------------------------------------------===//
|
|
823
|
-
// DuckDB
|
|
824
|
-
//
|
|
825
|
-
// duckdb/common/types/hash.hpp
|
|
826
|
-
//
|
|
827
|
-
//
|
|
828
|
-
//===----------------------------------------------------------------------===//
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
namespace duckdb {
|
|
836
|
-
|
|
837
|
-
struct string_t;
|
|
838
|
-
|
|
839
|
-
// efficient hash function that maximizes the avalanche effect and minimizes
|
|
840
|
-
// bias
|
|
841
|
-
// see: https://nullprogram.com/blog/2018/07/31/
|
|
842
|
-
|
|
843
|
-
inline hash_t murmurhash64(uint64_t x) {
|
|
844
|
-
return x * UINT64_C(0xbf58476d1ce4e5b9);
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
inline hash_t murmurhash32(uint32_t x) {
|
|
848
|
-
return murmurhash64(x);
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
template <class T>
|
|
852
|
-
hash_t Hash(T value) {
|
|
853
|
-
return murmurhash32(value);
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
//! Combine two hashes by XORing them
|
|
857
|
-
inline hash_t CombineHash(hash_t left, hash_t right) {
|
|
858
|
-
return left ^ right;
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
template <>
|
|
862
|
-
hash_t Hash(uint64_t val);
|
|
863
|
-
template <>
|
|
864
|
-
hash_t Hash(int64_t val);
|
|
865
|
-
template <>
|
|
866
|
-
hash_t Hash(hugeint_t val);
|
|
867
|
-
template <>
|
|
868
|
-
hash_t Hash(float val);
|
|
869
|
-
template <>
|
|
870
|
-
hash_t Hash(double val);
|
|
871
|
-
template <>
|
|
872
|
-
hash_t Hash(const char *val);
|
|
873
|
-
template <>
|
|
874
|
-
hash_t Hash(char *val);
|
|
875
|
-
template <>
|
|
876
|
-
hash_t Hash(string_t val);
|
|
877
|
-
template <>
|
|
878
|
-
hash_t Hash(interval_t val);
|
|
879
|
-
hash_t Hash(const char *val, size_t size);
|
|
880
|
-
hash_t Hash(uint8_t *val, size_t size);
|
|
881
|
-
|
|
882
|
-
} // namespace duckdb
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
namespace duckdb {
|
|
887
|
-
|
|
888
|
-
struct QualifiedColumnHashFunction {
|
|
889
|
-
uint64_t operator()(const QualifiedColumnName &a) const {
|
|
890
|
-
std::hash<std::string> str_hasher;
|
|
891
|
-
return str_hasher(a.schema) ^ str_hasher(a.table) ^ str_hasher(a.column);
|
|
892
|
-
}
|
|
893
|
-
};
|
|
894
|
-
|
|
895
|
-
struct QualifiedColumnEquality {
|
|
896
|
-
bool operator()(const QualifiedColumnName &a, const QualifiedColumnName &b) const {
|
|
897
|
-
return a.schema == b.schema && a.table == b.table && a.column == b.column;
|
|
898
|
-
}
|
|
899
|
-
};
|
|
900
|
-
|
|
901
|
-
using qualified_column_set_t = unordered_set<QualifiedColumnName, QualifiedColumnHashFunction, QualifiedColumnEquality>;
|
|
902
|
-
|
|
903
|
-
} // namespace duckdb
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
//===----------------------------------------------------------------------===//
|
|
907
|
-
// DuckDB
|
|
908
|
-
//
|
|
909
|
-
// duckdb/planner/expression_binder.hpp
|
|
910
|
-
//
|
|
911
|
-
//
|
|
912
|
-
//===----------------------------------------------------------------------===//
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
//===----------------------------------------------------------------------===//
|
|
918
|
-
// DuckDB
|
|
919
|
-
//
|
|
920
|
-
// duckdb/parser/expression/bound_expression.hpp
|
|
921
|
-
//
|
|
922
|
-
//
|
|
923
|
-
//===----------------------------------------------------------------------===//
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
namespace duckdb {
|
|
932
|
-
|
|
933
|
-
//! BoundExpression is an intermediate dummy class used by the binder. It is a ParsedExpression but holds an Expression.
|
|
934
|
-
//! It represents a successfully bound expression. It is used in the Binder to prevent re-binding of already bound parts
|
|
935
|
-
//! when dealing with subqueries.
|
|
936
|
-
class BoundExpression : public ParsedExpression {
|
|
937
|
-
public:
|
|
938
|
-
BoundExpression(unique_ptr<Expression> expr)
|
|
939
|
-
: ParsedExpression(ExpressionType::INVALID, ExpressionClass::BOUND_EXPRESSION), expr(move(expr)) {
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
unique_ptr<Expression> expr;
|
|
943
|
-
|
|
944
|
-
public:
|
|
945
|
-
string ToString() const override {
|
|
946
|
-
return expr->ToString();
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
bool Equals(const BaseExpression *other) const override {
|
|
950
|
-
return false;
|
|
951
|
-
}
|
|
952
|
-
hash_t Hash() const override {
|
|
953
|
-
return 0;
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
unique_ptr<ParsedExpression> Copy() const override {
|
|
957
|
-
throw SerializationException("Cannot copy or serialize bound expression");
|
|
958
|
-
}
|
|
959
|
-
};
|
|
960
|
-
|
|
961
|
-
} // namespace duckdb
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
namespace duckdb {
|
|
969
|
-
|
|
970
|
-
class Binder;
|
|
971
|
-
class ClientContext;
|
|
972
|
-
class QueryNode;
|
|
973
|
-
|
|
974
|
-
class ScalarFunctionCatalogEntry;
|
|
975
|
-
class AggregateFunctionCatalogEntry;
|
|
976
|
-
class MacroCatalogEntry;
|
|
977
|
-
class CatalogEntry;
|
|
978
|
-
class SimpleFunction;
|
|
979
|
-
|
|
980
|
-
struct MacroBinding;
|
|
981
|
-
|
|
982
|
-
struct BoundColumnReferenceInfo {
|
|
983
|
-
string name;
|
|
984
|
-
idx_t query_location;
|
|
985
|
-
};
|
|
986
|
-
|
|
987
|
-
struct BindResult {
|
|
988
|
-
BindResult() {
|
|
989
|
-
}
|
|
990
|
-
explicit BindResult(string error) : error(error) {
|
|
991
|
-
}
|
|
992
|
-
explicit BindResult(unique_ptr<Expression> expr) : expression(move(expr)) {
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
bool HasError() {
|
|
996
|
-
return !error.empty();
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
unique_ptr<Expression> expression;
|
|
1000
|
-
string error;
|
|
1001
|
-
};
|
|
1002
|
-
|
|
1003
|
-
class ExpressionBinder {
|
|
1004
|
-
public:
|
|
1005
|
-
ExpressionBinder(Binder &binder, ClientContext &context, bool replace_binder = false);
|
|
1006
|
-
virtual ~ExpressionBinder();
|
|
1007
|
-
|
|
1008
|
-
//! The target type that should result from the binder. If the result is not of this type, a cast to this type will
|
|
1009
|
-
//! be added. Defaults to INVALID.
|
|
1010
|
-
LogicalType target_type;
|
|
1011
|
-
|
|
1012
|
-
public:
|
|
1013
|
-
unique_ptr<Expression> Bind(unique_ptr<ParsedExpression> &expr, LogicalType *result_type = nullptr,
|
|
1014
|
-
bool root_expression = true);
|
|
1015
|
-
|
|
1016
|
-
//! Returns whether or not any columns have been bound by the expression binder
|
|
1017
|
-
bool HasBoundColumns() {
|
|
1018
|
-
return !bound_columns.empty();
|
|
1019
|
-
}
|
|
1020
|
-
const vector<BoundColumnReferenceInfo> &GetBoundColumns() {
|
|
1021
|
-
return bound_columns;
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
string Bind(unique_ptr<ParsedExpression> *expr, idx_t depth, bool root_expression = false);
|
|
1025
|
-
|
|
1026
|
-
unique_ptr<ParsedExpression> CreateStructExtract(unique_ptr<ParsedExpression> base, string field_name);
|
|
1027
|
-
BindResult BindQualifiedColumnName(ColumnRefExpression &colref, const string &table_name);
|
|
1028
|
-
|
|
1029
|
-
unique_ptr<ParsedExpression> QualifyColumnName(const string &column_name, string &error_message);
|
|
1030
|
-
unique_ptr<ParsedExpression> QualifyColumnName(ColumnRefExpression &colref, string &error_message);
|
|
1031
|
-
|
|
1032
|
-
// Bind table names to ColumnRefExpressions
|
|
1033
|
-
void QualifyColumnNames(unique_ptr<ParsedExpression> &expr);
|
|
1034
|
-
static void QualifyColumnNames(Binder &binder, unique_ptr<ParsedExpression> &expr);
|
|
1035
|
-
|
|
1036
|
-
static unique_ptr<Expression> PushCollation(ClientContext &context, unique_ptr<Expression> source,
|
|
1037
|
-
const string &collation, bool equality_only = false);
|
|
1038
|
-
static void TestCollation(ClientContext &context, const string &collation);
|
|
1039
|
-
|
|
1040
|
-
bool BindCorrelatedColumns(unique_ptr<ParsedExpression> &expr);
|
|
1041
|
-
|
|
1042
|
-
void BindChild(unique_ptr<ParsedExpression> &expr, idx_t depth, string &error);
|
|
1043
|
-
static void ExtractCorrelatedExpressions(Binder &binder, Expression &expr);
|
|
1044
|
-
|
|
1045
|
-
static bool ContainsNullType(const LogicalType &type);
|
|
1046
|
-
static LogicalType ExchangeNullType(const LogicalType &type);
|
|
1047
|
-
static bool ContainsType(const LogicalType &type, LogicalTypeId target);
|
|
1048
|
-
static LogicalType ExchangeType(const LogicalType &type, LogicalTypeId target, LogicalType new_type);
|
|
1049
|
-
|
|
1050
|
-
static void ResolveParameterType(LogicalType &type);
|
|
1051
|
-
static void ResolveParameterType(unique_ptr<Expression> &expr);
|
|
1052
|
-
|
|
1053
|
-
//! Bind the given expresion. Unlike Bind(), this does *not* mute the given ParsedExpression.
|
|
1054
|
-
//! Exposed to be used from sub-binders that aren't subclasses of ExpressionBinder.
|
|
1055
|
-
virtual BindResult BindExpression(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth,
|
|
1056
|
-
bool root_expression = false);
|
|
1057
|
-
|
|
1058
|
-
protected:
|
|
1059
|
-
BindResult BindExpression(BetweenExpression &expr, idx_t depth);
|
|
1060
|
-
BindResult BindExpression(CaseExpression &expr, idx_t depth);
|
|
1061
|
-
BindResult BindExpression(CollateExpression &expr, idx_t depth);
|
|
1062
|
-
BindResult BindExpression(CastExpression &expr, idx_t depth);
|
|
1063
|
-
BindResult BindExpression(ColumnRefExpression &expr, idx_t depth);
|
|
1064
|
-
BindResult BindExpression(ComparisonExpression &expr, idx_t depth);
|
|
1065
|
-
BindResult BindExpression(ConjunctionExpression &expr, idx_t depth);
|
|
1066
|
-
BindResult BindExpression(ConstantExpression &expr, idx_t depth);
|
|
1067
|
-
BindResult BindExpression(FunctionExpression &expr, idx_t depth, unique_ptr<ParsedExpression> *expr_ptr);
|
|
1068
|
-
BindResult BindExpression(LambdaExpression &expr, idx_t depth);
|
|
1069
|
-
BindResult BindExpression(OperatorExpression &expr, idx_t depth);
|
|
1070
|
-
BindResult BindExpression(ParameterExpression &expr, idx_t depth);
|
|
1071
|
-
BindResult BindExpression(PositionalReferenceExpression &ref, idx_t depth);
|
|
1072
|
-
BindResult BindExpression(StarExpression &expr, idx_t depth);
|
|
1073
|
-
BindResult BindExpression(SubqueryExpression &expr, idx_t depth);
|
|
1074
|
-
|
|
1075
|
-
protected:
|
|
1076
|
-
virtual BindResult BindGroupingFunction(OperatorExpression &op, idx_t depth);
|
|
1077
|
-
virtual BindResult BindFunction(FunctionExpression &expr, ScalarFunctionCatalogEntry *function, idx_t depth);
|
|
1078
|
-
virtual BindResult BindAggregate(FunctionExpression &expr, AggregateFunctionCatalogEntry *function, idx_t depth);
|
|
1079
|
-
virtual BindResult BindUnnest(FunctionExpression &expr, idx_t depth);
|
|
1080
|
-
virtual BindResult BindMacro(FunctionExpression &expr, MacroCatalogEntry *macro, idx_t depth,
|
|
1081
|
-
unique_ptr<ParsedExpression> *expr_ptr);
|
|
1082
|
-
|
|
1083
|
-
void ReplaceMacroParametersRecursive(unique_ptr<ParsedExpression> &expr);
|
|
1084
|
-
|
|
1085
|
-
virtual string UnsupportedAggregateMessage();
|
|
1086
|
-
virtual string UnsupportedUnnestMessage();
|
|
1087
|
-
|
|
1088
|
-
Binder &binder;
|
|
1089
|
-
ClientContext &context;
|
|
1090
|
-
ExpressionBinder *stored_binder;
|
|
1091
|
-
MacroBinding *macro_binding;
|
|
1092
|
-
vector<BoundColumnReferenceInfo> bound_columns;
|
|
1093
|
-
};
|
|
1094
|
-
|
|
1095
|
-
} // namespace duckdb
|
|
1096
|
-
|
|
1097
|
-
//===----------------------------------------------------------------------===//
|
|
1098
|
-
// DuckDB
|
|
1099
|
-
//
|
|
1100
|
-
// duckdb/planner/table_binding.hpp
|
|
1101
|
-
//
|
|
1102
|
-
//
|
|
1103
|
-
//===----------------------------------------------------------------------===//
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
namespace duckdb {
|
|
1114
|
-
class BindContext;
|
|
1115
|
-
class BoundQueryNode;
|
|
1116
|
-
class ColumnRefExpression;
|
|
1117
|
-
class SubqueryRef;
|
|
1118
|
-
class LogicalGet;
|
|
1119
|
-
class TableCatalogEntry;
|
|
1120
|
-
class TableFunctionCatalogEntry;
|
|
1121
|
-
class BoundTableFunction;
|
|
1122
|
-
|
|
1123
|
-
//! A Binding represents a binding to a table, table-producing function or subquery with a specified table index.
|
|
1124
|
-
struct Binding {
|
|
1125
|
-
Binding(const string &alias, vector<LogicalType> types, vector<string> names, idx_t index);
|
|
1126
|
-
virtual ~Binding() = default;
|
|
1127
|
-
|
|
1128
|
-
//! The alias of the binding
|
|
1129
|
-
string alias;
|
|
1130
|
-
//! The table index of the binding
|
|
1131
|
-
idx_t index;
|
|
1132
|
-
vector<LogicalType> types;
|
|
1133
|
-
//! Column names of the subquery
|
|
1134
|
-
vector<string> names;
|
|
1135
|
-
//! Name -> index for the names
|
|
1136
|
-
case_insensitive_map_t<column_t> name_map;
|
|
1137
|
-
|
|
1138
|
-
public:
|
|
1139
|
-
bool TryGetBindingIndex(const string &column_name, column_t &column_index);
|
|
1140
|
-
column_t GetBindingIndex(const string &column_name);
|
|
1141
|
-
bool HasMatchingBinding(const string &column_name);
|
|
1142
|
-
virtual string ColumnNotFoundError(const string &column_name) const;
|
|
1143
|
-
virtual BindResult Bind(ColumnRefExpression &colref, idx_t depth);
|
|
1144
|
-
virtual TableCatalogEntry *GetTableEntry();
|
|
1145
|
-
};
|
|
1146
|
-
|
|
1147
|
-
//! TableBinding is exactly like the Binding, except it keeps track of which columns were bound in the linked LogicalGet
|
|
1148
|
-
//! node for projection pushdown purposes.
|
|
1149
|
-
struct TableBinding : public Binding {
|
|
1150
|
-
TableBinding(const string &alias, vector<LogicalType> types, vector<string> names, LogicalGet &get, idx_t index,
|
|
1151
|
-
bool add_row_id = false);
|
|
1152
|
-
|
|
1153
|
-
//! the underlying LogicalGet
|
|
1154
|
-
LogicalGet &get;
|
|
1155
|
-
|
|
1156
|
-
public:
|
|
1157
|
-
BindResult Bind(ColumnRefExpression &colref, idx_t depth) override;
|
|
1158
|
-
TableCatalogEntry *GetTableEntry() override;
|
|
1159
|
-
string ColumnNotFoundError(const string &column_name) const override;
|
|
1160
|
-
};
|
|
1161
|
-
|
|
1162
|
-
//! MacroBinding is like the Binding, except the alias and index are set by default. Used for binding Macro
|
|
1163
|
-
//! Params/Arguments.
|
|
1164
|
-
struct MacroBinding : public Binding {
|
|
1165
|
-
static constexpr const char *MACRO_NAME = "0_macro_parameters";
|
|
1166
|
-
|
|
1167
|
-
public:
|
|
1168
|
-
MacroBinding(vector<LogicalType> types_p, vector<string> names_p, string macro_name);
|
|
1169
|
-
|
|
1170
|
-
//! Arguments
|
|
1171
|
-
vector<unique_ptr<ParsedExpression>> arguments;
|
|
1172
|
-
//! The name of the macro
|
|
1173
|
-
string macro_name;
|
|
1174
|
-
|
|
1175
|
-
public:
|
|
1176
|
-
BindResult Bind(ColumnRefExpression &colref, idx_t depth) override;
|
|
1177
|
-
|
|
1178
|
-
//! Given the parameter colref, returns a copy of the argument that was supplied for this parameter
|
|
1179
|
-
unique_ptr<ParsedExpression> ParamToArg(ColumnRefExpression &colref);
|
|
1180
|
-
};
|
|
1181
|
-
|
|
1182
|
-
} // namespace duckdb
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
namespace duckdb {
|
|
1186
|
-
class Binder;
|
|
1187
|
-
class LogicalGet;
|
|
1188
|
-
class BoundQueryNode;
|
|
1189
|
-
|
|
1190
|
-
class StarExpression;
|
|
1191
|
-
|
|
1192
|
-
struct UsingColumnSet {
|
|
1193
|
-
string primary_binding;
|
|
1194
|
-
unordered_set<string> bindings;
|
|
1195
|
-
};
|
|
1196
|
-
|
|
1197
|
-
//! The BindContext object keeps track of all the tables and columns that are
|
|
1198
|
-
//! encountered during the binding process.
|
|
1199
|
-
class BindContext {
|
|
1200
|
-
public:
|
|
1201
|
-
//! Keep track of recursive CTE references
|
|
1202
|
-
case_insensitive_map_t<std::shared_ptr<idx_t>> cte_references;
|
|
1203
|
-
|
|
1204
|
-
public:
|
|
1205
|
-
//! Given a column name, find the matching table it belongs to. Throws an
|
|
1206
|
-
//! exception if no table has a column of the given name.
|
|
1207
|
-
string GetMatchingBinding(const string &column_name);
|
|
1208
|
-
//! Like GetMatchingBinding, but instead of throwing an error if multiple tables have the same binding it will
|
|
1209
|
-
//! return a list of all the matching ones
|
|
1210
|
-
unordered_set<string> GetMatchingBindings(const string &column_name);
|
|
1211
|
-
//! Like GetMatchingBindings, but returns the top 3 most similar bindings (in levenshtein distance) instead of the
|
|
1212
|
-
//! matching ones
|
|
1213
|
-
vector<string> GetSimilarBindings(const string &column_name);
|
|
1214
|
-
|
|
1215
|
-
Binding *GetCTEBinding(const string &ctename);
|
|
1216
|
-
//! Binds a column expression to the base table. Returns the bound expression
|
|
1217
|
-
//! or throws an exception if the column could not be bound.
|
|
1218
|
-
BindResult BindColumn(ColumnRefExpression &colref, idx_t depth);
|
|
1219
|
-
string BindColumn(PositionalReferenceExpression &ref, string &table_name, string &column_name);
|
|
1220
|
-
BindResult BindColumn(PositionalReferenceExpression &ref, idx_t depth);
|
|
1221
|
-
|
|
1222
|
-
unique_ptr<ParsedExpression> CreateColumnReference(const string &table_name, const string &column_name);
|
|
1223
|
-
unique_ptr<ParsedExpression> CreateColumnReference(const string &schema_name, const string &table_name,
|
|
1224
|
-
const string &column_name);
|
|
1225
|
-
|
|
1226
|
-
//! Generate column expressions for all columns that are present in the
|
|
1227
|
-
//! referenced tables. This is used to resolve the * expression in a
|
|
1228
|
-
//! selection list.
|
|
1229
|
-
void GenerateAllColumnExpressions(StarExpression &expr, vector<unique_ptr<ParsedExpression>> &new_select_list);
|
|
1230
|
-
//! Check if the given (binding, column_name) is in the exclusion/replacement lists.
|
|
1231
|
-
//! Returns true if it is in one of these lists, and should therefore be skipped.
|
|
1232
|
-
bool CheckExclusionList(StarExpression &expr, Binding *binding, const string &column_name,
|
|
1233
|
-
vector<unique_ptr<ParsedExpression>> &new_select_list,
|
|
1234
|
-
case_insensitive_set_t &excluded_columns);
|
|
1235
|
-
|
|
1236
|
-
const vector<std::pair<string, Binding *>> &GetBindingsList() {
|
|
1237
|
-
return bindings_list;
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
//! Adds a base table with the given alias to the BindContext.
|
|
1241
|
-
void AddBaseTable(idx_t index, const string &alias, const vector<string> &names, const vector<LogicalType> &types,
|
|
1242
|
-
LogicalGet &get);
|
|
1243
|
-
//! Adds a call to a table function with the given alias to the BindContext.
|
|
1244
|
-
void AddTableFunction(idx_t index, const string &alias, const vector<string> &names,
|
|
1245
|
-
const vector<LogicalType> &types, LogicalGet &get);
|
|
1246
|
-
//! Adds a subquery with a given alias to the BindContext.
|
|
1247
|
-
void AddSubquery(idx_t index, const string &alias, SubqueryRef &ref, BoundQueryNode &subquery);
|
|
1248
|
-
//! Adds a base table with the given alias to the BindContext.
|
|
1249
|
-
void AddGenericBinding(idx_t index, const string &alias, const vector<string> &names,
|
|
1250
|
-
const vector<LogicalType> &types);
|
|
1251
|
-
|
|
1252
|
-
//! Adds a base table with the given alias to the CTE BindContext.
|
|
1253
|
-
//! We need this to correctly bind recursive CTEs with multiple references.
|
|
1254
|
-
void AddCTEBinding(idx_t index, const string &alias, const vector<string> &names, const vector<LogicalType> &types);
|
|
1255
|
-
|
|
1256
|
-
//! Add an implicit join condition (e.g. USING (x))
|
|
1257
|
-
void AddUsingBinding(const string &column_name, UsingColumnSet *set);
|
|
1258
|
-
|
|
1259
|
-
void AddUsingBindingSet(unique_ptr<UsingColumnSet> set);
|
|
1260
|
-
|
|
1261
|
-
//! Returns any using column set for the given column name, or nullptr if there is none. On conflict (multiple using
|
|
1262
|
-
//! column sets with the same name) throw an exception.
|
|
1263
|
-
UsingColumnSet *GetUsingBinding(const string &column_name);
|
|
1264
|
-
//! Returns any using column set for the given column name, or nullptr if there is none
|
|
1265
|
-
UsingColumnSet *GetUsingBinding(const string &column_name, const string &binding_name);
|
|
1266
|
-
//! Erase a using binding from the set of using bindings
|
|
1267
|
-
void RemoveUsingBinding(const string &column_name, UsingColumnSet *set);
|
|
1268
|
-
//! Finds the using bindings for a given column. Returns true if any exists, false otherwise.
|
|
1269
|
-
bool FindUsingBinding(const string &column_name, unordered_set<UsingColumnSet *> **using_columns);
|
|
1270
|
-
//! Transfer a using binding from one bind context to this bind context
|
|
1271
|
-
void TransferUsingBinding(BindContext ¤t_context, UsingColumnSet *current_set, UsingColumnSet *new_set,
|
|
1272
|
-
const string &binding, const string &using_column);
|
|
1273
|
-
|
|
1274
|
-
//! Fetch the actual column name from the given binding, or throws if none exists
|
|
1275
|
-
//! This can be different from "column_name" because of case insensitivity
|
|
1276
|
-
//! (e.g. "column_name" might return "COLUMN_NAME")
|
|
1277
|
-
string GetActualColumnName(const string &binding, const string &column_name);
|
|
1278
|
-
|
|
1279
|
-
case_insensitive_map_t<std::shared_ptr<Binding>> GetCTEBindings() {
|
|
1280
|
-
return cte_bindings;
|
|
1281
|
-
}
|
|
1282
|
-
void SetCTEBindings(case_insensitive_map_t<std::shared_ptr<Binding>> bindings) {
|
|
1283
|
-
cte_bindings = bindings;
|
|
1284
|
-
}
|
|
1285
|
-
|
|
1286
|
-
//! Alias a set of column names for the specified table, using the original names if there are not enough aliases
|
|
1287
|
-
//! specified.
|
|
1288
|
-
static vector<string> AliasColumnNames(const string &table_name, const vector<string> &names,
|
|
1289
|
-
const vector<string> &column_aliases);
|
|
1290
|
-
|
|
1291
|
-
//! Add all the bindings from a BindContext to this BindContext. The other BindContext is destroyed in the process.
|
|
1292
|
-
void AddContext(BindContext other);
|
|
1293
|
-
|
|
1294
|
-
//! Gets a binding of the specified name. Returns a nullptr and sets the out_error if the binding could not be
|
|
1295
|
-
//! found.
|
|
1296
|
-
Binding *GetBinding(const string &name, string &out_error);
|
|
1297
|
-
|
|
1298
|
-
private:
|
|
1299
|
-
void AddBinding(const string &alias, unique_ptr<Binding> binding);
|
|
1300
|
-
|
|
1301
|
-
private:
|
|
1302
|
-
//! The set of bindings
|
|
1303
|
-
case_insensitive_map_t<unique_ptr<Binding>> bindings;
|
|
1304
|
-
//! The list of bindings in insertion order
|
|
1305
|
-
vector<std::pair<string, Binding *>> bindings_list;
|
|
1306
|
-
//! The set of columns used in USING join conditions
|
|
1307
|
-
case_insensitive_map_t<unordered_set<UsingColumnSet *>> using_columns;
|
|
1308
|
-
//! Using column sets
|
|
1309
|
-
vector<unique_ptr<UsingColumnSet>> using_column_sets;
|
|
1310
|
-
|
|
1311
|
-
//! The set of CTE bindings
|
|
1312
|
-
case_insensitive_map_t<std::shared_ptr<Binding>> cte_bindings;
|
|
1313
|
-
};
|
|
1314
|
-
} // namespace duckdb
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
//===----------------------------------------------------------------------===//
|
|
1318
|
-
// DuckDB
|
|
1319
|
-
//
|
|
1320
|
-
// duckdb/planner/expression/bound_columnref_expression.hpp
|
|
1321
|
-
//
|
|
1322
|
-
//
|
|
1323
|
-
//===----------------------------------------------------------------------===//
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
namespace duckdb {
|
|
1331
|
-
|
|
1332
|
-
//! A BoundColumnRef expression represents a ColumnRef expression that was bound to an actual table and column index. It
|
|
1333
|
-
//! is not yet executable, however. The ColumnBindingResolver transforms the BoundColumnRefExpressions into
|
|
1334
|
-
//! BoundExpressions, which refer to indexes into the physical chunks that pass through the executor.
|
|
1335
|
-
class BoundColumnRefExpression : public Expression {
|
|
1336
|
-
public:
|
|
1337
|
-
BoundColumnRefExpression(LogicalType type, ColumnBinding binding, idx_t depth = 0);
|
|
1338
|
-
BoundColumnRefExpression(string alias, LogicalType type, ColumnBinding binding, idx_t depth = 0);
|
|
1339
|
-
|
|
1340
|
-
//! Column index set by the binder, used to generate the final BoundExpression
|
|
1341
|
-
ColumnBinding binding;
|
|
1342
|
-
//! The subquery depth (i.e. depth 0 = current query, depth 1 = parent query, depth 2 = parent of parent, etc...).
|
|
1343
|
-
//! This is only non-zero for correlated expressions inside subqueries.
|
|
1344
|
-
idx_t depth;
|
|
1345
|
-
|
|
1346
|
-
public:
|
|
1347
|
-
bool IsScalar() const override {
|
|
1348
|
-
return false;
|
|
1349
|
-
}
|
|
1350
|
-
bool IsFoldable() const override {
|
|
1351
|
-
return false;
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1354
|
-
string ToString() const override;
|
|
1355
|
-
|
|
1356
|
-
bool Equals(const BaseExpression *other) const override;
|
|
1357
|
-
hash_t Hash() const override;
|
|
1358
|
-
|
|
1359
|
-
unique_ptr<Expression> Copy() override;
|
|
1360
|
-
};
|
|
1361
|
-
} // namespace duckdb
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
namespace duckdb {
|
|
1369
|
-
class BoundResultModifier;
|
|
1370
|
-
class BoundSelectNode;
|
|
1371
|
-
class ClientContext;
|
|
1372
|
-
class ExpressionBinder;
|
|
1373
|
-
class LimitModifier;
|
|
1374
|
-
class OrderBinder;
|
|
1375
|
-
class TableCatalogEntry;
|
|
1376
|
-
class ViewCatalogEntry;
|
|
1377
|
-
|
|
1378
|
-
struct CreateInfo;
|
|
1379
|
-
struct BoundCreateTableInfo;
|
|
1380
|
-
struct BoundCreateFunctionInfo;
|
|
1381
|
-
struct CommonTableExpressionInfo;
|
|
1382
|
-
|
|
1383
|
-
struct CorrelatedColumnInfo {
|
|
1384
|
-
ColumnBinding binding;
|
|
1385
|
-
LogicalType type;
|
|
1386
|
-
string name;
|
|
1387
|
-
idx_t depth;
|
|
1388
|
-
|
|
1389
|
-
explicit CorrelatedColumnInfo(BoundColumnRefExpression &expr)
|
|
1390
|
-
: binding(expr.binding), type(expr.return_type), name(expr.GetName()), depth(expr.depth) {
|
|
1391
|
-
}
|
|
1392
|
-
|
|
1393
|
-
bool operator==(const CorrelatedColumnInfo &rhs) const {
|
|
1394
|
-
return binding == rhs.binding;
|
|
1395
|
-
}
|
|
1396
|
-
};
|
|
1397
|
-
|
|
1398
|
-
//! Bind the parsed query tree to the actual columns present in the catalog.
|
|
1399
|
-
/*!
|
|
1400
|
-
The binder is responsible for binding tables and columns to actual physical
|
|
1401
|
-
tables and columns in the catalog. In the process, it also resolves types of
|
|
1402
|
-
all expressions.
|
|
1403
|
-
*/
|
|
1404
|
-
class Binder : public std::enable_shared_from_this<Binder> {
|
|
1405
|
-
friend class ExpressionBinder;
|
|
1406
|
-
friend class SelectBinder;
|
|
1407
|
-
friend class RecursiveSubqueryPlanner;
|
|
1408
|
-
|
|
1409
|
-
public:
|
|
1410
|
-
static shared_ptr<Binder> CreateBinder(ClientContext &context, Binder *parent = nullptr, bool inherit_ctes = true);
|
|
1411
|
-
|
|
1412
|
-
//! The client context
|
|
1413
|
-
ClientContext &context;
|
|
1414
|
-
//! A mapping of names to common table expressions
|
|
1415
|
-
case_insensitive_map_t<CommonTableExpressionInfo *> CTE_bindings;
|
|
1416
|
-
//! The CTEs that have already been bound
|
|
1417
|
-
unordered_set<CommonTableExpressionInfo *> bound_ctes;
|
|
1418
|
-
//! The bind context
|
|
1419
|
-
BindContext bind_context;
|
|
1420
|
-
//! The set of correlated columns bound by this binder (FIXME: this should probably be an unordered_set and not a
|
|
1421
|
-
//! vector)
|
|
1422
|
-
vector<CorrelatedColumnInfo> correlated_columns;
|
|
1423
|
-
//! The set of parameter expressions bound by this binder
|
|
1424
|
-
vector<BoundParameterExpression *> *parameters;
|
|
1425
|
-
//! Whether or not the bound statement is read-only
|
|
1426
|
-
bool read_only;
|
|
1427
|
-
//! Whether or not the statement requires a valid transaction to run
|
|
1428
|
-
bool requires_valid_transaction;
|
|
1429
|
-
//! Whether or not the statement can be streamed to the client
|
|
1430
|
-
bool allow_stream_result;
|
|
1431
|
-
//! The alias for the currently processing subquery, if it exists
|
|
1432
|
-
string alias;
|
|
1433
|
-
//! Macro parameter bindings (if any)
|
|
1434
|
-
MacroBinding *macro_binding = nullptr;
|
|
1435
|
-
|
|
1436
|
-
public:
|
|
1437
|
-
BoundStatement Bind(SQLStatement &statement);
|
|
1438
|
-
BoundStatement Bind(QueryNode &node);
|
|
1439
|
-
|
|
1440
|
-
unique_ptr<BoundCreateTableInfo> BindCreateTableInfo(unique_ptr<CreateInfo> info);
|
|
1441
|
-
void BindCreateViewInfo(CreateViewInfo &base);
|
|
1442
|
-
SchemaCatalogEntry *BindSchema(CreateInfo &info);
|
|
1443
|
-
SchemaCatalogEntry *BindCreateFunctionInfo(CreateInfo &info);
|
|
1444
|
-
|
|
1445
|
-
//! Check usage, and cast named parameters to their types
|
|
1446
|
-
static void BindNamedParameters(unordered_map<string, LogicalType> &types, unordered_map<string, Value> &values,
|
|
1447
|
-
QueryErrorContext &error_context, string &func_name);
|
|
1448
|
-
|
|
1449
|
-
unique_ptr<BoundTableRef> Bind(TableRef &ref);
|
|
1450
|
-
unique_ptr<LogicalOperator> CreatePlan(BoundTableRef &ref);
|
|
1451
|
-
|
|
1452
|
-
//! Generates an unused index for a table
|
|
1453
|
-
idx_t GenerateTableIndex();
|
|
1454
|
-
|
|
1455
|
-
//! Add a common table expression to the binder
|
|
1456
|
-
void AddCTE(const string &name, CommonTableExpressionInfo *cte);
|
|
1457
|
-
//! Find a common table expression by name; returns nullptr if none exists
|
|
1458
|
-
CommonTableExpressionInfo *FindCTE(const string &name, bool skip = false);
|
|
1459
|
-
|
|
1460
|
-
bool CTEIsAlreadyBound(CommonTableExpressionInfo *cte);
|
|
1461
|
-
|
|
1462
|
-
void PushExpressionBinder(ExpressionBinder *binder);
|
|
1463
|
-
void PopExpressionBinder();
|
|
1464
|
-
void SetActiveBinder(ExpressionBinder *binder);
|
|
1465
|
-
ExpressionBinder *GetActiveBinder();
|
|
1466
|
-
bool HasActiveBinder();
|
|
1467
|
-
|
|
1468
|
-
vector<ExpressionBinder *> &GetActiveBinders();
|
|
1469
|
-
|
|
1470
|
-
void MergeCorrelatedColumns(vector<CorrelatedColumnInfo> &other);
|
|
1471
|
-
//! Add a correlated column to this binder (if it does not exist)
|
|
1472
|
-
void AddCorrelatedColumn(const CorrelatedColumnInfo &info);
|
|
1473
|
-
|
|
1474
|
-
string FormatError(ParsedExpression &expr_context, const string &message);
|
|
1475
|
-
string FormatError(TableRef &ref_context, const string &message);
|
|
1476
|
-
|
|
1477
|
-
string FormatErrorRecursive(idx_t query_location, const string &message, vector<ExceptionFormatValue> &values);
|
|
1478
|
-
template <class T, typename... Args>
|
|
1479
|
-
string FormatErrorRecursive(idx_t query_location, const string &msg, vector<ExceptionFormatValue> &values, T param,
|
|
1480
|
-
Args... params) {
|
|
1481
|
-
values.push_back(ExceptionFormatValue::CreateFormatValue<T>(param));
|
|
1482
|
-
return FormatErrorRecursive(query_location, msg, values, params...);
|
|
1483
|
-
}
|
|
1484
|
-
|
|
1485
|
-
template <typename... Args>
|
|
1486
|
-
string FormatError(idx_t query_location, const string &msg, Args... params) {
|
|
1487
|
-
vector<ExceptionFormatValue> values;
|
|
1488
|
-
return FormatErrorRecursive(query_location, msg, values, params...);
|
|
1489
|
-
}
|
|
1490
|
-
|
|
1491
|
-
static void BindLogicalType(ClientContext &context, LogicalType &type, const string &schema = "");
|
|
1492
|
-
|
|
1493
|
-
bool HasMatchingBinding(const string &table_name, const string &column_name, string &error_message);
|
|
1494
|
-
bool HasMatchingBinding(const string &schema_name, const string &table_name, const string &column_name,
|
|
1495
|
-
string &error_message);
|
|
1496
|
-
|
|
1497
|
-
private:
|
|
1498
|
-
//! The parent binder (if any)
|
|
1499
|
-
shared_ptr<Binder> parent;
|
|
1500
|
-
//! The vector of active binders
|
|
1501
|
-
vector<ExpressionBinder *> active_binders;
|
|
1502
|
-
//! The count of bound_tables
|
|
1503
|
-
idx_t bound_tables;
|
|
1504
|
-
//! Whether or not the binder has any unplanned subqueries that still need to be planned
|
|
1505
|
-
bool has_unplanned_subqueries = false;
|
|
1506
|
-
//! Whether or not subqueries should be planned already
|
|
1507
|
-
bool plan_subquery = true;
|
|
1508
|
-
//! Whether CTEs should reference the parent binder (if it exists)
|
|
1509
|
-
bool inherit_ctes = true;
|
|
1510
|
-
//! Whether or not the binder can contain NULLs as the root of expressions
|
|
1511
|
-
bool can_contain_nulls = false;
|
|
1512
|
-
//! The root statement of the query that is currently being parsed
|
|
1513
|
-
SQLStatement *root_statement = nullptr;
|
|
1514
|
-
|
|
1515
|
-
private:
|
|
1516
|
-
//! Bind the default values of the columns of a table
|
|
1517
|
-
void BindDefaultValues(vector<ColumnDefinition> &columns, vector<unique_ptr<Expression>> &bound_defaults);
|
|
1518
|
-
//! Bind a delimiter value (LIMIT or OFFSET)
|
|
1519
|
-
unique_ptr<Expression> BindDelimiter(ClientContext &context, unique_ptr<ParsedExpression> delimiter,
|
|
1520
|
-
const LogicalType &type, Value &delimiter_value);
|
|
1521
|
-
|
|
1522
|
-
//! Move correlated expressions from the child binder to this binder
|
|
1523
|
-
void MoveCorrelatedExpressions(Binder &other);
|
|
1524
|
-
|
|
1525
|
-
BoundStatement Bind(SelectStatement &stmt);
|
|
1526
|
-
BoundStatement Bind(InsertStatement &stmt);
|
|
1527
|
-
BoundStatement Bind(CopyStatement &stmt);
|
|
1528
|
-
BoundStatement Bind(DeleteStatement &stmt);
|
|
1529
|
-
BoundStatement Bind(UpdateStatement &stmt);
|
|
1530
|
-
BoundStatement Bind(CreateStatement &stmt);
|
|
1531
|
-
BoundStatement Bind(DropStatement &stmt);
|
|
1532
|
-
BoundStatement Bind(AlterStatement &stmt);
|
|
1533
|
-
BoundStatement Bind(TransactionStatement &stmt);
|
|
1534
|
-
BoundStatement Bind(PragmaStatement &stmt);
|
|
1535
|
-
BoundStatement Bind(ExplainStatement &stmt);
|
|
1536
|
-
BoundStatement Bind(VacuumStatement &stmt);
|
|
1537
|
-
BoundStatement Bind(RelationStatement &stmt);
|
|
1538
|
-
BoundStatement Bind(ShowStatement &stmt);
|
|
1539
|
-
BoundStatement Bind(CallStatement &stmt);
|
|
1540
|
-
BoundStatement Bind(ExportStatement &stmt);
|
|
1541
|
-
BoundStatement Bind(SetStatement &stmt);
|
|
1542
|
-
BoundStatement Bind(LoadStatement &stmt);
|
|
1543
|
-
|
|
1544
|
-
unique_ptr<BoundQueryNode> BindNode(SelectNode &node);
|
|
1545
|
-
unique_ptr<BoundQueryNode> BindNode(SetOperationNode &node);
|
|
1546
|
-
unique_ptr<BoundQueryNode> BindNode(RecursiveCTENode &node);
|
|
1547
|
-
unique_ptr<BoundQueryNode> BindNode(QueryNode &node);
|
|
1548
|
-
|
|
1549
|
-
unique_ptr<LogicalOperator> VisitQueryNode(BoundQueryNode &node, unique_ptr<LogicalOperator> root);
|
|
1550
|
-
unique_ptr<LogicalOperator> CreatePlan(BoundRecursiveCTENode &node);
|
|
1551
|
-
unique_ptr<LogicalOperator> CreatePlan(BoundSelectNode &statement);
|
|
1552
|
-
unique_ptr<LogicalOperator> CreatePlan(BoundSetOperationNode &node);
|
|
1553
|
-
unique_ptr<LogicalOperator> CreatePlan(BoundQueryNode &node);
|
|
1554
|
-
|
|
1555
|
-
unique_ptr<BoundTableRef> Bind(BaseTableRef &ref);
|
|
1556
|
-
unique_ptr<BoundTableRef> Bind(CrossProductRef &ref);
|
|
1557
|
-
unique_ptr<BoundTableRef> Bind(JoinRef &ref);
|
|
1558
|
-
unique_ptr<BoundTableRef> Bind(SubqueryRef &ref, CommonTableExpressionInfo *cte = nullptr);
|
|
1559
|
-
unique_ptr<BoundTableRef> Bind(TableFunctionRef &ref);
|
|
1560
|
-
unique_ptr<BoundTableRef> Bind(EmptyTableRef &ref);
|
|
1561
|
-
unique_ptr<BoundTableRef> Bind(ExpressionListRef &ref);
|
|
1562
|
-
|
|
1563
|
-
bool BindFunctionParameters(vector<unique_ptr<ParsedExpression>> &expressions, vector<LogicalType> &arguments,
|
|
1564
|
-
vector<Value> ¶meters, unordered_map<string, Value> &named_parameters,
|
|
1565
|
-
unique_ptr<BoundSubqueryRef> &subquery, string &error);
|
|
1566
|
-
|
|
1567
|
-
unique_ptr<LogicalOperator> CreatePlan(BoundBaseTableRef &ref);
|
|
1568
|
-
unique_ptr<LogicalOperator> CreatePlan(BoundCrossProductRef &ref);
|
|
1569
|
-
unique_ptr<LogicalOperator> CreatePlan(BoundJoinRef &ref);
|
|
1570
|
-
unique_ptr<LogicalOperator> CreatePlan(BoundSubqueryRef &ref);
|
|
1571
|
-
unique_ptr<LogicalOperator> CreatePlan(BoundTableFunction &ref);
|
|
1572
|
-
unique_ptr<LogicalOperator> CreatePlan(BoundEmptyTableRef &ref);
|
|
1573
|
-
unique_ptr<LogicalOperator> CreatePlan(BoundExpressionListRef &ref);
|
|
1574
|
-
unique_ptr<LogicalOperator> CreatePlan(BoundCTERef &ref);
|
|
1575
|
-
|
|
1576
|
-
unique_ptr<LogicalOperator> BindTable(TableCatalogEntry &table, BaseTableRef &ref);
|
|
1577
|
-
unique_ptr<LogicalOperator> BindView(ViewCatalogEntry &view, BaseTableRef &ref);
|
|
1578
|
-
unique_ptr<LogicalOperator> BindTableOrView(BaseTableRef &ref);
|
|
1579
|
-
|
|
1580
|
-
BoundStatement BindCopyTo(CopyStatement &stmt);
|
|
1581
|
-
BoundStatement BindCopyFrom(CopyStatement &stmt);
|
|
1582
|
-
|
|
1583
|
-
void BindModifiers(OrderBinder &order_binder, QueryNode &statement, BoundQueryNode &result);
|
|
1584
|
-
void BindModifierTypes(BoundQueryNode &result, const vector<LogicalType> &sql_types, idx_t projection_index);
|
|
1585
|
-
|
|
1586
|
-
BoundStatement BindSummarize(ShowStatement &stmt);
|
|
1587
|
-
unique_ptr<BoundResultModifier> BindLimit(LimitModifier &limit_mod);
|
|
1588
|
-
unique_ptr<BoundResultModifier> BindLimitPercent(LimitPercentModifier &limit_mod);
|
|
1589
|
-
unique_ptr<Expression> BindOrderExpression(OrderBinder &order_binder, unique_ptr<ParsedExpression> expr);
|
|
1590
|
-
|
|
1591
|
-
unique_ptr<LogicalOperator> PlanFilter(unique_ptr<Expression> condition, unique_ptr<LogicalOperator> root);
|
|
1592
|
-
|
|
1593
|
-
void PlanSubqueries(unique_ptr<Expression> *expr, unique_ptr<LogicalOperator> *root);
|
|
1594
|
-
unique_ptr<Expression> PlanSubquery(BoundSubqueryExpression &expr, unique_ptr<LogicalOperator> &root);
|
|
1595
|
-
|
|
1596
|
-
unique_ptr<LogicalOperator> CastLogicalOperatorToTypes(vector<LogicalType> &source_types,
|
|
1597
|
-
vector<LogicalType> &target_types,
|
|
1598
|
-
unique_ptr<LogicalOperator> op);
|
|
1599
|
-
|
|
1600
|
-
string FindBinding(const string &using_column, const string &join_side);
|
|
1601
|
-
bool TryFindBinding(const string &using_column, const string &join_side, string &result);
|
|
1602
|
-
|
|
1603
|
-
void AddUsingBindingSet(unique_ptr<UsingColumnSet> set);
|
|
1604
|
-
string RetrieveUsingBinding(Binder ¤t_binder, UsingColumnSet *current_set, const string &column_name,
|
|
1605
|
-
const string &join_side, UsingColumnSet *new_set);
|
|
1606
|
-
|
|
1607
|
-
public:
|
|
1608
|
-
// This should really be a private constructor, but make_shared does not allow it...
|
|
1609
|
-
// If you are thinking about calling this, you should probably call Binder::CreateBinder
|
|
1610
|
-
Binder(bool I_know_what_I_am_doing, ClientContext &context, shared_ptr<Binder> parent, bool inherit_ctes);
|
|
1611
|
-
};
|
|
1612
|
-
|
|
1613
|
-
} // namespace duckdb
|
|
1614
408
|
|
|
1615
409
|
|
|
1616
410
|
|
|
@@ -1887,121 +681,6 @@ public:
|
|
|
1887
681
|
} // namespace duckdb
|
|
1888
682
|
|
|
1889
683
|
|
|
1890
|
-
//===----------------------------------------------------------------------===//
|
|
1891
|
-
// DuckDB
|
|
1892
|
-
//
|
|
1893
|
-
// duckdb/catalog/catalog_entry/sequence_catalog_entry.hpp
|
|
1894
|
-
//
|
|
1895
|
-
//
|
|
1896
|
-
//===----------------------------------------------------------------------===//
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
//===----------------------------------------------------------------------===//
|
|
1902
|
-
// DuckDB
|
|
1903
|
-
//
|
|
1904
|
-
// duckdb/parser/parsed_data/create_sequence_info.hpp
|
|
1905
|
-
//
|
|
1906
|
-
//
|
|
1907
|
-
//===----------------------------------------------------------------------===//
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
namespace duckdb {
|
|
1915
|
-
|
|
1916
|
-
struct CreateSequenceInfo : public CreateInfo {
|
|
1917
|
-
CreateSequenceInfo()
|
|
1918
|
-
: CreateInfo(CatalogType::SEQUENCE_ENTRY, INVALID_SCHEMA), name(string()), usage_count(0), increment(1),
|
|
1919
|
-
min_value(1), max_value(NumericLimits<int64_t>::Maximum()), start_value(1), cycle(false) {
|
|
1920
|
-
}
|
|
1921
|
-
|
|
1922
|
-
//! Sequence name to create
|
|
1923
|
-
string name;
|
|
1924
|
-
//! Usage count of the sequence
|
|
1925
|
-
uint64_t usage_count;
|
|
1926
|
-
//! The increment value
|
|
1927
|
-
int64_t increment;
|
|
1928
|
-
//! The minimum value of the sequence
|
|
1929
|
-
int64_t min_value;
|
|
1930
|
-
//! The maximum value of the sequence
|
|
1931
|
-
int64_t max_value;
|
|
1932
|
-
//! The start value of the sequence
|
|
1933
|
-
int64_t start_value;
|
|
1934
|
-
//! Whether or not the sequence cycles
|
|
1935
|
-
bool cycle;
|
|
1936
|
-
|
|
1937
|
-
public:
|
|
1938
|
-
unique_ptr<CreateInfo> Copy() const override {
|
|
1939
|
-
auto result = make_unique<CreateSequenceInfo>();
|
|
1940
|
-
CopyProperties(*result);
|
|
1941
|
-
result->name = name;
|
|
1942
|
-
result->schema = schema;
|
|
1943
|
-
result->usage_count = usage_count;
|
|
1944
|
-
result->increment = increment;
|
|
1945
|
-
result->min_value = min_value;
|
|
1946
|
-
result->max_value = max_value;
|
|
1947
|
-
result->start_value = start_value;
|
|
1948
|
-
result->cycle = cycle;
|
|
1949
|
-
return move(result);
|
|
1950
|
-
}
|
|
1951
|
-
};
|
|
1952
|
-
|
|
1953
|
-
} // namespace duckdb
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
namespace duckdb {
|
|
1958
|
-
class Serializer;
|
|
1959
|
-
class Deserializer;
|
|
1960
|
-
|
|
1961
|
-
struct SequenceValue {
|
|
1962
|
-
SequenceValue() : usage_count(0), counter(-1) {
|
|
1963
|
-
}
|
|
1964
|
-
SequenceValue(uint64_t usage_count, int64_t counter) : usage_count(usage_count), counter(counter) {
|
|
1965
|
-
}
|
|
1966
|
-
|
|
1967
|
-
uint64_t usage_count;
|
|
1968
|
-
int64_t counter;
|
|
1969
|
-
};
|
|
1970
|
-
|
|
1971
|
-
//! A sequence catalog entry
|
|
1972
|
-
class SequenceCatalogEntry : public StandardEntry {
|
|
1973
|
-
public:
|
|
1974
|
-
//! Create a real TableCatalogEntry and initialize storage for it
|
|
1975
|
-
SequenceCatalogEntry(Catalog *catalog, SchemaCatalogEntry *schema, CreateSequenceInfo *info);
|
|
1976
|
-
|
|
1977
|
-
//! Lock for getting a value on the sequence
|
|
1978
|
-
mutex lock;
|
|
1979
|
-
//! The amount of times the sequence has been used
|
|
1980
|
-
uint64_t usage_count;
|
|
1981
|
-
//! The sequence counter
|
|
1982
|
-
int64_t counter;
|
|
1983
|
-
//! The most recently returned value
|
|
1984
|
-
int64_t last_value;
|
|
1985
|
-
//! The increment value
|
|
1986
|
-
int64_t increment;
|
|
1987
|
-
//! The minimum value of the sequence
|
|
1988
|
-
int64_t start_value;
|
|
1989
|
-
//! The minimum value of the sequence
|
|
1990
|
-
int64_t min_value;
|
|
1991
|
-
//! The maximum value of the sequence
|
|
1992
|
-
int64_t max_value;
|
|
1993
|
-
//! Whether or not the sequence cycles
|
|
1994
|
-
bool cycle;
|
|
1995
|
-
|
|
1996
|
-
public:
|
|
1997
|
-
//! Serialize the meta information of the SequenceCatalogEntry a serializer
|
|
1998
|
-
virtual void Serialize(Serializer &serializer);
|
|
1999
|
-
//! Deserializes to a CreateTableInfo
|
|
2000
|
-
static unique_ptr<CreateSequenceInfo> Deserialize(Deserializer &source);
|
|
2001
|
-
|
|
2002
|
-
string ToSQL() override;
|
|
2003
|
-
};
|
|
2004
|
-
} // namespace duckdb
|
|
2005
684
|
|
|
2006
685
|
|
|
2007
686
|
|
|
@@ -2016,128 +695,6 @@ public:
|
|
|
2016
695
|
|
|
2017
696
|
|
|
2018
697
|
|
|
2019
|
-
//===----------------------------------------------------------------------===//
|
|
2020
|
-
// DuckDB
|
|
2021
|
-
//
|
|
2022
|
-
// duckdb/parser/statement/select_statement.hpp
|
|
2023
|
-
//
|
|
2024
|
-
//
|
|
2025
|
-
//===----------------------------------------------------------------------===//
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
//===----------------------------------------------------------------------===//
|
|
2032
|
-
// DuckDB
|
|
2033
|
-
//
|
|
2034
|
-
// duckdb/parser/query_node.hpp
|
|
2035
|
-
//
|
|
2036
|
-
//
|
|
2037
|
-
//===----------------------------------------------------------------------===//
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
//===----------------------------------------------------------------------===//
|
|
2046
|
-
// DuckDB
|
|
2047
|
-
//
|
|
2048
|
-
// duckdb/parser/common_table_expression_info.hpp
|
|
2049
|
-
//
|
|
2050
|
-
//
|
|
2051
|
-
//===----------------------------------------------------------------------===//
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
namespace duckdb {
|
|
2058
|
-
|
|
2059
|
-
class SelectStatement;
|
|
2060
|
-
|
|
2061
|
-
struct CommonTableExpressionInfo {
|
|
2062
|
-
vector<string> aliases;
|
|
2063
|
-
unique_ptr<SelectStatement> query;
|
|
2064
|
-
};
|
|
2065
|
-
|
|
2066
|
-
} // namespace duckdb
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
namespace duckdb {
|
|
2070
|
-
|
|
2071
|
-
enum QueryNodeType : uint8_t {
|
|
2072
|
-
SELECT_NODE = 1,
|
|
2073
|
-
SET_OPERATION_NODE = 2,
|
|
2074
|
-
BOUND_SUBQUERY_NODE = 3,
|
|
2075
|
-
RECURSIVE_CTE_NODE = 4
|
|
2076
|
-
};
|
|
2077
|
-
|
|
2078
|
-
class QueryNode {
|
|
2079
|
-
public:
|
|
2080
|
-
explicit QueryNode(QueryNodeType type) : type(type) {
|
|
2081
|
-
}
|
|
2082
|
-
virtual ~QueryNode() {
|
|
2083
|
-
}
|
|
2084
|
-
|
|
2085
|
-
//! The type of the query node, either SetOperation or Select
|
|
2086
|
-
QueryNodeType type;
|
|
2087
|
-
//! The set of result modifiers associated with this query node
|
|
2088
|
-
vector<unique_ptr<ResultModifier>> modifiers;
|
|
2089
|
-
//! CTEs (used by SelectNode and SetOperationNode)
|
|
2090
|
-
unordered_map<string, unique_ptr<CommonTableExpressionInfo>> cte_map;
|
|
2091
|
-
|
|
2092
|
-
virtual const vector<unique_ptr<ParsedExpression>> &GetSelectList() const = 0;
|
|
2093
|
-
|
|
2094
|
-
public:
|
|
2095
|
-
virtual bool Equals(const QueryNode *other) const;
|
|
2096
|
-
|
|
2097
|
-
//! Create a copy of this QueryNode
|
|
2098
|
-
virtual unique_ptr<QueryNode> Copy() = 0;
|
|
2099
|
-
//! Serializes a QueryNode to a stand-alone binary blob
|
|
2100
|
-
virtual void Serialize(Serializer &serializer);
|
|
2101
|
-
//! Deserializes a blob back into a QueryNode, returns nullptr if
|
|
2102
|
-
//! deserialization is not possible
|
|
2103
|
-
static unique_ptr<QueryNode> Deserialize(Deserializer &source);
|
|
2104
|
-
|
|
2105
|
-
protected:
|
|
2106
|
-
//! Copy base QueryNode properties from another expression to this one,
|
|
2107
|
-
//! used in Copy method
|
|
2108
|
-
void CopyProperties(QueryNode &other) const;
|
|
2109
|
-
};
|
|
2110
|
-
|
|
2111
|
-
} // namespace duckdb
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
namespace duckdb {
|
|
2117
|
-
|
|
2118
|
-
class QueryNode;
|
|
2119
|
-
|
|
2120
|
-
//! SelectStatement is a typical SELECT clause
|
|
2121
|
-
class SelectStatement : public SQLStatement {
|
|
2122
|
-
public:
|
|
2123
|
-
SelectStatement() : SQLStatement(StatementType::SELECT_STATEMENT) {
|
|
2124
|
-
}
|
|
2125
|
-
|
|
2126
|
-
//! The main query node
|
|
2127
|
-
unique_ptr<QueryNode> node;
|
|
2128
|
-
|
|
2129
|
-
public:
|
|
2130
|
-
//! Create a copy of this SelectStatement
|
|
2131
|
-
unique_ptr<SQLStatement> Copy() const override;
|
|
2132
|
-
//! Serializes a SelectStatement to a stand-alone binary blob
|
|
2133
|
-
void Serialize(Serializer &serializer);
|
|
2134
|
-
//! Deserializes a blob back into a SelectStatement, returns nullptr if
|
|
2135
|
-
//! deserialization is not possible
|
|
2136
|
-
static unique_ptr<SelectStatement> Deserialize(Deserializer &source);
|
|
2137
|
-
//! Whether or not the statements are equivalent
|
|
2138
|
-
bool Equals(const SQLStatement *other) const;
|
|
2139
|
-
};
|
|
2140
|
-
} // namespace duckdb
|
|
2141
698
|
|
|
2142
699
|
|
|
2143
700
|
|
|
@@ -2235,7 +792,12 @@ public:
|
|
|
2235
792
|
namespace duckdb {
|
|
2236
793
|
class CatalogEntry;
|
|
2237
794
|
|
|
2238
|
-
enum class DependencyType {
|
|
795
|
+
enum class DependencyType {
|
|
796
|
+
DEPENDENCY_REGULAR = 0,
|
|
797
|
+
DEPENDENCY_AUTOMATIC = 1,
|
|
798
|
+
DEPENDENCY_OWNS = 2,
|
|
799
|
+
DEPENDENCY_OWNED_BY = 3
|
|
800
|
+
};
|
|
2239
801
|
|
|
2240
802
|
struct Dependency {
|
|
2241
803
|
Dependency(CatalogEntry *entry, DependencyType dependency_type = DependencyType::DEPENDENCY_REGULAR)
|
|
@@ -2286,18 +848,20 @@ public:
|
|
|
2286
848
|
//! Scans all dependencies, returning pairs of (object, dependent)
|
|
2287
849
|
void Scan(const std::function<void(CatalogEntry *, CatalogEntry *, DependencyType)> &callback);
|
|
2288
850
|
|
|
851
|
+
void AddOwnership(ClientContext &context, CatalogEntry *owner, CatalogEntry *entry);
|
|
852
|
+
|
|
2289
853
|
private:
|
|
2290
854
|
Catalog &catalog;
|
|
2291
855
|
//! Map of objects that DEPEND on [object], i.e. [object] can only be deleted when all entries in the dependency map
|
|
2292
856
|
//! are deleted.
|
|
2293
857
|
unordered_map<CatalogEntry *, dependency_set_t> dependents_map;
|
|
2294
858
|
//! Map of objects that the source object DEPENDS on, i.e. when any of the entries in the vector perform a CASCADE
|
|
2295
|
-
//! drop then [object] is deleted as
|
|
859
|
+
//! drop then [object] is deleted as well
|
|
2296
860
|
unordered_map<CatalogEntry *, unordered_set<CatalogEntry *>> dependencies_map;
|
|
2297
861
|
|
|
2298
862
|
private:
|
|
2299
863
|
void AddObject(ClientContext &context, CatalogEntry *object, unordered_set<CatalogEntry *> &dependencies);
|
|
2300
|
-
void DropObject(ClientContext &context, CatalogEntry *object, bool cascade
|
|
864
|
+
void DropObject(ClientContext &context, CatalogEntry *object, bool cascade);
|
|
2301
865
|
void AlterObject(ClientContext &context, CatalogEntry *old_obj, CatalogEntry *new_obj);
|
|
2302
866
|
void EraseObjectInternal(CatalogEntry *object);
|
|
2303
867
|
};
|
|
@@ -2361,244 +925,6 @@ public:
|
|
|
2361
925
|
};
|
|
2362
926
|
} // namespace duckdb
|
|
2363
927
|
|
|
2364
|
-
//===----------------------------------------------------------------------===//
|
|
2365
|
-
// DuckDB
|
|
2366
|
-
//
|
|
2367
|
-
// duckdb/parser/parsed_data/alter_table_info.hpp
|
|
2368
|
-
//
|
|
2369
|
-
//
|
|
2370
|
-
//===----------------------------------------------------------------------===//
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
namespace duckdb {
|
|
2379
|
-
|
|
2380
|
-
enum class AlterType : uint8_t { INVALID = 0, ALTER_TABLE = 1, ALTER_VIEW = 2 };
|
|
2381
|
-
|
|
2382
|
-
struct AlterInfo : public ParseInfo {
|
|
2383
|
-
AlterInfo(AlterType type, string schema, string name) : type(type), schema(move(schema)), name(move(name)) {
|
|
2384
|
-
}
|
|
2385
|
-
~AlterInfo() override {
|
|
2386
|
-
}
|
|
2387
|
-
|
|
2388
|
-
AlterType type;
|
|
2389
|
-
//! Schema name to alter
|
|
2390
|
-
string schema;
|
|
2391
|
-
//! Entry name to alter
|
|
2392
|
-
string name;
|
|
2393
|
-
|
|
2394
|
-
public:
|
|
2395
|
-
virtual CatalogType GetCatalogType() = 0;
|
|
2396
|
-
virtual unique_ptr<AlterInfo> Copy() const = 0;
|
|
2397
|
-
virtual void Serialize(Serializer &serializer);
|
|
2398
|
-
static unique_ptr<AlterInfo> Deserialize(Deserializer &source);
|
|
2399
|
-
};
|
|
2400
|
-
|
|
2401
|
-
//===--------------------------------------------------------------------===//
|
|
2402
|
-
// Alter Table
|
|
2403
|
-
//===--------------------------------------------------------------------===//
|
|
2404
|
-
enum class AlterTableType : uint8_t {
|
|
2405
|
-
INVALID = 0,
|
|
2406
|
-
RENAME_COLUMN = 1,
|
|
2407
|
-
RENAME_TABLE = 2,
|
|
2408
|
-
ADD_COLUMN = 3,
|
|
2409
|
-
REMOVE_COLUMN = 4,
|
|
2410
|
-
ALTER_COLUMN_TYPE = 5,
|
|
2411
|
-
SET_DEFAULT = 6
|
|
2412
|
-
};
|
|
2413
|
-
|
|
2414
|
-
struct AlterTableInfo : public AlterInfo {
|
|
2415
|
-
AlterTableInfo(AlterTableType type, string schema, string table)
|
|
2416
|
-
: AlterInfo(AlterType::ALTER_TABLE, schema, table), alter_table_type(type) {
|
|
2417
|
-
}
|
|
2418
|
-
~AlterTableInfo() override {
|
|
2419
|
-
}
|
|
2420
|
-
|
|
2421
|
-
AlterTableType alter_table_type;
|
|
2422
|
-
|
|
2423
|
-
public:
|
|
2424
|
-
CatalogType GetCatalogType() override {
|
|
2425
|
-
return CatalogType::TABLE_ENTRY;
|
|
2426
|
-
}
|
|
2427
|
-
void Serialize(Serializer &serializer) override;
|
|
2428
|
-
static unique_ptr<AlterInfo> Deserialize(Deserializer &source);
|
|
2429
|
-
};
|
|
2430
|
-
|
|
2431
|
-
//===--------------------------------------------------------------------===//
|
|
2432
|
-
// RenameColumnInfo
|
|
2433
|
-
//===--------------------------------------------------------------------===//
|
|
2434
|
-
struct RenameColumnInfo : public AlterTableInfo {
|
|
2435
|
-
RenameColumnInfo(string schema, string table, string old_name_p, string new_name_p)
|
|
2436
|
-
: AlterTableInfo(AlterTableType::RENAME_COLUMN, move(schema), move(table)), old_name(move(old_name_p)),
|
|
2437
|
-
new_name(move(new_name_p)) {
|
|
2438
|
-
}
|
|
2439
|
-
~RenameColumnInfo() override {
|
|
2440
|
-
}
|
|
2441
|
-
|
|
2442
|
-
//! Column old name
|
|
2443
|
-
string old_name;
|
|
2444
|
-
//! Column new name
|
|
2445
|
-
string new_name;
|
|
2446
|
-
|
|
2447
|
-
public:
|
|
2448
|
-
unique_ptr<AlterInfo> Copy() const override;
|
|
2449
|
-
void Serialize(Serializer &serializer) override;
|
|
2450
|
-
static unique_ptr<AlterInfo> Deserialize(Deserializer &source, string schema, string table);
|
|
2451
|
-
};
|
|
2452
|
-
|
|
2453
|
-
//===--------------------------------------------------------------------===//
|
|
2454
|
-
// RenameTableInfo
|
|
2455
|
-
//===--------------------------------------------------------------------===//
|
|
2456
|
-
struct RenameTableInfo : public AlterTableInfo {
|
|
2457
|
-
RenameTableInfo(string schema, string table, string new_name)
|
|
2458
|
-
: AlterTableInfo(AlterTableType::RENAME_TABLE, schema, table), new_table_name(new_name) {
|
|
2459
|
-
}
|
|
2460
|
-
~RenameTableInfo() override {
|
|
2461
|
-
}
|
|
2462
|
-
|
|
2463
|
-
//! Relation new name
|
|
2464
|
-
string new_table_name;
|
|
2465
|
-
|
|
2466
|
-
public:
|
|
2467
|
-
unique_ptr<AlterInfo> Copy() const override;
|
|
2468
|
-
void Serialize(Serializer &serializer) override;
|
|
2469
|
-
static unique_ptr<AlterInfo> Deserialize(Deserializer &source, string schema, string table);
|
|
2470
|
-
};
|
|
2471
|
-
|
|
2472
|
-
//===--------------------------------------------------------------------===//
|
|
2473
|
-
// AddColumnInfo
|
|
2474
|
-
//===--------------------------------------------------------------------===//
|
|
2475
|
-
struct AddColumnInfo : public AlterTableInfo {
|
|
2476
|
-
AddColumnInfo(string schema, string table, ColumnDefinition new_column)
|
|
2477
|
-
: AlterTableInfo(AlterTableType::ADD_COLUMN, schema, table), new_column(move(new_column)) {
|
|
2478
|
-
}
|
|
2479
|
-
~AddColumnInfo() override {
|
|
2480
|
-
}
|
|
2481
|
-
|
|
2482
|
-
//! New column
|
|
2483
|
-
ColumnDefinition new_column;
|
|
2484
|
-
|
|
2485
|
-
public:
|
|
2486
|
-
unique_ptr<AlterInfo> Copy() const override;
|
|
2487
|
-
void Serialize(Serializer &serializer) override;
|
|
2488
|
-
static unique_ptr<AlterInfo> Deserialize(Deserializer &source, string schema, string table);
|
|
2489
|
-
};
|
|
2490
|
-
|
|
2491
|
-
//===--------------------------------------------------------------------===//
|
|
2492
|
-
// RemoveColumnInfo
|
|
2493
|
-
//===--------------------------------------------------------------------===//
|
|
2494
|
-
struct RemoveColumnInfo : public AlterTableInfo {
|
|
2495
|
-
RemoveColumnInfo(string schema, string table, string removed_column, bool if_exists)
|
|
2496
|
-
: AlterTableInfo(AlterTableType::REMOVE_COLUMN, schema, table), removed_column(move(removed_column)),
|
|
2497
|
-
if_exists(if_exists) {
|
|
2498
|
-
}
|
|
2499
|
-
~RemoveColumnInfo() override {
|
|
2500
|
-
}
|
|
2501
|
-
|
|
2502
|
-
//! The column to remove
|
|
2503
|
-
string removed_column;
|
|
2504
|
-
//! Whether or not an error should be thrown if the column does not exist
|
|
2505
|
-
bool if_exists;
|
|
2506
|
-
|
|
2507
|
-
public:
|
|
2508
|
-
unique_ptr<AlterInfo> Copy() const override;
|
|
2509
|
-
void Serialize(Serializer &serializer) override;
|
|
2510
|
-
static unique_ptr<AlterInfo> Deserialize(Deserializer &source, string schema, string table);
|
|
2511
|
-
};
|
|
2512
|
-
|
|
2513
|
-
//===--------------------------------------------------------------------===//
|
|
2514
|
-
// ChangeColumnTypeInfo
|
|
2515
|
-
//===--------------------------------------------------------------------===//
|
|
2516
|
-
struct ChangeColumnTypeInfo : public AlterTableInfo {
|
|
2517
|
-
ChangeColumnTypeInfo(string schema, string table, string column_name, LogicalType target_type,
|
|
2518
|
-
unique_ptr<ParsedExpression> expression)
|
|
2519
|
-
: AlterTableInfo(AlterTableType::ALTER_COLUMN_TYPE, schema, table), column_name(move(column_name)),
|
|
2520
|
-
target_type(move(target_type)), expression(move(expression)) {
|
|
2521
|
-
}
|
|
2522
|
-
~ChangeColumnTypeInfo() override {
|
|
2523
|
-
}
|
|
2524
|
-
|
|
2525
|
-
//! The column name to alter
|
|
2526
|
-
string column_name;
|
|
2527
|
-
//! The target type of the column
|
|
2528
|
-
LogicalType target_type;
|
|
2529
|
-
//! The expression used for data conversion
|
|
2530
|
-
unique_ptr<ParsedExpression> expression;
|
|
2531
|
-
|
|
2532
|
-
public:
|
|
2533
|
-
unique_ptr<AlterInfo> Copy() const override;
|
|
2534
|
-
void Serialize(Serializer &serializer) override;
|
|
2535
|
-
static unique_ptr<AlterInfo> Deserialize(Deserializer &source, string schema, string table);
|
|
2536
|
-
};
|
|
2537
|
-
|
|
2538
|
-
//===--------------------------------------------------------------------===//
|
|
2539
|
-
// SetDefaultInfo
|
|
2540
|
-
//===--------------------------------------------------------------------===//
|
|
2541
|
-
struct SetDefaultInfo : public AlterTableInfo {
|
|
2542
|
-
SetDefaultInfo(string schema, string table, string column_name, unique_ptr<ParsedExpression> new_default)
|
|
2543
|
-
: AlterTableInfo(AlterTableType::SET_DEFAULT, schema, table), column_name(move(column_name)),
|
|
2544
|
-
expression(move(new_default)) {
|
|
2545
|
-
}
|
|
2546
|
-
~SetDefaultInfo() override {
|
|
2547
|
-
}
|
|
2548
|
-
|
|
2549
|
-
//! The column name to alter
|
|
2550
|
-
string column_name;
|
|
2551
|
-
//! The expression used for data conversion
|
|
2552
|
-
unique_ptr<ParsedExpression> expression;
|
|
2553
|
-
|
|
2554
|
-
public:
|
|
2555
|
-
unique_ptr<AlterInfo> Copy() const override;
|
|
2556
|
-
void Serialize(Serializer &serializer) override;
|
|
2557
|
-
static unique_ptr<AlterInfo> Deserialize(Deserializer &source, string schema, string table);
|
|
2558
|
-
};
|
|
2559
|
-
|
|
2560
|
-
//===--------------------------------------------------------------------===//
|
|
2561
|
-
// Alter View
|
|
2562
|
-
//===--------------------------------------------------------------------===//
|
|
2563
|
-
enum class AlterViewType : uint8_t { INVALID = 0, RENAME_VIEW = 1 };
|
|
2564
|
-
|
|
2565
|
-
struct AlterViewInfo : public AlterInfo {
|
|
2566
|
-
AlterViewInfo(AlterViewType type, string schema, string view)
|
|
2567
|
-
: AlterInfo(AlterType::ALTER_VIEW, schema, view), alter_view_type(type) {
|
|
2568
|
-
}
|
|
2569
|
-
~AlterViewInfo() override {
|
|
2570
|
-
}
|
|
2571
|
-
|
|
2572
|
-
AlterViewType alter_view_type;
|
|
2573
|
-
|
|
2574
|
-
public:
|
|
2575
|
-
CatalogType GetCatalogType() override {
|
|
2576
|
-
return CatalogType::VIEW_ENTRY;
|
|
2577
|
-
}
|
|
2578
|
-
void Serialize(Serializer &serializer) override;
|
|
2579
|
-
static unique_ptr<AlterInfo> Deserialize(Deserializer &source);
|
|
2580
|
-
};
|
|
2581
|
-
|
|
2582
|
-
//===--------------------------------------------------------------------===//
|
|
2583
|
-
// RenameViewInfo
|
|
2584
|
-
//===--------------------------------------------------------------------===//
|
|
2585
|
-
struct RenameViewInfo : public AlterViewInfo {
|
|
2586
|
-
RenameViewInfo(string schema, string view, string new_name)
|
|
2587
|
-
: AlterViewInfo(AlterViewType::RENAME_VIEW, schema, view), new_view_name(new_name) {
|
|
2588
|
-
}
|
|
2589
|
-
~RenameViewInfo() override {
|
|
2590
|
-
}
|
|
2591
|
-
|
|
2592
|
-
//! Relation new name
|
|
2593
|
-
string new_view_name;
|
|
2594
|
-
|
|
2595
|
-
public:
|
|
2596
|
-
unique_ptr<AlterInfo> Copy() const override;
|
|
2597
|
-
void Serialize(Serializer &serializer) override;
|
|
2598
|
-
static unique_ptr<AlterInfo> Deserialize(Deserializer &source, string schema, string table);
|
|
2599
|
-
};
|
|
2600
|
-
|
|
2601
|
-
} // namespace duckdb
|
|
2602
928
|
|
|
2603
929
|
|
|
2604
930
|
|
|
@@ -2892,58 +1218,6 @@ public:
|
|
|
2892
1218
|
|
|
2893
1219
|
|
|
2894
1220
|
|
|
2895
|
-
//===----------------------------------------------------------------------===//
|
|
2896
|
-
// DuckDB
|
|
2897
|
-
//
|
|
2898
|
-
// duckdb/storage/storage_lock.hpp
|
|
2899
|
-
//
|
|
2900
|
-
//
|
|
2901
|
-
//===----------------------------------------------------------------------===//
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
namespace duckdb {
|
|
2910
|
-
class StorageLock;
|
|
2911
|
-
|
|
2912
|
-
enum class StorageLockType { SHARED = 0, EXCLUSIVE = 1 };
|
|
2913
|
-
|
|
2914
|
-
class StorageLockKey {
|
|
2915
|
-
public:
|
|
2916
|
-
StorageLockKey(StorageLock &lock, StorageLockType type);
|
|
2917
|
-
~StorageLockKey();
|
|
2918
|
-
|
|
2919
|
-
private:
|
|
2920
|
-
StorageLock &lock;
|
|
2921
|
-
StorageLockType type;
|
|
2922
|
-
};
|
|
2923
|
-
|
|
2924
|
-
class StorageLock {
|
|
2925
|
-
friend class StorageLockKey;
|
|
2926
|
-
|
|
2927
|
-
public:
|
|
2928
|
-
StorageLock();
|
|
2929
|
-
|
|
2930
|
-
//! Get an exclusive lock
|
|
2931
|
-
unique_ptr<StorageLockKey> GetExclusiveLock();
|
|
2932
|
-
//! Get a shared lock
|
|
2933
|
-
unique_ptr<StorageLockKey> GetSharedLock();
|
|
2934
|
-
|
|
2935
|
-
private:
|
|
2936
|
-
mutex exclusive_lock;
|
|
2937
|
-
atomic<idx_t> read_count;
|
|
2938
|
-
|
|
2939
|
-
private:
|
|
2940
|
-
//! Release an exclusive lock
|
|
2941
|
-
void ReleaseExclusiveLock();
|
|
2942
|
-
//! Release a shared lock
|
|
2943
|
-
void ReleaseSharedLock();
|
|
2944
|
-
};
|
|
2945
|
-
|
|
2946
|
-
} // namespace duckdb
|
|
2947
1221
|
|
|
2948
1222
|
//===----------------------------------------------------------------------===//
|
|
2949
1223
|
// DuckDB
|
|
@@ -3033,73 +1307,6 @@ public:
|
|
|
3033
1307
|
|
|
3034
1308
|
|
|
3035
1309
|
|
|
3036
|
-
//===----------------------------------------------------------------------===//
|
|
3037
|
-
// DuckDB
|
|
3038
|
-
//
|
|
3039
|
-
// duckdb/storage/storage_info.hpp
|
|
3040
|
-
//
|
|
3041
|
-
//
|
|
3042
|
-
//===----------------------------------------------------------------------===//
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
namespace duckdb {
|
|
3049
|
-
class Serializer;
|
|
3050
|
-
class Deserializer;
|
|
3051
|
-
struct FileHandle;
|
|
3052
|
-
|
|
3053
|
-
//! The version number of the database storage format
|
|
3054
|
-
extern const uint64_t VERSION_NUMBER;
|
|
3055
|
-
|
|
3056
|
-
using block_id_t = int64_t;
|
|
3057
|
-
|
|
3058
|
-
#define INVALID_BLOCK (-1)
|
|
3059
|
-
|
|
3060
|
-
// maximum block id, 2^62
|
|
3061
|
-
#define MAXIMUM_BLOCK 4611686018427388000LL
|
|
3062
|
-
|
|
3063
|
-
//! The MainHeader is the first header in the storage file. The MainHeader is typically written only once for a database
|
|
3064
|
-
//! file.
|
|
3065
|
-
struct MainHeader {
|
|
3066
|
-
static constexpr idx_t MAGIC_BYTE_SIZE = 4;
|
|
3067
|
-
static constexpr idx_t MAGIC_BYTE_OFFSET = sizeof(uint64_t);
|
|
3068
|
-
static constexpr idx_t FLAG_COUNT = 4;
|
|
3069
|
-
// the magic bytes in front of the file
|
|
3070
|
-
// should be "DUCK"
|
|
3071
|
-
static const char MAGIC_BYTES[];
|
|
3072
|
-
//! The version of the database
|
|
3073
|
-
uint64_t version_number;
|
|
3074
|
-
//! The set of flags used by the database
|
|
3075
|
-
uint64_t flags[FLAG_COUNT];
|
|
3076
|
-
|
|
3077
|
-
static void CheckMagicBytes(FileHandle &handle);
|
|
3078
|
-
|
|
3079
|
-
void Serialize(Serializer &ser);
|
|
3080
|
-
static MainHeader Deserialize(Deserializer &source);
|
|
3081
|
-
};
|
|
3082
|
-
|
|
3083
|
-
//! The DatabaseHeader contains information about the current state of the database. Every storage file has two
|
|
3084
|
-
//! DatabaseHeaders. On startup, the DatabaseHeader with the highest iteration count is used as the active header. When
|
|
3085
|
-
//! a checkpoint is performed, the active DatabaseHeader is switched by increasing the iteration count of the
|
|
3086
|
-
//! DatabaseHeader.
|
|
3087
|
-
struct DatabaseHeader {
|
|
3088
|
-
//! The iteration count, increases by 1 every time the storage is checkpointed.
|
|
3089
|
-
uint64_t iteration;
|
|
3090
|
-
//! A pointer to the initial meta block
|
|
3091
|
-
block_id_t meta_block;
|
|
3092
|
-
//! A pointer to the block containing the free list
|
|
3093
|
-
block_id_t free_list;
|
|
3094
|
-
//! The number of blocks that is in the file as of this database header. If the file is larger than BLOCK_SIZE *
|
|
3095
|
-
//! block_count any blocks appearing AFTER block_count are implicitly part of the free_list.
|
|
3096
|
-
uint64_t block_count;
|
|
3097
|
-
|
|
3098
|
-
void Serialize(Serializer &ser);
|
|
3099
|
-
static DatabaseHeader Deserialize(Deserializer &source);
|
|
3100
|
-
};
|
|
3101
|
-
|
|
3102
|
-
} // namespace duckdb
|
|
3103
1310
|
|
|
3104
1311
|
//===----------------------------------------------------------------------===//
|
|
3105
1312
|
// DuckDB
|
|
@@ -3263,35 +1470,6 @@ private:
|
|
|
3263
1470
|
|
|
3264
1471
|
|
|
3265
1472
|
|
|
3266
|
-
//===----------------------------------------------------------------------===//
|
|
3267
|
-
// DuckDB
|
|
3268
|
-
//
|
|
3269
|
-
// duckdb/storage/buffer/buffer_handle.hpp
|
|
3270
|
-
//
|
|
3271
|
-
//
|
|
3272
|
-
//===----------------------------------------------------------------------===//
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
namespace duckdb {
|
|
3279
|
-
class BlockHandle;
|
|
3280
|
-
class FileBuffer;
|
|
3281
|
-
|
|
3282
|
-
class BufferHandle {
|
|
3283
|
-
public:
|
|
3284
|
-
BufferHandle(shared_ptr<BlockHandle> handle, FileBuffer *node);
|
|
3285
|
-
~BufferHandle();
|
|
3286
|
-
|
|
3287
|
-
//! The block handle
|
|
3288
|
-
shared_ptr<BlockHandle> handle;
|
|
3289
|
-
//! The managed buffer node
|
|
3290
|
-
FileBuffer *node;
|
|
3291
|
-
data_ptr_t Ptr();
|
|
3292
|
-
};
|
|
3293
|
-
|
|
3294
|
-
} // namespace duckdb
|
|
3295
1473
|
|
|
3296
1474
|
|
|
3297
1475
|
|
|
@@ -3344,927 +1522,6 @@ struct TableAppendState {
|
|
|
3344
1522
|
|
|
3345
1523
|
} // namespace duckdb
|
|
3346
1524
|
|
|
3347
|
-
//===----------------------------------------------------------------------===//
|
|
3348
|
-
// DuckDB
|
|
3349
|
-
//
|
|
3350
|
-
// duckdb/storage/table/scan_state.hpp
|
|
3351
|
-
//
|
|
3352
|
-
//
|
|
3353
|
-
//===----------------------------------------------------------------------===//
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
//===----------------------------------------------------------------------===//
|
|
3362
|
-
// DuckDB
|
|
3363
|
-
//
|
|
3364
|
-
// duckdb/execution/adaptive_filter.hpp
|
|
3365
|
-
//
|
|
3366
|
-
//
|
|
3367
|
-
//===----------------------------------------------------------------------===//
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
//===----------------------------------------------------------------------===//
|
|
3372
|
-
// DuckDB
|
|
3373
|
-
//
|
|
3374
|
-
// duckdb/planner/expression/bound_aggregate_expression.hpp
|
|
3375
|
-
//
|
|
3376
|
-
//
|
|
3377
|
-
//===----------------------------------------------------------------------===//
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
#include <memory>
|
|
3384
|
-
|
|
3385
|
-
namespace duckdb {
|
|
3386
|
-
class BoundAggregateExpression : public Expression {
|
|
3387
|
-
public:
|
|
3388
|
-
BoundAggregateExpression(AggregateFunction function, vector<unique_ptr<Expression>> children,
|
|
3389
|
-
unique_ptr<Expression> filter, unique_ptr<FunctionData> bind_info, bool distinct);
|
|
3390
|
-
|
|
3391
|
-
//! The bound function expression
|
|
3392
|
-
AggregateFunction function;
|
|
3393
|
-
//! List of arguments to the function
|
|
3394
|
-
vector<unique_ptr<Expression>> children;
|
|
3395
|
-
//! The bound function data (if any)
|
|
3396
|
-
unique_ptr<FunctionData> bind_info;
|
|
3397
|
-
//! True to aggregate on distinct values
|
|
3398
|
-
bool distinct;
|
|
3399
|
-
|
|
3400
|
-
//! Filter for this aggregate
|
|
3401
|
-
unique_ptr<Expression> filter;
|
|
3402
|
-
|
|
3403
|
-
public:
|
|
3404
|
-
bool IsAggregate() const override {
|
|
3405
|
-
return true;
|
|
3406
|
-
}
|
|
3407
|
-
bool IsFoldable() const override {
|
|
3408
|
-
return false;
|
|
3409
|
-
}
|
|
3410
|
-
|
|
3411
|
-
string ToString() const override;
|
|
3412
|
-
|
|
3413
|
-
hash_t Hash() const override;
|
|
3414
|
-
bool Equals(const BaseExpression *other) const override;
|
|
3415
|
-
unique_ptr<Expression> Copy() override;
|
|
3416
|
-
};
|
|
3417
|
-
} // namespace duckdb
|
|
3418
|
-
|
|
3419
|
-
//===----------------------------------------------------------------------===//
|
|
3420
|
-
// DuckDB
|
|
3421
|
-
//
|
|
3422
|
-
// duckdb/planner/expression/bound_between_expression.hpp
|
|
3423
|
-
//
|
|
3424
|
-
//
|
|
3425
|
-
//===----------------------------------------------------------------------===//
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
namespace duckdb {
|
|
3432
|
-
|
|
3433
|
-
class BoundBetweenExpression : public Expression {
|
|
3434
|
-
public:
|
|
3435
|
-
BoundBetweenExpression(unique_ptr<Expression> input, unique_ptr<Expression> lower, unique_ptr<Expression> upper,
|
|
3436
|
-
bool lower_inclusive, bool upper_inclusive);
|
|
3437
|
-
|
|
3438
|
-
unique_ptr<Expression> input;
|
|
3439
|
-
unique_ptr<Expression> lower;
|
|
3440
|
-
unique_ptr<Expression> upper;
|
|
3441
|
-
bool lower_inclusive;
|
|
3442
|
-
bool upper_inclusive;
|
|
3443
|
-
|
|
3444
|
-
public:
|
|
3445
|
-
string ToString() const override;
|
|
3446
|
-
|
|
3447
|
-
bool Equals(const BaseExpression *other) const override;
|
|
3448
|
-
|
|
3449
|
-
unique_ptr<Expression> Copy() override;
|
|
3450
|
-
|
|
3451
|
-
public:
|
|
3452
|
-
ExpressionType LowerComparisonType() {
|
|
3453
|
-
return lower_inclusive ? ExpressionType::COMPARE_GREATERTHANOREQUALTO : ExpressionType::COMPARE_GREATERTHAN;
|
|
3454
|
-
}
|
|
3455
|
-
ExpressionType UpperComparisonType() {
|
|
3456
|
-
return upper_inclusive ? ExpressionType::COMPARE_LESSTHANOREQUALTO : ExpressionType::COMPARE_LESSTHAN;
|
|
3457
|
-
}
|
|
3458
|
-
};
|
|
3459
|
-
} // namespace duckdb
|
|
3460
|
-
|
|
3461
|
-
//===----------------------------------------------------------------------===//
|
|
3462
|
-
// DuckDB
|
|
3463
|
-
//
|
|
3464
|
-
// duckdb/planner/expression/bound_case_expression.hpp
|
|
3465
|
-
//
|
|
3466
|
-
//
|
|
3467
|
-
//===----------------------------------------------------------------------===//
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
namespace duckdb {
|
|
3474
|
-
|
|
3475
|
-
struct BoundCaseCheck {
|
|
3476
|
-
unique_ptr<Expression> when_expr;
|
|
3477
|
-
unique_ptr<Expression> then_expr;
|
|
3478
|
-
};
|
|
3479
|
-
|
|
3480
|
-
class BoundCaseExpression : public Expression {
|
|
3481
|
-
public:
|
|
3482
|
-
BoundCaseExpression(LogicalType type);
|
|
3483
|
-
BoundCaseExpression(unique_ptr<Expression> when_expr, unique_ptr<Expression> then_expr,
|
|
3484
|
-
unique_ptr<Expression> else_expr);
|
|
3485
|
-
|
|
3486
|
-
vector<BoundCaseCheck> case_checks;
|
|
3487
|
-
unique_ptr<Expression> else_expr;
|
|
3488
|
-
|
|
3489
|
-
public:
|
|
3490
|
-
string ToString() const override;
|
|
3491
|
-
|
|
3492
|
-
bool Equals(const BaseExpression *other) const override;
|
|
3493
|
-
|
|
3494
|
-
unique_ptr<Expression> Copy() override;
|
|
3495
|
-
};
|
|
3496
|
-
} // namespace duckdb
|
|
3497
|
-
|
|
3498
|
-
//===----------------------------------------------------------------------===//
|
|
3499
|
-
// DuckDB
|
|
3500
|
-
//
|
|
3501
|
-
// duckdb/planner/expression/bound_cast_expression.hpp
|
|
3502
|
-
//
|
|
3503
|
-
//
|
|
3504
|
-
//===----------------------------------------------------------------------===//
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
namespace duckdb {
|
|
3511
|
-
|
|
3512
|
-
class BoundCastExpression : public Expression {
|
|
3513
|
-
public:
|
|
3514
|
-
BoundCastExpression(unique_ptr<Expression> child, LogicalType target_type, bool try_cast = false);
|
|
3515
|
-
|
|
3516
|
-
//! The child type
|
|
3517
|
-
unique_ptr<Expression> child;
|
|
3518
|
-
//! Whether to use try_cast or not. try_cast converts cast failures into NULLs instead of throwing an error.
|
|
3519
|
-
bool try_cast;
|
|
3520
|
-
|
|
3521
|
-
public:
|
|
3522
|
-
LogicalType source_type() {
|
|
3523
|
-
return child->return_type;
|
|
3524
|
-
}
|
|
3525
|
-
|
|
3526
|
-
//! Cast an expression to the specified SQL type if required
|
|
3527
|
-
static unique_ptr<Expression> AddCastToType(unique_ptr<Expression> expr, const LogicalType &target_type);
|
|
3528
|
-
//! Returns true if a cast is invertible (i.e. CAST(s -> t -> s) = s for all values of s). This is not true for e.g.
|
|
3529
|
-
//! boolean casts, because that can be e.g. -1 -> TRUE -> 1. This is necessary to prevent some optimizer bugs.
|
|
3530
|
-
static bool CastIsInvertible(const LogicalType &source_type, const LogicalType &target_type);
|
|
3531
|
-
|
|
3532
|
-
string ToString() const override;
|
|
3533
|
-
|
|
3534
|
-
bool Equals(const BaseExpression *other) const override;
|
|
3535
|
-
|
|
3536
|
-
unique_ptr<Expression> Copy() override;
|
|
3537
|
-
};
|
|
3538
|
-
} // namespace duckdb
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
//===----------------------------------------------------------------------===//
|
|
3542
|
-
// DuckDB
|
|
3543
|
-
//
|
|
3544
|
-
// duckdb/planner/expression/bound_comparison_expression.hpp
|
|
3545
|
-
//
|
|
3546
|
-
//
|
|
3547
|
-
//===----------------------------------------------------------------------===//
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
namespace duckdb {
|
|
3554
|
-
|
|
3555
|
-
class BoundComparisonExpression : public Expression {
|
|
3556
|
-
public:
|
|
3557
|
-
BoundComparisonExpression(ExpressionType type, unique_ptr<Expression> left, unique_ptr<Expression> right);
|
|
3558
|
-
|
|
3559
|
-
unique_ptr<Expression> left;
|
|
3560
|
-
unique_ptr<Expression> right;
|
|
3561
|
-
|
|
3562
|
-
public:
|
|
3563
|
-
string ToString() const override;
|
|
3564
|
-
|
|
3565
|
-
bool Equals(const BaseExpression *other) const override;
|
|
3566
|
-
|
|
3567
|
-
unique_ptr<Expression> Copy() override;
|
|
3568
|
-
|
|
3569
|
-
public:
|
|
3570
|
-
static LogicalType BindComparison(LogicalType left_type, LogicalType right_type);
|
|
3571
|
-
};
|
|
3572
|
-
} // namespace duckdb
|
|
3573
|
-
|
|
3574
|
-
//===----------------------------------------------------------------------===//
|
|
3575
|
-
// DuckDB
|
|
3576
|
-
//
|
|
3577
|
-
// duckdb/planner/expression/bound_conjunction_expression.hpp
|
|
3578
|
-
//
|
|
3579
|
-
//
|
|
3580
|
-
//===----------------------------------------------------------------------===//
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
namespace duckdb {
|
|
3587
|
-
|
|
3588
|
-
class BoundConjunctionExpression : public Expression {
|
|
3589
|
-
public:
|
|
3590
|
-
explicit BoundConjunctionExpression(ExpressionType type);
|
|
3591
|
-
BoundConjunctionExpression(ExpressionType type, unique_ptr<Expression> left, unique_ptr<Expression> right);
|
|
3592
|
-
|
|
3593
|
-
vector<unique_ptr<Expression>> children;
|
|
3594
|
-
|
|
3595
|
-
public:
|
|
3596
|
-
string ToString() const override;
|
|
3597
|
-
|
|
3598
|
-
bool Equals(const BaseExpression *other) const override;
|
|
3599
|
-
|
|
3600
|
-
unique_ptr<Expression> Copy() override;
|
|
3601
|
-
};
|
|
3602
|
-
} // namespace duckdb
|
|
3603
|
-
|
|
3604
|
-
//===----------------------------------------------------------------------===//
|
|
3605
|
-
// DuckDB
|
|
3606
|
-
//
|
|
3607
|
-
// duckdb/planner/expression/bound_constant_expression.hpp
|
|
3608
|
-
//
|
|
3609
|
-
//
|
|
3610
|
-
//===----------------------------------------------------------------------===//
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
namespace duckdb {
|
|
3618
|
-
|
|
3619
|
-
class BoundConstantExpression : public Expression {
|
|
3620
|
-
public:
|
|
3621
|
-
explicit BoundConstantExpression(Value value);
|
|
3622
|
-
|
|
3623
|
-
Value value;
|
|
3624
|
-
|
|
3625
|
-
public:
|
|
3626
|
-
string ToString() const override;
|
|
3627
|
-
|
|
3628
|
-
bool Equals(const BaseExpression *other) const override;
|
|
3629
|
-
hash_t Hash() const override;
|
|
3630
|
-
|
|
3631
|
-
unique_ptr<Expression> Copy() override;
|
|
3632
|
-
};
|
|
3633
|
-
} // namespace duckdb
|
|
3634
|
-
|
|
3635
|
-
//===----------------------------------------------------------------------===//
|
|
3636
|
-
// DuckDB
|
|
3637
|
-
//
|
|
3638
|
-
// duckdb/planner/expression/bound_default_expression.hpp
|
|
3639
|
-
//
|
|
3640
|
-
//
|
|
3641
|
-
//===----------------------------------------------------------------------===//
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
namespace duckdb {
|
|
3648
|
-
|
|
3649
|
-
class BoundDefaultExpression : public Expression {
|
|
3650
|
-
public:
|
|
3651
|
-
explicit BoundDefaultExpression(LogicalType type = LogicalType())
|
|
3652
|
-
: Expression(ExpressionType::VALUE_DEFAULT, ExpressionClass::BOUND_DEFAULT, type) {
|
|
3653
|
-
}
|
|
3654
|
-
|
|
3655
|
-
public:
|
|
3656
|
-
bool IsScalar() const override {
|
|
3657
|
-
return false;
|
|
3658
|
-
}
|
|
3659
|
-
bool IsFoldable() const override {
|
|
3660
|
-
return false;
|
|
3661
|
-
}
|
|
3662
|
-
|
|
3663
|
-
string ToString() const override {
|
|
3664
|
-
return "DEFAULT";
|
|
3665
|
-
}
|
|
3666
|
-
|
|
3667
|
-
unique_ptr<Expression> Copy() override {
|
|
3668
|
-
return make_unique<BoundDefaultExpression>(return_type);
|
|
3669
|
-
}
|
|
3670
|
-
};
|
|
3671
|
-
} // namespace duckdb
|
|
3672
|
-
|
|
3673
|
-
//===----------------------------------------------------------------------===//
|
|
3674
|
-
// DuckDB
|
|
3675
|
-
//
|
|
3676
|
-
// duckdb/planner/expression/bound_function_expression.hpp
|
|
3677
|
-
//
|
|
3678
|
-
//
|
|
3679
|
-
//===----------------------------------------------------------------------===//
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
namespace duckdb {
|
|
3687
|
-
class ScalarFunctionCatalogEntry;
|
|
3688
|
-
|
|
3689
|
-
//! Represents a function call that has been bound to a base function
|
|
3690
|
-
class BoundFunctionExpression : public Expression {
|
|
3691
|
-
public:
|
|
3692
|
-
BoundFunctionExpression(LogicalType return_type, ScalarFunction bound_function,
|
|
3693
|
-
vector<unique_ptr<Expression>> arguments, unique_ptr<FunctionData> bind_info,
|
|
3694
|
-
bool is_operator = false);
|
|
3695
|
-
|
|
3696
|
-
// The bound function expression
|
|
3697
|
-
ScalarFunction function;
|
|
3698
|
-
//! List of child-expressions of the function
|
|
3699
|
-
vector<unique_ptr<Expression>> children;
|
|
3700
|
-
//! The bound function data (if any)
|
|
3701
|
-
unique_ptr<FunctionData> bind_info;
|
|
3702
|
-
//! Whether or not the function is an operator, only used for rendering
|
|
3703
|
-
bool is_operator;
|
|
3704
|
-
|
|
3705
|
-
public:
|
|
3706
|
-
bool HasSideEffects() const override;
|
|
3707
|
-
bool IsFoldable() const override;
|
|
3708
|
-
string ToString() const override;
|
|
3709
|
-
|
|
3710
|
-
hash_t Hash() const override;
|
|
3711
|
-
bool Equals(const BaseExpression *other) const override;
|
|
3712
|
-
|
|
3713
|
-
unique_ptr<Expression> Copy() override;
|
|
3714
|
-
};
|
|
3715
|
-
} // namespace duckdb
|
|
3716
|
-
|
|
3717
|
-
//===----------------------------------------------------------------------===//
|
|
3718
|
-
// DuckDB
|
|
3719
|
-
//
|
|
3720
|
-
// duckdb/planner/expression/bound_operator_expression.hpp
|
|
3721
|
-
//
|
|
3722
|
-
//
|
|
3723
|
-
//===----------------------------------------------------------------------===//
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
namespace duckdb {
|
|
3730
|
-
|
|
3731
|
-
class BoundOperatorExpression : public Expression {
|
|
3732
|
-
public:
|
|
3733
|
-
BoundOperatorExpression(ExpressionType type, LogicalType return_type);
|
|
3734
|
-
|
|
3735
|
-
vector<unique_ptr<Expression>> children;
|
|
3736
|
-
|
|
3737
|
-
public:
|
|
3738
|
-
string ToString() const override;
|
|
3739
|
-
|
|
3740
|
-
bool Equals(const BaseExpression *other) const override;
|
|
3741
|
-
|
|
3742
|
-
unique_ptr<Expression> Copy() override;
|
|
3743
|
-
};
|
|
3744
|
-
} // namespace duckdb
|
|
3745
|
-
|
|
3746
|
-
//===----------------------------------------------------------------------===//
|
|
3747
|
-
// DuckDB
|
|
3748
|
-
//
|
|
3749
|
-
// duckdb/planner/expression/bound_parameter_expression.hpp
|
|
3750
|
-
//
|
|
3751
|
-
//
|
|
3752
|
-
//===----------------------------------------------------------------------===//
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
namespace duckdb {
|
|
3760
|
-
|
|
3761
|
-
class BoundParameterExpression : public Expression {
|
|
3762
|
-
public:
|
|
3763
|
-
explicit BoundParameterExpression(idx_t parameter_nr);
|
|
3764
|
-
|
|
3765
|
-
idx_t parameter_nr;
|
|
3766
|
-
Value *value;
|
|
3767
|
-
|
|
3768
|
-
public:
|
|
3769
|
-
bool IsScalar() const override;
|
|
3770
|
-
bool HasParameter() const override;
|
|
3771
|
-
bool IsFoldable() const override;
|
|
3772
|
-
|
|
3773
|
-
string ToString() const override;
|
|
3774
|
-
|
|
3775
|
-
bool Equals(const BaseExpression *other) const override;
|
|
3776
|
-
hash_t Hash() const override;
|
|
3777
|
-
|
|
3778
|
-
unique_ptr<Expression> Copy() override;
|
|
3779
|
-
};
|
|
3780
|
-
} // namespace duckdb
|
|
3781
|
-
|
|
3782
|
-
//===----------------------------------------------------------------------===//
|
|
3783
|
-
// DuckDB
|
|
3784
|
-
//
|
|
3785
|
-
// duckdb/planner/expression/bound_reference_expression.hpp
|
|
3786
|
-
//
|
|
3787
|
-
//
|
|
3788
|
-
//===----------------------------------------------------------------------===//
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
namespace duckdb {
|
|
3795
|
-
|
|
3796
|
-
//! A BoundReferenceExpression represents a physical index into a DataChunk
|
|
3797
|
-
class BoundReferenceExpression : public Expression {
|
|
3798
|
-
public:
|
|
3799
|
-
BoundReferenceExpression(string alias, LogicalType type, idx_t index);
|
|
3800
|
-
BoundReferenceExpression(LogicalType type, idx_t index);
|
|
3801
|
-
|
|
3802
|
-
//! Index used to access data in the chunks
|
|
3803
|
-
idx_t index;
|
|
3804
|
-
|
|
3805
|
-
public:
|
|
3806
|
-
bool IsScalar() const override {
|
|
3807
|
-
return false;
|
|
3808
|
-
}
|
|
3809
|
-
bool IsFoldable() const override {
|
|
3810
|
-
return false;
|
|
3811
|
-
}
|
|
3812
|
-
|
|
3813
|
-
string ToString() const override;
|
|
3814
|
-
|
|
3815
|
-
hash_t Hash() const override;
|
|
3816
|
-
bool Equals(const BaseExpression *other) const override;
|
|
3817
|
-
|
|
3818
|
-
unique_ptr<Expression> Copy() override;
|
|
3819
|
-
};
|
|
3820
|
-
} // namespace duckdb
|
|
3821
|
-
|
|
3822
|
-
//===----------------------------------------------------------------------===//
|
|
3823
|
-
// DuckDB
|
|
3824
|
-
//
|
|
3825
|
-
// duckdb/planner/expression/bound_subquery_expression.hpp
|
|
3826
|
-
//
|
|
3827
|
-
//
|
|
3828
|
-
//===----------------------------------------------------------------------===//
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
//===----------------------------------------------------------------------===//
|
|
3833
|
-
// DuckDB
|
|
3834
|
-
//
|
|
3835
|
-
// duckdb/common/enums/subquery_type.hpp
|
|
3836
|
-
//
|
|
3837
|
-
//
|
|
3838
|
-
//===----------------------------------------------------------------------===//
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
namespace duckdb {
|
|
3845
|
-
|
|
3846
|
-
//===--------------------------------------------------------------------===//
|
|
3847
|
-
// Subquery Types
|
|
3848
|
-
//===--------------------------------------------------------------------===//
|
|
3849
|
-
enum class SubqueryType : uint8_t {
|
|
3850
|
-
INVALID = 0,
|
|
3851
|
-
SCALAR = 1, // Regular scalar subquery
|
|
3852
|
-
EXISTS = 2, // EXISTS (SELECT...)
|
|
3853
|
-
NOT_EXISTS = 3, // NOT EXISTS(SELECT...)
|
|
3854
|
-
ANY = 4, // x = ANY(SELECT...) OR x IN (SELECT...)
|
|
3855
|
-
};
|
|
3856
|
-
|
|
3857
|
-
} // namespace duckdb
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
//===----------------------------------------------------------------------===//
|
|
3861
|
-
// DuckDB
|
|
3862
|
-
//
|
|
3863
|
-
// duckdb/planner/bound_query_node.hpp
|
|
3864
|
-
//
|
|
3865
|
-
//
|
|
3866
|
-
//===----------------------------------------------------------------------===//
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
namespace duckdb {
|
|
3875
|
-
|
|
3876
|
-
//! Bound equivalent of QueryNode
|
|
3877
|
-
class BoundQueryNode {
|
|
3878
|
-
public:
|
|
3879
|
-
explicit BoundQueryNode(QueryNodeType type) : type(type) {
|
|
3880
|
-
}
|
|
3881
|
-
virtual ~BoundQueryNode() {
|
|
3882
|
-
}
|
|
3883
|
-
|
|
3884
|
-
//! The type of the query node, either SetOperation or Select
|
|
3885
|
-
QueryNodeType type;
|
|
3886
|
-
//! The result modifiers that should be applied to this query node
|
|
3887
|
-
vector<unique_ptr<BoundResultModifier>> modifiers;
|
|
3888
|
-
|
|
3889
|
-
//! The names returned by this QueryNode.
|
|
3890
|
-
vector<string> names;
|
|
3891
|
-
//! The types returned by this QueryNode.
|
|
3892
|
-
vector<LogicalType> types;
|
|
3893
|
-
|
|
3894
|
-
public:
|
|
3895
|
-
virtual idx_t GetRootIndex() = 0;
|
|
3896
|
-
};
|
|
3897
|
-
|
|
3898
|
-
} // namespace duckdb
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
namespace duckdb {
|
|
3903
|
-
|
|
3904
|
-
class BoundSubqueryExpression : public Expression {
|
|
3905
|
-
public:
|
|
3906
|
-
explicit BoundSubqueryExpression(LogicalType return_type);
|
|
3907
|
-
|
|
3908
|
-
bool IsCorrelated() {
|
|
3909
|
-
return binder->correlated_columns.size() > 0;
|
|
3910
|
-
}
|
|
3911
|
-
|
|
3912
|
-
//! The binder used to bind the subquery node
|
|
3913
|
-
shared_ptr<Binder> binder;
|
|
3914
|
-
//! The bound subquery node
|
|
3915
|
-
unique_ptr<BoundQueryNode> subquery;
|
|
3916
|
-
//! The subquery type
|
|
3917
|
-
SubqueryType subquery_type;
|
|
3918
|
-
//! the child expression to compare with (in case of IN, ANY, ALL operators)
|
|
3919
|
-
unique_ptr<Expression> child;
|
|
3920
|
-
//! The comparison type of the child expression with the subquery (in case of ANY, ALL operators)
|
|
3921
|
-
ExpressionType comparison_type;
|
|
3922
|
-
//! The LogicalType of the subquery result. Only used for ANY expressions.
|
|
3923
|
-
LogicalType child_type;
|
|
3924
|
-
//! The target LogicalType of the subquery result (i.e. to which type it should be casted, if child_type <>
|
|
3925
|
-
//! child_target). Only used for ANY expressions.
|
|
3926
|
-
LogicalType child_target;
|
|
3927
|
-
|
|
3928
|
-
public:
|
|
3929
|
-
bool HasSubquery() const override {
|
|
3930
|
-
return true;
|
|
3931
|
-
}
|
|
3932
|
-
bool IsScalar() const override {
|
|
3933
|
-
return false;
|
|
3934
|
-
}
|
|
3935
|
-
bool IsFoldable() const override {
|
|
3936
|
-
return false;
|
|
3937
|
-
}
|
|
3938
|
-
|
|
3939
|
-
string ToString() const override;
|
|
3940
|
-
|
|
3941
|
-
bool Equals(const BaseExpression *other) const override;
|
|
3942
|
-
|
|
3943
|
-
unique_ptr<Expression> Copy() override;
|
|
3944
|
-
};
|
|
3945
|
-
} // namespace duckdb
|
|
3946
|
-
|
|
3947
|
-
//===----------------------------------------------------------------------===//
|
|
3948
|
-
// DuckDB
|
|
3949
|
-
//
|
|
3950
|
-
// duckdb/planner/expression/bound_unnest_expression.hpp
|
|
3951
|
-
//
|
|
3952
|
-
//
|
|
3953
|
-
//===----------------------------------------------------------------------===//
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
namespace duckdb {
|
|
3960
|
-
|
|
3961
|
-
//! Represents a function call that has been bound to a base function
|
|
3962
|
-
class BoundUnnestExpression : public Expression {
|
|
3963
|
-
public:
|
|
3964
|
-
explicit BoundUnnestExpression(LogicalType return_type);
|
|
3965
|
-
|
|
3966
|
-
unique_ptr<Expression> child;
|
|
3967
|
-
|
|
3968
|
-
public:
|
|
3969
|
-
bool IsFoldable() const override;
|
|
3970
|
-
string ToString() const override;
|
|
3971
|
-
|
|
3972
|
-
hash_t Hash() const override;
|
|
3973
|
-
bool Equals(const BaseExpression *other) const override;
|
|
3974
|
-
|
|
3975
|
-
unique_ptr<Expression> Copy() override;
|
|
3976
|
-
};
|
|
3977
|
-
} // namespace duckdb
|
|
3978
|
-
|
|
3979
|
-
//===----------------------------------------------------------------------===//
|
|
3980
|
-
// DuckDB
|
|
3981
|
-
//
|
|
3982
|
-
// duckdb/planner/expression/bound_window_expression.hpp
|
|
3983
|
-
//
|
|
3984
|
-
//
|
|
3985
|
-
//===----------------------------------------------------------------------===//
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
//===----------------------------------------------------------------------===//
|
|
3990
|
-
// DuckDB
|
|
3991
|
-
//
|
|
3992
|
-
// duckdb/parser/expression/window_expression.hpp
|
|
3993
|
-
//
|
|
3994
|
-
//
|
|
3995
|
-
//===----------------------------------------------------------------------===//
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
namespace duckdb {
|
|
4003
|
-
|
|
4004
|
-
enum class WindowBoundary : uint8_t {
|
|
4005
|
-
INVALID = 0,
|
|
4006
|
-
UNBOUNDED_PRECEDING = 1,
|
|
4007
|
-
UNBOUNDED_FOLLOWING = 2,
|
|
4008
|
-
CURRENT_ROW_RANGE = 3,
|
|
4009
|
-
CURRENT_ROW_ROWS = 4,
|
|
4010
|
-
EXPR_PRECEDING_ROWS = 5,
|
|
4011
|
-
EXPR_FOLLOWING_ROWS = 6,
|
|
4012
|
-
EXPR_PRECEDING_RANGE = 7,
|
|
4013
|
-
EXPR_FOLLOWING_RANGE = 8
|
|
4014
|
-
};
|
|
4015
|
-
|
|
4016
|
-
//! The WindowExpression represents a window function in the query. They are a special case of aggregates which is why
|
|
4017
|
-
//! they inherit from them.
|
|
4018
|
-
class WindowExpression : public ParsedExpression {
|
|
4019
|
-
public:
|
|
4020
|
-
WindowExpression(ExpressionType type, string schema_name, const string &function_name);
|
|
4021
|
-
|
|
4022
|
-
//! Schema of the aggregate function
|
|
4023
|
-
string schema;
|
|
4024
|
-
//! Name of the aggregate function
|
|
4025
|
-
string function_name;
|
|
4026
|
-
//! The child expression of the main window aggregate
|
|
4027
|
-
vector<unique_ptr<ParsedExpression>> children;
|
|
4028
|
-
//! The set of expressions to partition by
|
|
4029
|
-
vector<unique_ptr<ParsedExpression>> partitions;
|
|
4030
|
-
//! The set of ordering clauses
|
|
4031
|
-
vector<OrderByNode> orders;
|
|
4032
|
-
//! True to ignore NULL values
|
|
4033
|
-
bool ignore_nulls;
|
|
4034
|
-
//! The window boundaries
|
|
4035
|
-
WindowBoundary start = WindowBoundary::INVALID;
|
|
4036
|
-
WindowBoundary end = WindowBoundary::INVALID;
|
|
4037
|
-
|
|
4038
|
-
unique_ptr<ParsedExpression> start_expr;
|
|
4039
|
-
unique_ptr<ParsedExpression> end_expr;
|
|
4040
|
-
//! Offset and default expressions for WINDOW_LEAD and WINDOW_LAG functions
|
|
4041
|
-
unique_ptr<ParsedExpression> offset_expr;
|
|
4042
|
-
unique_ptr<ParsedExpression> default_expr;
|
|
4043
|
-
|
|
4044
|
-
public:
|
|
4045
|
-
bool IsWindow() const override {
|
|
4046
|
-
return true;
|
|
4047
|
-
}
|
|
4048
|
-
|
|
4049
|
-
//! Get the name of the expression
|
|
4050
|
-
string GetName() const override;
|
|
4051
|
-
//! Convert the Expression to a String
|
|
4052
|
-
string ToString() const override;
|
|
4053
|
-
|
|
4054
|
-
static bool Equals(const WindowExpression *a, const WindowExpression *b);
|
|
4055
|
-
|
|
4056
|
-
unique_ptr<ParsedExpression> Copy() const override;
|
|
4057
|
-
|
|
4058
|
-
void Serialize(Serializer &serializer) override;
|
|
4059
|
-
static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
|
|
4060
|
-
};
|
|
4061
|
-
} // namespace duckdb
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
namespace duckdb {
|
|
4068
|
-
class AggregateFunction;
|
|
4069
|
-
|
|
4070
|
-
class BoundWindowExpression : public Expression {
|
|
4071
|
-
public:
|
|
4072
|
-
BoundWindowExpression(ExpressionType type, LogicalType return_type, unique_ptr<AggregateFunction> aggregate,
|
|
4073
|
-
unique_ptr<FunctionData> bind_info);
|
|
4074
|
-
|
|
4075
|
-
//! The bound aggregate function
|
|
4076
|
-
unique_ptr<AggregateFunction> aggregate;
|
|
4077
|
-
//! The bound function info
|
|
4078
|
-
unique_ptr<FunctionData> bind_info;
|
|
4079
|
-
//! The child expressions of the main window aggregate
|
|
4080
|
-
vector<unique_ptr<Expression>> children;
|
|
4081
|
-
//! The set of expressions to partition by
|
|
4082
|
-
vector<unique_ptr<Expression>> partitions;
|
|
4083
|
-
//! Statistics belonging to the partitions expressions
|
|
4084
|
-
vector<unique_ptr<BaseStatistics>> partitions_stats;
|
|
4085
|
-
//! The set of ordering clauses
|
|
4086
|
-
vector<BoundOrderByNode> orders;
|
|
4087
|
-
//! True to ignore NULL values
|
|
4088
|
-
bool ignore_nulls;
|
|
4089
|
-
//! The window boundaries
|
|
4090
|
-
WindowBoundary start = WindowBoundary::INVALID;
|
|
4091
|
-
WindowBoundary end = WindowBoundary::INVALID;
|
|
4092
|
-
|
|
4093
|
-
unique_ptr<Expression> start_expr;
|
|
4094
|
-
unique_ptr<Expression> end_expr;
|
|
4095
|
-
//! Offset and default expressions for WINDOW_LEAD and WINDOW_LAG functions
|
|
4096
|
-
unique_ptr<Expression> offset_expr;
|
|
4097
|
-
unique_ptr<Expression> default_expr;
|
|
4098
|
-
|
|
4099
|
-
public:
|
|
4100
|
-
bool IsWindow() const override {
|
|
4101
|
-
return true;
|
|
4102
|
-
}
|
|
4103
|
-
bool IsFoldable() const override {
|
|
4104
|
-
return false;
|
|
4105
|
-
}
|
|
4106
|
-
|
|
4107
|
-
string ToString() const override;
|
|
4108
|
-
|
|
4109
|
-
bool KeysAreCompatible(const BoundWindowExpression *other) const;
|
|
4110
|
-
bool Equals(const BaseExpression *other) const override;
|
|
4111
|
-
|
|
4112
|
-
unique_ptr<Expression> Copy() override;
|
|
4113
|
-
};
|
|
4114
|
-
} // namespace duckdb
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
#include <random>
|
|
4119
|
-
namespace duckdb {
|
|
4120
|
-
|
|
4121
|
-
class AdaptiveFilter {
|
|
4122
|
-
public:
|
|
4123
|
-
explicit AdaptiveFilter(const Expression &expr);
|
|
4124
|
-
explicit AdaptiveFilter(TableFilterSet *table_filters);
|
|
4125
|
-
void AdaptRuntimeStatistics(double duration);
|
|
4126
|
-
vector<idx_t> permutation;
|
|
4127
|
-
|
|
4128
|
-
private:
|
|
4129
|
-
//! used for adaptive expression reordering
|
|
4130
|
-
idx_t iteration_count;
|
|
4131
|
-
idx_t swap_idx;
|
|
4132
|
-
idx_t right_random_border;
|
|
4133
|
-
idx_t observe_interval;
|
|
4134
|
-
idx_t execute_interval;
|
|
4135
|
-
double runtime_sum;
|
|
4136
|
-
double prev_mean;
|
|
4137
|
-
bool observe;
|
|
4138
|
-
bool warmup;
|
|
4139
|
-
vector<idx_t> swap_likeliness;
|
|
4140
|
-
std::default_random_engine generator;
|
|
4141
|
-
};
|
|
4142
|
-
} // namespace duckdb
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
namespace duckdb {
|
|
4146
|
-
class ColumnSegment;
|
|
4147
|
-
class LocalTableStorage;
|
|
4148
|
-
class Index;
|
|
4149
|
-
class RowGroup;
|
|
4150
|
-
class UpdateSegment;
|
|
4151
|
-
class TableScanState;
|
|
4152
|
-
class ColumnSegment;
|
|
4153
|
-
class ValiditySegment;
|
|
4154
|
-
class TableFilterSet;
|
|
4155
|
-
|
|
4156
|
-
struct SegmentScanState {
|
|
4157
|
-
virtual ~SegmentScanState() {
|
|
4158
|
-
}
|
|
4159
|
-
};
|
|
4160
|
-
|
|
4161
|
-
struct IndexScanState {
|
|
4162
|
-
virtual ~IndexScanState() {
|
|
4163
|
-
}
|
|
4164
|
-
};
|
|
4165
|
-
|
|
4166
|
-
typedef unordered_map<block_id_t, unique_ptr<BufferHandle>> buffer_handle_set_t;
|
|
4167
|
-
|
|
4168
|
-
struct ColumnScanState {
|
|
4169
|
-
//! The column segment that is currently being scanned
|
|
4170
|
-
ColumnSegment *current;
|
|
4171
|
-
//! The current row index of the scan
|
|
4172
|
-
idx_t row_index;
|
|
4173
|
-
//! The internal row index (i.e. the position of the SegmentScanState)
|
|
4174
|
-
idx_t internal_index;
|
|
4175
|
-
//! Segment scan state
|
|
4176
|
-
unique_ptr<SegmentScanState> scan_state;
|
|
4177
|
-
//! Child states of the vector
|
|
4178
|
-
vector<ColumnScanState> child_states;
|
|
4179
|
-
//! Whether or not InitializeState has been called for this segment
|
|
4180
|
-
bool initialized = false;
|
|
4181
|
-
//! If this segment has already been checked for skipping purposes
|
|
4182
|
-
bool segment_checked = false;
|
|
4183
|
-
|
|
4184
|
-
public:
|
|
4185
|
-
//! Move the scan state forward by "count" rows (including all child states)
|
|
4186
|
-
void Next(idx_t count);
|
|
4187
|
-
//! Move ONLY this state forward by "count" rows (i.e. not the child states)
|
|
4188
|
-
void NextInternal(idx_t count);
|
|
4189
|
-
//! Move the scan state forward by STANDARD_VECTOR_SIZE rows
|
|
4190
|
-
void NextVector();
|
|
4191
|
-
};
|
|
4192
|
-
|
|
4193
|
-
struct ColumnFetchState {
|
|
4194
|
-
//! The set of pinned block handles for this set of fetches
|
|
4195
|
-
buffer_handle_set_t handles;
|
|
4196
|
-
//! Any child states of the fetch
|
|
4197
|
-
vector<unique_ptr<ColumnFetchState>> child_states;
|
|
4198
|
-
};
|
|
4199
|
-
|
|
4200
|
-
struct LocalScanState {
|
|
4201
|
-
~LocalScanState();
|
|
4202
|
-
|
|
4203
|
-
void SetStorage(LocalTableStorage *storage);
|
|
4204
|
-
LocalTableStorage *GetStorage() {
|
|
4205
|
-
return storage;
|
|
4206
|
-
}
|
|
4207
|
-
|
|
4208
|
-
idx_t chunk_index;
|
|
4209
|
-
idx_t max_index;
|
|
4210
|
-
idx_t last_chunk_count;
|
|
4211
|
-
TableFilterSet *table_filters;
|
|
4212
|
-
|
|
4213
|
-
private:
|
|
4214
|
-
LocalTableStorage *storage = nullptr;
|
|
4215
|
-
};
|
|
4216
|
-
|
|
4217
|
-
class RowGroupScanState {
|
|
4218
|
-
public:
|
|
4219
|
-
RowGroupScanState(TableScanState &parent_p) : parent(parent_p), vector_index(0), max_row(0) {
|
|
4220
|
-
}
|
|
4221
|
-
|
|
4222
|
-
//! The parent scan state
|
|
4223
|
-
TableScanState &parent;
|
|
4224
|
-
//! The current row_group we are scanning
|
|
4225
|
-
RowGroup *row_group;
|
|
4226
|
-
//! The vector index within the row_group
|
|
4227
|
-
idx_t vector_index;
|
|
4228
|
-
//! The maximum row index of this row_group scan
|
|
4229
|
-
idx_t max_row;
|
|
4230
|
-
//! Child column scans
|
|
4231
|
-
unique_ptr<ColumnScanState[]> column_scans;
|
|
4232
|
-
|
|
4233
|
-
public:
|
|
4234
|
-
//! Move to the next vector, skipping past the current one
|
|
4235
|
-
void NextVector();
|
|
4236
|
-
};
|
|
4237
|
-
|
|
4238
|
-
class TableScanState {
|
|
4239
|
-
public:
|
|
4240
|
-
TableScanState() : row_group_scan_state(*this), max_row(0) {};
|
|
4241
|
-
|
|
4242
|
-
//! The row_group scan state
|
|
4243
|
-
RowGroupScanState row_group_scan_state;
|
|
4244
|
-
//! The total maximum row index
|
|
4245
|
-
idx_t max_row;
|
|
4246
|
-
//! The column identifiers of the scan
|
|
4247
|
-
vector<column_t> column_ids;
|
|
4248
|
-
//! The table filters (if any)
|
|
4249
|
-
TableFilterSet *table_filters = nullptr;
|
|
4250
|
-
//! Adaptive filter info (if any)
|
|
4251
|
-
unique_ptr<AdaptiveFilter> adaptive_filter;
|
|
4252
|
-
//! Transaction-local scan state
|
|
4253
|
-
LocalScanState local_state;
|
|
4254
|
-
|
|
4255
|
-
public:
|
|
4256
|
-
//! Move to the next vector
|
|
4257
|
-
void NextVector();
|
|
4258
|
-
};
|
|
4259
|
-
|
|
4260
|
-
class CreateIndexScanState : public TableScanState {
|
|
4261
|
-
public:
|
|
4262
|
-
vector<unique_ptr<StorageLockKey>> locks;
|
|
4263
|
-
unique_lock<mutex> append_lock;
|
|
4264
|
-
unique_lock<mutex> delete_lock;
|
|
4265
|
-
};
|
|
4266
|
-
|
|
4267
|
-
} // namespace duckdb
|
|
4268
1525
|
|
|
4269
1526
|
//===----------------------------------------------------------------------===//
|
|
4270
1527
|
// DuckDB
|
|
@@ -4814,6 +2071,19 @@ CatalogEntryLookup Catalog::LookupEntry(ClientContext &context, CatalogType type
|
|
|
4814
2071
|
return {nullptr, nullptr};
|
|
4815
2072
|
}
|
|
4816
2073
|
|
|
2074
|
+
CatalogEntry *Catalog::GetEntry(ClientContext &context, const string &schema, const string &name) {
|
|
2075
|
+
vector<CatalogType> entry_types {CatalogType::TABLE_ENTRY, CatalogType::SEQUENCE_ENTRY};
|
|
2076
|
+
|
|
2077
|
+
for (auto entry_type : entry_types) {
|
|
2078
|
+
CatalogEntry *result = GetEntry(context, entry_type, schema, name, true);
|
|
2079
|
+
if (result != nullptr) {
|
|
2080
|
+
return result;
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2084
|
+
throw CatalogException("CatalogElement \"%s.%s\" does not exist!", schema, name);
|
|
2085
|
+
}
|
|
2086
|
+
|
|
4817
2087
|
CatalogEntry *Catalog::GetEntry(ClientContext &context, CatalogType type, const string &schema_name, const string &name,
|
|
4818
2088
|
bool if_exists, QueryErrorContext error_context) {
|
|
4819
2089
|
return LookupEntry(context, type, schema_name, name, if_exists, error_context).entry;
|
|
@@ -5779,110 +3049,6 @@ private:
|
|
|
5779
3049
|
|
|
5780
3050
|
} // namespace duckdb
|
|
5781
3051
|
|
|
5782
|
-
//===----------------------------------------------------------------------===//
|
|
5783
|
-
// DuckDB
|
|
5784
|
-
//
|
|
5785
|
-
// duckdb/transaction/local_storage.hpp
|
|
5786
|
-
//
|
|
5787
|
-
//
|
|
5788
|
-
//===----------------------------------------------------------------------===//
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
namespace duckdb {
|
|
5796
|
-
class DataTable;
|
|
5797
|
-
class WriteAheadLog;
|
|
5798
|
-
struct TableAppendState;
|
|
5799
|
-
|
|
5800
|
-
class LocalTableStorage {
|
|
5801
|
-
public:
|
|
5802
|
-
explicit LocalTableStorage(DataTable &table);
|
|
5803
|
-
~LocalTableStorage();
|
|
5804
|
-
|
|
5805
|
-
DataTable &table;
|
|
5806
|
-
//! The main chunk collection holding the data
|
|
5807
|
-
ChunkCollection collection;
|
|
5808
|
-
//! The set of unique indexes
|
|
5809
|
-
vector<unique_ptr<Index>> indexes;
|
|
5810
|
-
//! The set of deleted entries
|
|
5811
|
-
unordered_map<idx_t, unique_ptr<bool[]>> deleted_entries;
|
|
5812
|
-
//! The number of deleted rows
|
|
5813
|
-
idx_t deleted_rows;
|
|
5814
|
-
//! The number of active scans
|
|
5815
|
-
atomic<idx_t> active_scans;
|
|
5816
|
-
|
|
5817
|
-
public:
|
|
5818
|
-
void InitializeScan(LocalScanState &state, TableFilterSet *table_filters = nullptr);
|
|
5819
|
-
idx_t EstimatedSize();
|
|
5820
|
-
|
|
5821
|
-
void Clear();
|
|
5822
|
-
};
|
|
5823
|
-
|
|
5824
|
-
//! The LocalStorage class holds appends that have not been committed yet
|
|
5825
|
-
class LocalStorage {
|
|
5826
|
-
public:
|
|
5827
|
-
struct CommitState {
|
|
5828
|
-
unordered_map<DataTable *, unique_ptr<TableAppendState>> append_states;
|
|
5829
|
-
};
|
|
5830
|
-
|
|
5831
|
-
public:
|
|
5832
|
-
explicit LocalStorage(Transaction &transaction) : transaction(transaction) {
|
|
5833
|
-
}
|
|
5834
|
-
|
|
5835
|
-
//! Initialize a scan of the local storage
|
|
5836
|
-
void InitializeScan(DataTable *table, LocalScanState &state, TableFilterSet *table_filters);
|
|
5837
|
-
//! Scan
|
|
5838
|
-
void Scan(LocalScanState &state, const vector<column_t> &column_ids, DataChunk &result);
|
|
5839
|
-
|
|
5840
|
-
//! Append a chunk to the local storage
|
|
5841
|
-
void Append(DataTable *table, DataChunk &chunk);
|
|
5842
|
-
//! Delete a set of rows from the local storage
|
|
5843
|
-
idx_t Delete(DataTable *table, Vector &row_ids, idx_t count);
|
|
5844
|
-
//! Update a set of rows in the local storage
|
|
5845
|
-
void Update(DataTable *table, Vector &row_ids, const vector<column_t> &column_ids, DataChunk &data);
|
|
5846
|
-
|
|
5847
|
-
//! Commits the local storage, writing it to the WAL and completing the commit
|
|
5848
|
-
void Commit(LocalStorage::CommitState &commit_state, Transaction &transaction, WriteAheadLog *log,
|
|
5849
|
-
transaction_t commit_id);
|
|
5850
|
-
|
|
5851
|
-
bool ChangesMade() noexcept {
|
|
5852
|
-
return table_storage.size() > 0;
|
|
5853
|
-
}
|
|
5854
|
-
idx_t EstimatedSize();
|
|
5855
|
-
|
|
5856
|
-
bool Find(DataTable *table) {
|
|
5857
|
-
return table_storage.find(table) != table_storage.end();
|
|
5858
|
-
}
|
|
5859
|
-
|
|
5860
|
-
idx_t AddedRows(DataTable *table) {
|
|
5861
|
-
auto entry = table_storage.find(table);
|
|
5862
|
-
if (entry == table_storage.end()) {
|
|
5863
|
-
return 0;
|
|
5864
|
-
}
|
|
5865
|
-
return entry->second->collection.Count() - entry->second->deleted_rows;
|
|
5866
|
-
}
|
|
5867
|
-
|
|
5868
|
-
void AddColumn(DataTable *old_dt, DataTable *new_dt, ColumnDefinition &new_column, Expression *default_value);
|
|
5869
|
-
void ChangeType(DataTable *old_dt, DataTable *new_dt, idx_t changed_idx, const LogicalType &target_type,
|
|
5870
|
-
const vector<column_t> &bound_columns, Expression &cast_expr);
|
|
5871
|
-
|
|
5872
|
-
private:
|
|
5873
|
-
LocalTableStorage *GetStorage(DataTable *table);
|
|
5874
|
-
|
|
5875
|
-
template <class T>
|
|
5876
|
-
bool ScanTableStorage(DataTable &table, LocalTableStorage &storage, T &&fun);
|
|
5877
|
-
|
|
5878
|
-
private:
|
|
5879
|
-
Transaction &transaction;
|
|
5880
|
-
unordered_map<DataTable *, unique_ptr<LocalTableStorage>> table_storage;
|
|
5881
|
-
|
|
5882
|
-
void Flush(DataTable &table, LocalTableStorage &storage);
|
|
5883
|
-
};
|
|
5884
|
-
|
|
5885
|
-
} // namespace duckdb
|
|
5886
3052
|
|
|
5887
3053
|
|
|
5888
3054
|
|
|
@@ -6328,216 +3494,6 @@ public:
|
|
|
6328
3494
|
|
|
6329
3495
|
|
|
6330
3496
|
|
|
6331
|
-
//===----------------------------------------------------------------------===//
|
|
6332
|
-
// DuckDB
|
|
6333
|
-
//
|
|
6334
|
-
// duckdb/transaction/transaction.hpp
|
|
6335
|
-
//
|
|
6336
|
-
//
|
|
6337
|
-
//===----------------------------------------------------------------------===//
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
//===----------------------------------------------------------------------===//
|
|
6345
|
-
// DuckDB
|
|
6346
|
-
//
|
|
6347
|
-
// duckdb/transaction/undo_buffer.hpp
|
|
6348
|
-
//
|
|
6349
|
-
//
|
|
6350
|
-
//===----------------------------------------------------------------------===//
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
//===----------------------------------------------------------------------===//
|
|
6356
|
-
// DuckDB
|
|
6357
|
-
//
|
|
6358
|
-
// duckdb/common/enums/undo_flags.hpp
|
|
6359
|
-
//
|
|
6360
|
-
//
|
|
6361
|
-
//===----------------------------------------------------------------------===//
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
|
|
6367
|
-
namespace duckdb {
|
|
6368
|
-
|
|
6369
|
-
enum class UndoFlags : uint32_t { // far to big but aligned (TM)
|
|
6370
|
-
EMPTY_ENTRY = 0,
|
|
6371
|
-
CATALOG_ENTRY = 1,
|
|
6372
|
-
INSERT_TUPLE = 2,
|
|
6373
|
-
DELETE_TUPLE = 3,
|
|
6374
|
-
UPDATE_TUPLE = 4
|
|
6375
|
-
};
|
|
6376
|
-
|
|
6377
|
-
} // namespace duckdb
|
|
6378
|
-
|
|
6379
|
-
|
|
6380
|
-
namespace duckdb {
|
|
6381
|
-
|
|
6382
|
-
class WriteAheadLog;
|
|
6383
|
-
|
|
6384
|
-
struct UndoChunk {
|
|
6385
|
-
explicit UndoChunk(idx_t size);
|
|
6386
|
-
~UndoChunk();
|
|
6387
|
-
|
|
6388
|
-
data_ptr_t WriteEntry(UndoFlags type, uint32_t len);
|
|
6389
|
-
|
|
6390
|
-
unique_ptr<data_t[]> data;
|
|
6391
|
-
idx_t current_position;
|
|
6392
|
-
idx_t maximum_size;
|
|
6393
|
-
unique_ptr<UndoChunk> next;
|
|
6394
|
-
UndoChunk *prev;
|
|
6395
|
-
};
|
|
6396
|
-
|
|
6397
|
-
//! The undo buffer of a transaction is used to hold previous versions of tuples
|
|
6398
|
-
//! that might be required in the future (because of rollbacks or previous
|
|
6399
|
-
//! transactions accessing them)
|
|
6400
|
-
class UndoBuffer {
|
|
6401
|
-
public:
|
|
6402
|
-
struct IteratorState {
|
|
6403
|
-
UndoChunk *current;
|
|
6404
|
-
data_ptr_t start;
|
|
6405
|
-
data_ptr_t end;
|
|
6406
|
-
};
|
|
6407
|
-
|
|
6408
|
-
public:
|
|
6409
|
-
UndoBuffer();
|
|
6410
|
-
|
|
6411
|
-
//! Reserve space for an entry of the specified type and length in the undo
|
|
6412
|
-
//! buffer
|
|
6413
|
-
data_ptr_t CreateEntry(UndoFlags type, idx_t len);
|
|
6414
|
-
|
|
6415
|
-
bool ChangesMade();
|
|
6416
|
-
idx_t EstimatedSize();
|
|
6417
|
-
|
|
6418
|
-
//! Cleanup the undo buffer
|
|
6419
|
-
void Cleanup();
|
|
6420
|
-
//! Commit the changes made in the UndoBuffer: should be called on commit
|
|
6421
|
-
void Commit(UndoBuffer::IteratorState &iterator_state, WriteAheadLog *log, transaction_t commit_id);
|
|
6422
|
-
//! Revert committed changes made in the UndoBuffer up until the currently committed state
|
|
6423
|
-
void RevertCommit(UndoBuffer::IteratorState &iterator_state, transaction_t transaction_id);
|
|
6424
|
-
//! Rollback the changes made in this UndoBuffer: should be called on
|
|
6425
|
-
//! rollback
|
|
6426
|
-
void Rollback() noexcept;
|
|
6427
|
-
|
|
6428
|
-
private:
|
|
6429
|
-
unique_ptr<UndoChunk> head;
|
|
6430
|
-
UndoChunk *tail;
|
|
6431
|
-
|
|
6432
|
-
private:
|
|
6433
|
-
template <class T>
|
|
6434
|
-
void IterateEntries(UndoBuffer::IteratorState &state, T &&callback);
|
|
6435
|
-
template <class T>
|
|
6436
|
-
void IterateEntries(UndoBuffer::IteratorState &state, UndoBuffer::IteratorState &end_state, T &&callback);
|
|
6437
|
-
template <class T>
|
|
6438
|
-
void ReverseIterateEntries(T &&callback);
|
|
6439
|
-
};
|
|
6440
|
-
|
|
6441
|
-
} // namespace duckdb
|
|
6442
|
-
|
|
6443
|
-
|
|
6444
|
-
|
|
6445
|
-
|
|
6446
|
-
namespace duckdb {
|
|
6447
|
-
class SequenceCatalogEntry;
|
|
6448
|
-
|
|
6449
|
-
class ColumnData;
|
|
6450
|
-
class ClientContext;
|
|
6451
|
-
class CatalogEntry;
|
|
6452
|
-
class DataTable;
|
|
6453
|
-
class DatabaseInstance;
|
|
6454
|
-
class WriteAheadLog;
|
|
6455
|
-
|
|
6456
|
-
class ChunkVectorInfo;
|
|
6457
|
-
|
|
6458
|
-
struct DeleteInfo;
|
|
6459
|
-
struct UpdateInfo;
|
|
6460
|
-
|
|
6461
|
-
//! The transaction object holds information about a currently running or past
|
|
6462
|
-
//! transaction
|
|
6463
|
-
|
|
6464
|
-
class Transaction {
|
|
6465
|
-
public:
|
|
6466
|
-
Transaction(weak_ptr<ClientContext> context, transaction_t start_time, transaction_t transaction_id,
|
|
6467
|
-
timestamp_t start_timestamp, idx_t catalog_version)
|
|
6468
|
-
: context(move(context)), start_time(start_time), transaction_id(transaction_id), commit_id(0),
|
|
6469
|
-
highest_active_query(0), active_query(MAXIMUM_QUERY_ID), start_timestamp(start_timestamp),
|
|
6470
|
-
catalog_version(catalog_version), storage(*this), is_invalidated(false) {
|
|
6471
|
-
}
|
|
6472
|
-
|
|
6473
|
-
weak_ptr<ClientContext> context;
|
|
6474
|
-
//! The start timestamp of this transaction
|
|
6475
|
-
transaction_t start_time;
|
|
6476
|
-
//! The transaction id of this transaction
|
|
6477
|
-
transaction_t transaction_id;
|
|
6478
|
-
//! The commit id of this transaction, if it has successfully been committed
|
|
6479
|
-
transaction_t commit_id;
|
|
6480
|
-
//! Highest active query when the transaction finished, used for cleaning up
|
|
6481
|
-
transaction_t highest_active_query;
|
|
6482
|
-
//! The current active query for the transaction. Set to MAXIMUM_QUERY_ID if
|
|
6483
|
-
//! no query is active.
|
|
6484
|
-
atomic<transaction_t> active_query;
|
|
6485
|
-
//! The timestamp when the transaction started
|
|
6486
|
-
timestamp_t start_timestamp;
|
|
6487
|
-
//! The catalog version when the transaction was started
|
|
6488
|
-
idx_t catalog_version;
|
|
6489
|
-
//! The set of uncommitted appends for the transaction
|
|
6490
|
-
LocalStorage storage;
|
|
6491
|
-
//! Map of all sequences that were used during the transaction and the value they had in this transaction
|
|
6492
|
-
unordered_map<SequenceCatalogEntry *, SequenceValue> sequence_usage;
|
|
6493
|
-
//! Whether or not the transaction has been invalidated
|
|
6494
|
-
bool is_invalidated;
|
|
6495
|
-
|
|
6496
|
-
public:
|
|
6497
|
-
static Transaction &GetTransaction(ClientContext &context);
|
|
6498
|
-
|
|
6499
|
-
void PushCatalogEntry(CatalogEntry *entry, data_ptr_t extra_data = nullptr, idx_t extra_data_size = 0);
|
|
6500
|
-
|
|
6501
|
-
//! Commit the current transaction with the given commit identifier. Returns an error message if the transaction
|
|
6502
|
-
//! commit failed, or an empty string if the commit was sucessful
|
|
6503
|
-
string Commit(DatabaseInstance &db, transaction_t commit_id, bool checkpoint) noexcept;
|
|
6504
|
-
//! Returns whether or not a commit of this transaction should trigger an automatic checkpoint
|
|
6505
|
-
bool AutomaticCheckpoint(DatabaseInstance &db);
|
|
6506
|
-
|
|
6507
|
-
//! Rollback
|
|
6508
|
-
void Rollback() noexcept {
|
|
6509
|
-
undo_buffer.Rollback();
|
|
6510
|
-
}
|
|
6511
|
-
//! Cleanup the undo buffer
|
|
6512
|
-
void Cleanup() {
|
|
6513
|
-
undo_buffer.Cleanup();
|
|
6514
|
-
}
|
|
6515
|
-
|
|
6516
|
-
void Invalidate() {
|
|
6517
|
-
is_invalidated = true;
|
|
6518
|
-
}
|
|
6519
|
-
bool IsInvalidated() {
|
|
6520
|
-
return is_invalidated;
|
|
6521
|
-
}
|
|
6522
|
-
bool ChangesMade();
|
|
6523
|
-
|
|
6524
|
-
timestamp_t GetCurrentTransactionStartTimestamp() {
|
|
6525
|
-
return start_timestamp;
|
|
6526
|
-
}
|
|
6527
|
-
|
|
6528
|
-
void PushDelete(DataTable *table, ChunkVectorInfo *vinfo, row_t rows[], idx_t count, idx_t base_row);
|
|
6529
|
-
void PushAppend(DataTable *table, idx_t row_start, idx_t row_count);
|
|
6530
|
-
UpdateInfo *CreateUpdateInfo(idx_t type_size, idx_t entries);
|
|
6531
|
-
|
|
6532
|
-
private:
|
|
6533
|
-
//! The undo buffer is used to store old versions of rows that are updated
|
|
6534
|
-
//! or deleted
|
|
6535
|
-
UndoBuffer undo_buffer;
|
|
6536
|
-
|
|
6537
|
-
Transaction(const Transaction &) = delete;
|
|
6538
|
-
};
|
|
6539
|
-
|
|
6540
|
-
} // namespace duckdb
|
|
6541
3497
|
|
|
6542
3498
|
|
|
6543
3499
|
#include <algorithm>
|
|
@@ -6721,10 +3677,16 @@ void SchemaCatalogEntry::DropEntry(ClientContext &context, DropInfo *info) {
|
|
|
6721
3677
|
|
|
6722
3678
|
void SchemaCatalogEntry::Alter(ClientContext &context, AlterInfo *info) {
|
|
6723
3679
|
CatalogType type = info->GetCatalogType();
|
|
6724
|
-
string name = info->name;
|
|
6725
3680
|
auto &set = GetCatalogSet(type);
|
|
6726
|
-
if (
|
|
6727
|
-
|
|
3681
|
+
if (info->type == AlterType::CHANGE_OWNERSHIP) {
|
|
3682
|
+
if (!set.AlterOwnership(context, (ChangeOwnershipInfo *)info)) {
|
|
3683
|
+
throw CatalogException("Couldn't change ownership!");
|
|
3684
|
+
}
|
|
3685
|
+
} else {
|
|
3686
|
+
string name = info->name;
|
|
3687
|
+
if (!set.AlterEntry(context, name, info)) {
|
|
3688
|
+
throw CatalogException("Entry with name \"%s\" does not exist!", name);
|
|
3689
|
+
}
|
|
6728
3690
|
}
|
|
6729
3691
|
}
|
|
6730
3692
|
|
|
@@ -6791,6 +3753,7 @@ CatalogSet &SchemaCatalogEntry::GetCatalogSet(CatalogType type) {
|
|
|
6791
3753
|
|
|
6792
3754
|
|
|
6793
3755
|
|
|
3756
|
+
|
|
6794
3757
|
#include <algorithm>
|
|
6795
3758
|
#include <sstream>
|
|
6796
3759
|
|
|
@@ -6840,7 +3803,6 @@ string SequenceCatalogEntry::ToSQL() {
|
|
|
6840
3803
|
ss << " " << (cycle ? "CYCLE" : "NO CYCLE") << ";";
|
|
6841
3804
|
return ss.str();
|
|
6842
3805
|
}
|
|
6843
|
-
|
|
6844
3806
|
} // namespace duckdb
|
|
6845
3807
|
|
|
6846
3808
|
|
|
@@ -8513,14 +5475,15 @@ string TypeCatalogEntry::ToSQL() {
|
|
|
8513
5475
|
std::stringstream ss;
|
|
8514
5476
|
switch (user_type->id()) {
|
|
8515
5477
|
case (LogicalTypeId::ENUM): {
|
|
8516
|
-
|
|
5478
|
+
Vector values_insert_order(EnumType::GetValuesInsertOrder(*user_type));
|
|
5479
|
+
idx_t size = EnumType::GetSize(*user_type);
|
|
8517
5480
|
ss << "CREATE TYPE ";
|
|
8518
5481
|
ss << name;
|
|
8519
5482
|
ss << " AS ENUM ( ";
|
|
8520
5483
|
|
|
8521
|
-
for (idx_t i = 0; i <
|
|
8522
|
-
ss << "'" << values_insert_order
|
|
8523
|
-
if (i !=
|
|
5484
|
+
for (idx_t i = 0; i < size; i++) {
|
|
5485
|
+
ss << "'" << values_insert_order.GetValue(i).ToString() << "'";
|
|
5486
|
+
if (i != size - 1) {
|
|
8524
5487
|
ss << ", ";
|
|
8525
5488
|
}
|
|
8526
5489
|
}
|
|
@@ -8838,9 +5801,74 @@ private:
|
|
|
8838
5801
|
|
|
8839
5802
|
|
|
8840
5803
|
|
|
5804
|
+
//===----------------------------------------------------------------------===//
|
|
5805
|
+
// DuckDB
|
|
5806
|
+
//
|
|
5807
|
+
// duckdb/parser/expression/constant_expression.hpp
|
|
5808
|
+
//
|
|
5809
|
+
//
|
|
5810
|
+
//===----------------------------------------------------------------------===//
|
|
5811
|
+
|
|
5812
|
+
|
|
5813
|
+
|
|
5814
|
+
|
|
5815
|
+
|
|
5816
|
+
|
|
5817
|
+
namespace duckdb {
|
|
5818
|
+
|
|
5819
|
+
//! ConstantExpression represents a constant value in the query
|
|
5820
|
+
class ConstantExpression : public ParsedExpression {
|
|
5821
|
+
public:
|
|
5822
|
+
explicit ConstantExpression(Value val);
|
|
5823
|
+
|
|
5824
|
+
//! The constant value referenced
|
|
5825
|
+
Value value;
|
|
5826
|
+
|
|
5827
|
+
public:
|
|
5828
|
+
string ToString() const override;
|
|
5829
|
+
|
|
5830
|
+
static bool Equals(const ConstantExpression *a, const ConstantExpression *b);
|
|
5831
|
+
hash_t Hash() const override;
|
|
5832
|
+
|
|
5833
|
+
unique_ptr<ParsedExpression> Copy() const override;
|
|
5834
|
+
|
|
5835
|
+
void Serialize(Serializer &serializer) override;
|
|
5836
|
+
static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
|
|
5837
|
+
};
|
|
5838
|
+
|
|
5839
|
+
} // namespace duckdb
|
|
5840
|
+
|
|
8841
5841
|
|
|
8842
5842
|
namespace duckdb {
|
|
8843
5843
|
|
|
5844
|
+
//! Class responsible to keep track of state when removing entries from the catalog.
|
|
5845
|
+
//! When deleting, many types of errors can be thrown, since we want to avoid try/catch blocks
|
|
5846
|
+
//! this class makes sure that whatever elements were modified are returned to a correct state
|
|
5847
|
+
//! when exceptions are thrown.
|
|
5848
|
+
//! The idea here is to use RAII (Resource acquisition is initialization) to mimic a try/catch/finally block.
|
|
5849
|
+
//! If any exception is raised when this object exists, then its destructor will be called
|
|
5850
|
+
//! and the entry will return to its previous state during deconstruction.
|
|
5851
|
+
class EntryDropper {
|
|
5852
|
+
public:
|
|
5853
|
+
//! Both constructor and destructor are privates because they should only be called by DropEntryDependencies
|
|
5854
|
+
explicit EntryDropper(CatalogSet &catalog_set, idx_t entry_index)
|
|
5855
|
+
: catalog_set(catalog_set), entry_index(entry_index) {
|
|
5856
|
+
old_deleted = catalog_set.entries[entry_index].get()->deleted;
|
|
5857
|
+
}
|
|
5858
|
+
|
|
5859
|
+
~EntryDropper() {
|
|
5860
|
+
catalog_set.entries[entry_index].get()->deleted = old_deleted;
|
|
5861
|
+
}
|
|
5862
|
+
|
|
5863
|
+
private:
|
|
5864
|
+
//! The current catalog_set
|
|
5865
|
+
CatalogSet &catalog_set;
|
|
5866
|
+
//! Keeps track of the state of the entry before starting the delete
|
|
5867
|
+
bool old_deleted;
|
|
5868
|
+
//! Index of entry to be deleted
|
|
5869
|
+
idx_t entry_index;
|
|
5870
|
+
};
|
|
5871
|
+
|
|
8844
5872
|
CatalogSet::CatalogSet(Catalog &catalog, unique_ptr<DefaultGenerator> defaults)
|
|
8845
5873
|
: catalog(catalog), defaults(move(defaults)) {
|
|
8846
5874
|
}
|
|
@@ -8930,6 +5958,23 @@ bool CatalogSet::GetEntryInternal(ClientContext &context, const string &name, id
|
|
|
8930
5958
|
return GetEntryInternal(context, entry_index, catalog_entry);
|
|
8931
5959
|
}
|
|
8932
5960
|
|
|
5961
|
+
bool CatalogSet::AlterOwnership(ClientContext &context, ChangeOwnershipInfo *info) {
|
|
5962
|
+
idx_t entry_index;
|
|
5963
|
+
CatalogEntry *entry;
|
|
5964
|
+
if (!GetEntryInternal(context, info->name, entry_index, entry)) {
|
|
5965
|
+
return false;
|
|
5966
|
+
}
|
|
5967
|
+
|
|
5968
|
+
auto owner_entry = catalog.GetEntry(context, info->owner_schema, info->owner_name);
|
|
5969
|
+
if (!owner_entry) {
|
|
5970
|
+
return false;
|
|
5971
|
+
}
|
|
5972
|
+
|
|
5973
|
+
catalog.dependency_manager->AddOwnership(context, owner_entry, entry);
|
|
5974
|
+
|
|
5975
|
+
return true;
|
|
5976
|
+
}
|
|
5977
|
+
|
|
8933
5978
|
bool CatalogSet::AlterEntry(ClientContext &context, const string &name, AlterInfo *alter_info) {
|
|
8934
5979
|
auto &transaction = Transaction::GetTransaction(context);
|
|
8935
5980
|
// lock the catalog for writing
|
|
@@ -8957,6 +6002,7 @@ bool CatalogSet::AlterEntry(ClientContext &context, const string &name, AlterInf
|
|
|
8957
6002
|
// alter failed, but did not result in an error
|
|
8958
6003
|
return true;
|
|
8959
6004
|
}
|
|
6005
|
+
|
|
8960
6006
|
if (value->name != original_name) {
|
|
8961
6007
|
auto mapping_value = GetMapping(context, value->name);
|
|
8962
6008
|
if (mapping_value && !mapping_value->deleted) {
|
|
@@ -8990,16 +6036,26 @@ bool CatalogSet::AlterEntry(ClientContext &context, const string &name, AlterInf
|
|
|
8990
6036
|
return true;
|
|
8991
6037
|
}
|
|
8992
6038
|
|
|
8993
|
-
void CatalogSet::
|
|
8994
|
-
|
|
8995
|
-
|
|
6039
|
+
void CatalogSet::DropEntryDependencies(ClientContext &context, idx_t entry_index, CatalogEntry &entry, bool cascade) {
|
|
6040
|
+
|
|
6041
|
+
// Stores the deleted value of the entry before starting the process
|
|
6042
|
+
EntryDropper dropper(*this, entry_index);
|
|
6043
|
+
|
|
6044
|
+
// To correctly delete the object and its dependencies, it temporarily is set to deleted.
|
|
6045
|
+
entries[entry_index].get()->deleted = true;
|
|
6046
|
+
|
|
8996
6047
|
// check any dependencies of this object
|
|
8997
|
-
entry.catalog->dependency_manager->DropObject(context, &entry, cascade
|
|
6048
|
+
entry.catalog->dependency_manager->DropObject(context, &entry, cascade);
|
|
8998
6049
|
|
|
8999
|
-
//
|
|
9000
|
-
|
|
9001
|
-
|
|
9002
|
-
|
|
6050
|
+
// dropper destructor is called here
|
|
6051
|
+
// the destructor makes sure to return the value to the previous state
|
|
6052
|
+
// dropper.~EntryDropper()
|
|
6053
|
+
}
|
|
6054
|
+
|
|
6055
|
+
void CatalogSet::DropEntryInternal(ClientContext &context, idx_t entry_index, CatalogEntry &entry, bool cascade) {
|
|
6056
|
+
auto &transaction = Transaction::GetTransaction(context);
|
|
6057
|
+
|
|
6058
|
+
DropEntryDependencies(context, entry_index, entry, cascade);
|
|
9003
6059
|
|
|
9004
6060
|
// create a new entry and replace the currently stored one
|
|
9005
6061
|
// set the timestamp to the timestamp of the current transaction
|
|
@@ -9030,9 +6086,7 @@ bool CatalogSet::DropEntry(ClientContext &context, const string &name, bool casc
|
|
|
9030
6086
|
throw CatalogException("Cannot drop entry \"%s\" because it is an internal system entry", entry->name);
|
|
9031
6087
|
}
|
|
9032
6088
|
|
|
9033
|
-
|
|
9034
|
-
set_lock_map_t lock_set;
|
|
9035
|
-
DropEntryInternal(context, entry_index, *entry, cascade, lock_set);
|
|
6089
|
+
DropEntryInternal(context, entry_index, *entry, cascade);
|
|
9036
6090
|
return true;
|
|
9037
6091
|
}
|
|
9038
6092
|
|
|
@@ -9245,9 +6299,10 @@ void CatalogSet::AdjustDependency(CatalogEntry *entry, TableCatalogEntry *table,
|
|
|
9245
6299
|
}
|
|
9246
6300
|
}
|
|
9247
6301
|
}
|
|
6302
|
+
|
|
9248
6303
|
void CatalogSet::AdjustTableDependencies(CatalogEntry *entry) {
|
|
9249
6304
|
if (entry->type == CatalogType::TABLE_ENTRY && entry->parent->type == CatalogType::TABLE_ENTRY) {
|
|
9250
|
-
// If
|
|
6305
|
+
// If it's a table entry we have to check for possibly removing or adding user type dependencies
|
|
9251
6306
|
auto old_table = (TableCatalogEntry *)entry->parent;
|
|
9252
6307
|
auto new_table = (TableCatalogEntry *)entry;
|
|
9253
6308
|
|
|
@@ -9354,7 +6409,6 @@ void CatalogSet::Scan(const std::function<void(CatalogEntry *)> &callback) {
|
|
|
9354
6409
|
}
|
|
9355
6410
|
}
|
|
9356
6411
|
}
|
|
9357
|
-
|
|
9358
6412
|
} // namespace duckdb
|
|
9359
6413
|
|
|
9360
6414
|
//===----------------------------------------------------------------------===//
|
|
@@ -9739,6 +6793,7 @@ vector<string> DefaultViewGenerator::GetDefaultEntries() {
|
|
|
9739
6793
|
|
|
9740
6794
|
|
|
9741
6795
|
|
|
6796
|
+
|
|
9742
6797
|
namespace duckdb {
|
|
9743
6798
|
|
|
9744
6799
|
DependencyManager::DependencyManager(Catalog &catalog) : catalog(catalog) {
|
|
@@ -9766,8 +6821,7 @@ void DependencyManager::AddObject(ClientContext &context, CatalogEntry *object,
|
|
|
9766
6821
|
dependencies_map[object] = dependencies;
|
|
9767
6822
|
}
|
|
9768
6823
|
|
|
9769
|
-
void DependencyManager::DropObject(ClientContext &context, CatalogEntry *object, bool cascade
|
|
9770
|
-
set_lock_map_t &lock_set) {
|
|
6824
|
+
void DependencyManager::DropObject(ClientContext &context, CatalogEntry *object, bool cascade) {
|
|
9771
6825
|
D_ASSERT(dependents_map.find(object) != dependents_map.end());
|
|
9772
6826
|
|
|
9773
6827
|
// first check the objects that depend on this object
|
|
@@ -9787,9 +6841,10 @@ void DependencyManager::DropObject(ClientContext &context, CatalogEntry *object,
|
|
|
9787
6841
|
continue;
|
|
9788
6842
|
}
|
|
9789
6843
|
// conflict: attempting to delete this object but the dependent object still exists
|
|
9790
|
-
if (cascade || dep.dependency_type == DependencyType::DEPENDENCY_AUTOMATIC
|
|
6844
|
+
if (cascade || dep.dependency_type == DependencyType::DEPENDENCY_AUTOMATIC ||
|
|
6845
|
+
dep.dependency_type == DependencyType::DEPENDENCY_OWNS) {
|
|
9791
6846
|
// cascade: drop the dependent object
|
|
9792
|
-
catalog_set.DropEntryInternal(context, entry_index, *dependency_entry, cascade
|
|
6847
|
+
catalog_set.DropEntryInternal(context, entry_index, *dependency_entry, cascade);
|
|
9793
6848
|
} else {
|
|
9794
6849
|
// no cascade and there are objects that depend on this object: throw error
|
|
9795
6850
|
throw CatalogException("Cannot drop entry \"%s\" because there are entries that "
|
|
@@ -9804,6 +6859,7 @@ void DependencyManager::AlterObject(ClientContext &context, CatalogEntry *old_ob
|
|
|
9804
6859
|
D_ASSERT(dependencies_map.find(old_obj) != dependencies_map.end());
|
|
9805
6860
|
|
|
9806
6861
|
// first check the objects that depend on this object
|
|
6862
|
+
vector<CatalogEntry *> owned_objects_to_add;
|
|
9807
6863
|
auto &dependent_objects = dependents_map[old_obj];
|
|
9808
6864
|
for (auto &dep : dependent_objects) {
|
|
9809
6865
|
// look up the entry in the catalog set
|
|
@@ -9814,6 +6870,11 @@ void DependencyManager::AlterObject(ClientContext &context, CatalogEntry *old_ob
|
|
|
9814
6870
|
// the dependent object was already deleted, no conflict
|
|
9815
6871
|
continue;
|
|
9816
6872
|
}
|
|
6873
|
+
if (dep.dependency_type == DependencyType::DEPENDENCY_OWNS) {
|
|
6874
|
+
// the dependent object is owned by the current object
|
|
6875
|
+
owned_objects_to_add.push_back(dep.entry);
|
|
6876
|
+
continue;
|
|
6877
|
+
}
|
|
9817
6878
|
// conflict: attempting to alter this object but the dependent object still exists
|
|
9818
6879
|
// no cascade and there are objects that depend on this object: throw error
|
|
9819
6880
|
throw CatalogException("Cannot alter entry \"%s\" because there are entries that "
|
|
@@ -9867,6 +6928,12 @@ void DependencyManager::AlterObject(ClientContext &context, CatalogEntry *old_ob
|
|
|
9867
6928
|
dependencies_map[new_obj].insert(dependency);
|
|
9868
6929
|
dependents_map[dependency].insert(new_obj);
|
|
9869
6930
|
}
|
|
6931
|
+
|
|
6932
|
+
for (auto &dependency : owned_objects_to_add) {
|
|
6933
|
+
dependents_map[new_obj].insert(Dependency(dependency, DependencyType::DEPENDENCY_OWNS));
|
|
6934
|
+
dependents_map[dependency].insert(Dependency(new_obj, DependencyType::DEPENDENCY_OWNED_BY));
|
|
6935
|
+
dependencies_map[new_obj].insert(dependency);
|
|
6936
|
+
}
|
|
9870
6937
|
}
|
|
9871
6938
|
|
|
9872
6939
|
void DependencyManager::EraseObject(CatalogEntry *object) {
|
|
@@ -9903,6 +6970,38 @@ void DependencyManager::Scan(const std::function<void(CatalogEntry *, CatalogEnt
|
|
|
9903
6970
|
}
|
|
9904
6971
|
}
|
|
9905
6972
|
|
|
6973
|
+
void DependencyManager::AddOwnership(ClientContext &context, CatalogEntry *owner, CatalogEntry *entry) {
|
|
6974
|
+
// lock the catalog for writing
|
|
6975
|
+
lock_guard<mutex> write_lock(catalog.write_lock);
|
|
6976
|
+
|
|
6977
|
+
// If the owner is already owned by something else, throw an error
|
|
6978
|
+
for (auto &dep : dependents_map[owner]) {
|
|
6979
|
+
if (dep.dependency_type == DependencyType::DEPENDENCY_OWNED_BY) {
|
|
6980
|
+
throw CatalogException(owner->name + " already owned by " + dep.entry->name);
|
|
6981
|
+
}
|
|
6982
|
+
}
|
|
6983
|
+
|
|
6984
|
+
// If the entry is already owned, throw an error
|
|
6985
|
+
for (auto &dep : dependents_map[entry]) {
|
|
6986
|
+
// if the entry is already owned, throw error
|
|
6987
|
+
if (dep.entry != owner) {
|
|
6988
|
+
throw CatalogException(entry->name + " already depends on " + dep.entry->name);
|
|
6989
|
+
}
|
|
6990
|
+
// if the entry owns the owner, throw error
|
|
6991
|
+
if (dep.entry == owner && dep.dependency_type == DependencyType::DEPENDENCY_OWNS) {
|
|
6992
|
+
throw CatalogException(entry->name + " already owns " + owner->name +
|
|
6993
|
+
". Cannot have circular dependencies");
|
|
6994
|
+
}
|
|
6995
|
+
}
|
|
6996
|
+
|
|
6997
|
+
// Emplace guarantees that the same object cannot be inserted twice in the unordered_set
|
|
6998
|
+
// In the case AddOwnership is called twice, because of emplace, the object will not be repeated in the set.
|
|
6999
|
+
// We use an automatic dependency because if the Owner gets deleted, then the owned objects are also deleted
|
|
7000
|
+
dependents_map[owner].emplace(Dependency(entry, DependencyType::DEPENDENCY_OWNS));
|
|
7001
|
+
dependents_map[entry].emplace(Dependency(owner, DependencyType::DEPENDENCY_OWNED_BY));
|
|
7002
|
+
dependencies_map[owner].emplace(entry);
|
|
7003
|
+
}
|
|
7004
|
+
|
|
9906
7005
|
} // namespace duckdb
|
|
9907
7006
|
|
|
9908
7007
|
|
|
@@ -11770,6 +8869,8 @@ string Exception::ExceptionTypeToString(ExceptionType type) {
|
|
|
11770
8869
|
return "Invalid Input";
|
|
11771
8870
|
case ExceptionType::OUT_OF_MEMORY:
|
|
11772
8871
|
return "Out of Memory";
|
|
8872
|
+
case ExceptionType::PERMISSION:
|
|
8873
|
+
return "Permission";
|
|
11773
8874
|
default:
|
|
11774
8875
|
return "Unknown";
|
|
11775
8876
|
}
|
|
@@ -11855,6 +8956,9 @@ CatalogException::CatalogException(const string &msg) : StandardException(Except
|
|
|
11855
8956
|
ParserException::ParserException(const string &msg) : StandardException(ExceptionType::PARSER, msg) {
|
|
11856
8957
|
}
|
|
11857
8958
|
|
|
8959
|
+
PermissionException::PermissionException(const string &msg) : StandardException(ExceptionType::PERMISSION, msg) {
|
|
8960
|
+
}
|
|
8961
|
+
|
|
11858
8962
|
SyntaxException::SyntaxException(const string &msg) : Exception(ExceptionType::SYNTAX, msg) {
|
|
11859
8963
|
}
|
|
11860
8964
|
|
|
@@ -27293,11 +24397,9 @@ struct RowOperations {
|
|
|
27293
24397
|
//! Swizzles the base pointer of each row to offset within heap block
|
|
27294
24398
|
static void SwizzleHeapPointer(const RowLayout &layout, data_ptr_t row_ptr, const data_ptr_t heap_base_ptr,
|
|
27295
24399
|
const idx_t count);
|
|
27296
|
-
//!
|
|
27297
|
-
static void
|
|
27298
|
-
|
|
27299
|
-
//! Unswizzles offsets back to pointers to blobs
|
|
27300
|
-
static void UnswizzleColumns(const RowLayout &layout, const data_ptr_t base_row_ptr, const idx_t count);
|
|
24400
|
+
//! Unswizzles all offsets back to pointers
|
|
24401
|
+
static void UnswizzlePointers(const RowLayout &layout, const data_ptr_t base_row_ptr,
|
|
24402
|
+
const data_ptr_t base_heap_ptr, const idx_t count);
|
|
27301
24403
|
};
|
|
27302
24404
|
|
|
27303
24405
|
} // namespace duckdb
|
|
@@ -27533,46 +24635,44 @@ namespace duckdb {
|
|
|
27533
24635
|
|
|
27534
24636
|
void RowOperations::SwizzleColumns(const RowLayout &layout, const data_ptr_t base_row_ptr, const idx_t count) {
|
|
27535
24637
|
const idx_t row_width = layout.GetRowWidth();
|
|
27536
|
-
|
|
27537
|
-
|
|
27538
|
-
|
|
27539
|
-
|
|
27540
|
-
|
|
27541
|
-
|
|
24638
|
+
data_ptr_t heap_row_ptrs[STANDARD_VECTOR_SIZE];
|
|
24639
|
+
idx_t done = 0;
|
|
24640
|
+
while (done != count) {
|
|
24641
|
+
const idx_t next = MinValue<idx_t>(count - done, STANDARD_VECTOR_SIZE);
|
|
24642
|
+
const data_ptr_t row_ptr = base_row_ptr + done * row_width;
|
|
24643
|
+
// Load heap row pointers
|
|
24644
|
+
data_ptr_t heap_ptr_ptr = row_ptr + layout.GetHeapPointerOffset();
|
|
24645
|
+
for (idx_t i = 0; i < next; i++) {
|
|
24646
|
+
heap_row_ptrs[i] = Load<data_ptr_t>(heap_ptr_ptr);
|
|
24647
|
+
heap_ptr_ptr += row_width;
|
|
27542
24648
|
}
|
|
27543
|
-
|
|
27544
|
-
|
|
27545
|
-
|
|
27546
|
-
|
|
27547
|
-
|
|
27548
|
-
for (idx_t i = 0; i < count; i++) {
|
|
27549
|
-
const string_t str = Load<string_t>(row_ptr + col_offset);
|
|
27550
|
-
if (!str.IsInlined()) {
|
|
27551
|
-
// Load the pointer to the start of the row in the heap
|
|
27552
|
-
data_ptr_t heap_row_ptr = Load<data_ptr_t>(row_ptr + heap_pointer_offset);
|
|
27553
|
-
// This is where the pointer that points to the heap is stored in the RowLayout
|
|
27554
|
-
data_ptr_t col_ptr = row_ptr + col_offset + string_pointer_offset;
|
|
27555
|
-
// Load the pointer to the data of this column in the same heap row
|
|
27556
|
-
data_ptr_t heap_col_ptr = Load<data_ptr_t>(col_ptr);
|
|
27557
|
-
// Overwrite the column data pointer with the within-row offset (pointer arithmetic)
|
|
27558
|
-
Store<idx_t>(heap_col_ptr - heap_row_ptr, col_ptr);
|
|
27559
|
-
}
|
|
27560
|
-
row_ptr += row_width;
|
|
24649
|
+
// Loop through the blob columns
|
|
24650
|
+
for (idx_t col_idx = 0; col_idx < layout.ColumnCount(); col_idx++) {
|
|
24651
|
+
auto physical_type = layout.GetTypes()[col_idx].InternalType();
|
|
24652
|
+
if (TypeIsConstantSize(physical_type)) {
|
|
24653
|
+
continue;
|
|
27561
24654
|
}
|
|
27562
|
-
|
|
27563
|
-
|
|
27564
|
-
|
|
27565
|
-
|
|
27566
|
-
|
|
27567
|
-
|
|
27568
|
-
|
|
27569
|
-
|
|
27570
|
-
|
|
27571
|
-
|
|
27572
|
-
|
|
27573
|
-
|
|
24655
|
+
data_ptr_t col_ptr = row_ptr + layout.GetOffsets()[col_idx];
|
|
24656
|
+
if (physical_type == PhysicalType::VARCHAR) {
|
|
24657
|
+
data_ptr_t string_ptr = col_ptr + sizeof(uint32_t) + string_t::PREFIX_LENGTH;
|
|
24658
|
+
for (idx_t i = 0; i < next; i++) {
|
|
24659
|
+
if (Load<uint32_t>(col_ptr) > string_t::INLINE_LENGTH) {
|
|
24660
|
+
// Overwrite the string pointer with the within-row offset (if not inlined)
|
|
24661
|
+
Store<idx_t>(Load<data_ptr_t>(string_ptr) - heap_row_ptrs[i], string_ptr);
|
|
24662
|
+
}
|
|
24663
|
+
col_ptr += row_width;
|
|
24664
|
+
string_ptr += row_width;
|
|
24665
|
+
}
|
|
24666
|
+
} else {
|
|
24667
|
+
// Non-varchar blob columns
|
|
24668
|
+
for (idx_t i = 0; i < next; i++) {
|
|
24669
|
+
// Overwrite the column data pointer with the within-row offset
|
|
24670
|
+
Store<idx_t>(Load<data_ptr_t>(col_ptr) - heap_row_ptrs[i], col_ptr);
|
|
24671
|
+
col_ptr += row_width;
|
|
24672
|
+
}
|
|
27574
24673
|
}
|
|
27575
24674
|
}
|
|
24675
|
+
done += next;
|
|
27576
24676
|
}
|
|
27577
24677
|
}
|
|
27578
24678
|
|
|
@@ -27588,59 +24688,48 @@ void RowOperations::SwizzleHeapPointer(const RowLayout &layout, data_ptr_t row_p
|
|
|
27588
24688
|
}
|
|
27589
24689
|
}
|
|
27590
24690
|
|
|
27591
|
-
void RowOperations::
|
|
27592
|
-
|
|
27593
|
-
const idx_t row_width = layout.GetRowWidth();
|
|
27594
|
-
row_ptr += layout.GetHeapPointerOffset();
|
|
27595
|
-
for (idx_t i = 0; i < count; i++) {
|
|
27596
|
-
idx_t heap_row_offset = Load<idx_t>(row_ptr);
|
|
27597
|
-
Store<data_ptr_t>(heap_base_ptr + heap_row_offset, row_ptr);
|
|
27598
|
-
row_ptr += row_width;
|
|
27599
|
-
}
|
|
27600
|
-
}
|
|
27601
|
-
|
|
27602
|
-
void RowOperations::UnswizzleColumns(const RowLayout &layout, const data_ptr_t base_row_ptr, const idx_t count) {
|
|
24691
|
+
void RowOperations::UnswizzlePointers(const RowLayout &layout, const data_ptr_t base_row_ptr,
|
|
24692
|
+
const data_ptr_t base_heap_ptr, const idx_t count) {
|
|
27603
24693
|
const idx_t row_width = layout.GetRowWidth();
|
|
27604
|
-
|
|
27605
|
-
|
|
27606
|
-
|
|
27607
|
-
|
|
27608
|
-
|
|
27609
|
-
|
|
27610
|
-
|
|
27611
|
-
|
|
27612
|
-
|
|
27613
|
-
|
|
27614
|
-
|
|
27615
|
-
|
|
27616
|
-
|
|
27617
|
-
|
|
27618
|
-
|
|
27619
|
-
|
|
27620
|
-
|
|
27621
|
-
|
|
27622
|
-
|
|
27623
|
-
|
|
27624
|
-
|
|
24694
|
+
data_ptr_t heap_row_ptrs[STANDARD_VECTOR_SIZE];
|
|
24695
|
+
idx_t done = 0;
|
|
24696
|
+
while (done != count) {
|
|
24697
|
+
const idx_t next = MinValue<idx_t>(count - done, STANDARD_VECTOR_SIZE);
|
|
24698
|
+
const data_ptr_t row_ptr = base_row_ptr + done * row_width;
|
|
24699
|
+
// Restore heap row pointers
|
|
24700
|
+
data_ptr_t heap_ptr_ptr = row_ptr + layout.GetHeapPointerOffset();
|
|
24701
|
+
for (idx_t i = 0; i < next; i++) {
|
|
24702
|
+
heap_row_ptrs[i] = base_heap_ptr + Load<idx_t>(heap_ptr_ptr);
|
|
24703
|
+
Store<data_ptr_t>(heap_row_ptrs[i], heap_ptr_ptr);
|
|
24704
|
+
heap_ptr_ptr += row_width;
|
|
24705
|
+
}
|
|
24706
|
+
// Loop through the blob columns
|
|
24707
|
+
for (idx_t col_idx = 0; col_idx < layout.ColumnCount(); col_idx++) {
|
|
24708
|
+
auto physical_type = layout.GetTypes()[col_idx].InternalType();
|
|
24709
|
+
if (TypeIsConstantSize(physical_type)) {
|
|
24710
|
+
continue;
|
|
24711
|
+
}
|
|
24712
|
+
data_ptr_t col_ptr = row_ptr + layout.GetOffsets()[col_idx];
|
|
24713
|
+
if (physical_type == PhysicalType::VARCHAR) {
|
|
24714
|
+
data_ptr_t string_ptr = col_ptr + sizeof(uint32_t) + string_t::PREFIX_LENGTH;
|
|
24715
|
+
for (idx_t i = 0; i < next; i++) {
|
|
24716
|
+
if (Load<uint32_t>(col_ptr) > string_t::INLINE_LENGTH) {
|
|
24717
|
+
// Overwrite the string offset with the pointer (if not inlined)
|
|
24718
|
+
Store<data_ptr_t>(heap_row_ptrs[i] + Load<idx_t>(string_ptr), string_ptr);
|
|
24719
|
+
}
|
|
24720
|
+
col_ptr += row_width;
|
|
24721
|
+
string_ptr += row_width;
|
|
24722
|
+
}
|
|
24723
|
+
} else {
|
|
24724
|
+
// Non-varchar blob columns
|
|
24725
|
+
for (idx_t i = 0; i < next; i++) {
|
|
27625
24726
|
// Overwrite the column data offset with the pointer
|
|
27626
|
-
Store<data_ptr_t>(
|
|
24727
|
+
Store<data_ptr_t>(heap_row_ptrs[i] + Load<idx_t>(col_ptr), col_ptr);
|
|
24728
|
+
col_ptr += row_width;
|
|
27627
24729
|
}
|
|
27628
|
-
row_ptr += row_width;
|
|
27629
|
-
}
|
|
27630
|
-
} else {
|
|
27631
|
-
// Replace the offset with the pointer
|
|
27632
|
-
for (idx_t i = 0; i < count; i++) {
|
|
27633
|
-
// Load the pointer to the start of the row in the heap
|
|
27634
|
-
data_ptr_t heap_row_ptr = Load<data_ptr_t>(row_ptr + heap_pointer_offset);
|
|
27635
|
-
// This is where the pointer that points to the heap is stored in the RowLayout
|
|
27636
|
-
data_ptr_t col_ptr = row_ptr + col_offset;
|
|
27637
|
-
// Load the offset to the data of this column in the same heap row
|
|
27638
|
-
idx_t heap_col_offset = Load<idx_t>(col_ptr);
|
|
27639
|
-
// Overwrite the column data offset with the pointer
|
|
27640
|
-
Store<data_ptr_t>(heap_row_ptr + heap_col_offset, col_ptr);
|
|
27641
|
-
row_ptr += row_width;
|
|
27642
24730
|
}
|
|
27643
24731
|
}
|
|
24732
|
+
done += next;
|
|
27644
24733
|
}
|
|
27645
24734
|
}
|
|
27646
24735
|
|
|
@@ -32711,8 +29800,7 @@ void SortedData::Unswizzle() {
|
|
|
32711
29800
|
auto &heap_block = heap_blocks[i];
|
|
32712
29801
|
auto data_handle_p = buffer_manager.Pin(data_block.block);
|
|
32713
29802
|
auto heap_handle_p = buffer_manager.Pin(heap_block.block);
|
|
32714
|
-
RowOperations::
|
|
32715
|
-
RowOperations::UnswizzleColumns(layout, data_handle_p->Ptr(), data_block.count);
|
|
29803
|
+
RowOperations::UnswizzlePointers(layout, data_handle_p->Ptr(), heap_handle_p->Ptr(), data_block.count);
|
|
32716
29804
|
state.heap_blocks.push_back(move(heap_block));
|
|
32717
29805
|
state.pinned_blocks.push_back(move(heap_handle_p));
|
|
32718
29806
|
}
|
|
@@ -32958,9 +30046,7 @@ void PayloadScanner::Scan(DataChunk &chunk) {
|
|
|
32958
30046
|
}
|
|
32959
30047
|
// Unswizzle the offsets back to pointers (if needed)
|
|
32960
30048
|
if (!sorted_data.layout.AllConstant() && global_sort_state.external) {
|
|
32961
|
-
RowOperations::
|
|
32962
|
-
next);
|
|
32963
|
-
RowOperations::UnswizzleColumns(sorted_data.layout, data_ptr, next);
|
|
30049
|
+
RowOperations::UnswizzlePointers(sorted_data.layout, data_ptr, read_state.payload_heap_handle->Ptr(), next);
|
|
32964
30050
|
}
|
|
32965
30051
|
// Update state indices
|
|
32966
30052
|
read_state.entry_idx += next;
|
|
@@ -35812,6 +32898,8 @@ public:
|
|
|
35812
32898
|
|
|
35813
32899
|
|
|
35814
32900
|
|
|
32901
|
+
|
|
32902
|
+
|
|
35815
32903
|
namespace duckdb {
|
|
35816
32904
|
|
|
35817
32905
|
DataChunk::DataChunk() : count(0), capacity(STANDARD_VECTOR_SIZE) {
|
|
@@ -36214,6 +33302,79 @@ void SetStructMap(DuckDBArrowArrayChildHolder &child_holder, const LogicalType &
|
|
|
36214
33302
|
}
|
|
36215
33303
|
}
|
|
36216
33304
|
|
|
33305
|
+
struct ArrowUUIDConversion {
|
|
33306
|
+
using internal_type_t = uint64_t;
|
|
33307
|
+
|
|
33308
|
+
static unique_ptr<Vector> InitializeVector(Vector &data, idx_t size) {
|
|
33309
|
+
return make_unique<Vector>(LogicalType::VARCHAR, size);
|
|
33310
|
+
}
|
|
33311
|
+
|
|
33312
|
+
static idx_t GetStringLength(uint64_t value) {
|
|
33313
|
+
return UUID::STRING_SIZE;
|
|
33314
|
+
}
|
|
33315
|
+
|
|
33316
|
+
static string_t ConvertValue(Vector &tgt_vec, string_t *tgt_ptr, internal_type_t *src_ptr, idx_t row) {
|
|
33317
|
+
auto str_value = UUID::ToString(src_ptr[row]);
|
|
33318
|
+
// Have to store this string
|
|
33319
|
+
tgt_ptr[row] = StringVector::AddStringOrBlob(tgt_vec, str_value);
|
|
33320
|
+
return tgt_ptr[row];
|
|
33321
|
+
}
|
|
33322
|
+
};
|
|
33323
|
+
|
|
33324
|
+
struct ArrowVarcharConversion {
|
|
33325
|
+
using internal_type_t = string_t;
|
|
33326
|
+
|
|
33327
|
+
static unique_ptr<Vector> InitializeVector(Vector &data, idx_t size) {
|
|
33328
|
+
return make_unique<Vector>(data);
|
|
33329
|
+
}
|
|
33330
|
+
static idx_t GetStringLength(string_t value) {
|
|
33331
|
+
return value.GetSize();
|
|
33332
|
+
}
|
|
33333
|
+
|
|
33334
|
+
static string_t ConvertValue(Vector &tgt_vec, string_t *tgt_ptr, internal_type_t *src_ptr, idx_t row) {
|
|
33335
|
+
return src_ptr[row];
|
|
33336
|
+
}
|
|
33337
|
+
};
|
|
33338
|
+
|
|
33339
|
+
template <class CONVERT, class VECTOR_TYPE>
|
|
33340
|
+
void SetVarchar(DuckDBArrowArrayChildHolder &child_holder, const LogicalType &type, Vector &data, idx_t size) {
|
|
33341
|
+
auto &child = child_holder.array;
|
|
33342
|
+
child_holder.vector = CONVERT::InitializeVector(data, size);
|
|
33343
|
+
auto target_data_ptr = FlatVector::GetData<string_t>(data);
|
|
33344
|
+
child.n_buffers = 3;
|
|
33345
|
+
child_holder.offsets = unique_ptr<data_t[]>(new data_t[sizeof(uint32_t) * (size + 1)]);
|
|
33346
|
+
child.buffers[1] = child_holder.offsets.get();
|
|
33347
|
+
D_ASSERT(child.buffers[1]);
|
|
33348
|
+
//! step 1: figure out total string length:
|
|
33349
|
+
idx_t total_string_length = 0;
|
|
33350
|
+
auto source_ptr = FlatVector::GetData<VECTOR_TYPE>(data);
|
|
33351
|
+
auto &mask = FlatVector::Validity(data);
|
|
33352
|
+
for (idx_t row_idx = 0; row_idx < size; row_idx++) {
|
|
33353
|
+
if (!mask.RowIsValid(row_idx)) {
|
|
33354
|
+
continue;
|
|
33355
|
+
}
|
|
33356
|
+
total_string_length += CONVERT::GetStringLength(source_ptr[row_idx]);
|
|
33357
|
+
}
|
|
33358
|
+
//! step 2: allocate this much
|
|
33359
|
+
child_holder.data = unique_ptr<data_t[]>(new data_t[total_string_length]);
|
|
33360
|
+
child.buffers[2] = child_holder.data.get();
|
|
33361
|
+
D_ASSERT(child.buffers[2]);
|
|
33362
|
+
//! step 3: assign buffers
|
|
33363
|
+
idx_t current_heap_offset = 0;
|
|
33364
|
+
auto target_ptr = (uint32_t *)child.buffers[1];
|
|
33365
|
+
|
|
33366
|
+
for (idx_t row_idx = 0; row_idx < size; row_idx++) {
|
|
33367
|
+
target_ptr[row_idx] = current_heap_offset;
|
|
33368
|
+
if (!mask.RowIsValid(row_idx)) {
|
|
33369
|
+
continue;
|
|
33370
|
+
}
|
|
33371
|
+
string_t str = CONVERT::ConvertValue(*child_holder.vector, target_data_ptr, source_ptr, row_idx);
|
|
33372
|
+
memcpy((void *)((uint8_t *)child.buffers[2] + current_heap_offset), str.GetDataUnsafe(), str.GetSize());
|
|
33373
|
+
current_heap_offset += str.GetSize();
|
|
33374
|
+
}
|
|
33375
|
+
target_ptr[size] = current_heap_offset; //! need to terminate last string!
|
|
33376
|
+
}
|
|
33377
|
+
|
|
36217
33378
|
void SetArrowChild(DuckDBArrowArrayChildHolder &child_holder, const LogicalType &type, Vector &data, idx_t size) {
|
|
36218
33379
|
auto &child = child_holder.array;
|
|
36219
33380
|
switch (type.id()) {
|
|
@@ -36319,39 +33480,11 @@ void SetArrowChild(DuckDBArrowArrayChildHolder &child_holder, const LogicalType
|
|
|
36319
33480
|
}
|
|
36320
33481
|
case LogicalTypeId::BLOB:
|
|
36321
33482
|
case LogicalTypeId::VARCHAR: {
|
|
36322
|
-
child_holder
|
|
36323
|
-
|
|
36324
|
-
|
|
36325
|
-
|
|
36326
|
-
|
|
36327
|
-
//! step 1: figure out total string length:
|
|
36328
|
-
idx_t total_string_length = 0;
|
|
36329
|
-
auto string_t_ptr = FlatVector::GetData<string_t>(*child_holder.vector);
|
|
36330
|
-
auto &mask = FlatVector::Validity(*child_holder.vector);
|
|
36331
|
-
for (idx_t row_idx = 0; row_idx < size; row_idx++) {
|
|
36332
|
-
if (!mask.RowIsValid(row_idx)) {
|
|
36333
|
-
continue;
|
|
36334
|
-
}
|
|
36335
|
-
total_string_length += string_t_ptr[row_idx].GetSize();
|
|
36336
|
-
}
|
|
36337
|
-
//! step 2: allocate this much
|
|
36338
|
-
child_holder.data = unique_ptr<data_t[]>(new data_t[total_string_length]);
|
|
36339
|
-
child.buffers[2] = child_holder.data.get();
|
|
36340
|
-
D_ASSERT(child.buffers[2]);
|
|
36341
|
-
//! step 3: assign buffers
|
|
36342
|
-
idx_t current_heap_offset = 0;
|
|
36343
|
-
auto target_ptr = (uint32_t *)child.buffers[1];
|
|
36344
|
-
|
|
36345
|
-
for (idx_t row_idx = 0; row_idx < size; row_idx++) {
|
|
36346
|
-
target_ptr[row_idx] = current_heap_offset;
|
|
36347
|
-
if (!mask.RowIsValid(row_idx)) {
|
|
36348
|
-
continue;
|
|
36349
|
-
}
|
|
36350
|
-
auto &str = string_t_ptr[row_idx];
|
|
36351
|
-
memcpy((void *)((uint8_t *)child.buffers[2] + current_heap_offset), str.GetDataUnsafe(), str.GetSize());
|
|
36352
|
-
current_heap_offset += str.GetSize();
|
|
36353
|
-
}
|
|
36354
|
-
target_ptr[size] = current_heap_offset; //! need to terminate last string!
|
|
33483
|
+
SetVarchar<ArrowVarcharConversion, string_t>(child_holder, type, data, size);
|
|
33484
|
+
break;
|
|
33485
|
+
}
|
|
33486
|
+
case LogicalTypeId::UUID: {
|
|
33487
|
+
SetVarchar<ArrowUUIDConversion, uint64_t>(child_holder, type, data, size);
|
|
36355
33488
|
break;
|
|
36356
33489
|
}
|
|
36357
33490
|
case LogicalTypeId::LIST: {
|
|
@@ -36407,6 +33540,23 @@ void SetArrowChild(DuckDBArrowArrayChildHolder &child_holder, const LogicalType
|
|
|
36407
33540
|
}
|
|
36408
33541
|
break;
|
|
36409
33542
|
}
|
|
33543
|
+
case LogicalTypeId::ENUM: {
|
|
33544
|
+
// We need to initialize our dictionary
|
|
33545
|
+
child_holder.children.resize(1);
|
|
33546
|
+
idx_t dict_size = EnumType::GetSize(type);
|
|
33547
|
+
InitializeChild(child_holder.children[0], dict_size);
|
|
33548
|
+
Vector dictionary(EnumType::GetValuesInsertOrder(type));
|
|
33549
|
+
SetArrowChild(child_holder.children[0], dictionary.GetType(), dictionary, dict_size);
|
|
33550
|
+
child_holder.children_ptrs.push_back(&child_holder.children[0].array);
|
|
33551
|
+
|
|
33552
|
+
// now we set the data
|
|
33553
|
+
child.dictionary = child_holder.children_ptrs[0];
|
|
33554
|
+
child_holder.vector = make_unique<Vector>(data);
|
|
33555
|
+
child.n_buffers = 2;
|
|
33556
|
+
child.buffers[1] = (void *)FlatVector::GetData(*child_holder.vector);
|
|
33557
|
+
|
|
33558
|
+
break;
|
|
33559
|
+
}
|
|
36410
33560
|
default:
|
|
36411
33561
|
throw std::runtime_error("Unsupported type " + type.ToString());
|
|
36412
33562
|
}
|
|
@@ -40976,7 +38126,7 @@ string Value::ToString() const {
|
|
|
40976
38126
|
default:
|
|
40977
38127
|
throw InternalException("ENUM can only have unsigned integers (except UINT64) as physical types");
|
|
40978
38128
|
}
|
|
40979
|
-
return values_insert_order
|
|
38129
|
+
return values_insert_order.GetValue(enum_idx).ToString();
|
|
40980
38130
|
}
|
|
40981
38131
|
default:
|
|
40982
38132
|
throw NotImplementedException("Unimplemented type for printing: %s", type_.ToString());
|
|
@@ -43530,6 +40680,8 @@ const sel_t FlatVector::INCREMENTAL_VECTOR[] = {
|
|
|
43530
40680
|
|
|
43531
40681
|
|
|
43532
40682
|
|
|
40683
|
+
|
|
40684
|
+
|
|
43533
40685
|
namespace duckdb {
|
|
43534
40686
|
|
|
43535
40687
|
LogicalType::LogicalType() : LogicalType(LogicalTypeId::INVALID) {
|
|
@@ -44263,7 +41415,7 @@ struct ExtraTypeInfo {
|
|
|
44263
41415
|
public:
|
|
44264
41416
|
virtual bool Equals(ExtraTypeInfo *other) = 0;
|
|
44265
41417
|
//! Serializes a ExtraTypeInfo to a stand-alone binary blob
|
|
44266
|
-
virtual void Serialize(Serializer &serializer)
|
|
41418
|
+
virtual void Serialize(Serializer &serializer) = 0;
|
|
44267
41419
|
//! Serializes a ExtraTypeInfo to a stand-alone binary blob
|
|
44268
41420
|
static void Serialize(ExtraTypeInfo *info, Serializer &serializer);
|
|
44269
41421
|
//! Deserializes a blob back into an ExtraTypeInfo
|
|
@@ -44293,7 +41445,7 @@ public:
|
|
|
44293
41445
|
return width == other.width && scale == other.scale;
|
|
44294
41446
|
}
|
|
44295
41447
|
|
|
44296
|
-
void Serialize(Serializer &serializer)
|
|
41448
|
+
void Serialize(Serializer &serializer) override {
|
|
44297
41449
|
serializer.Write<uint8_t>(width);
|
|
44298
41450
|
serializer.Write<uint8_t>(scale);
|
|
44299
41451
|
}
|
|
@@ -44340,7 +41492,7 @@ public:
|
|
|
44340
41492
|
return true;
|
|
44341
41493
|
}
|
|
44342
41494
|
|
|
44343
|
-
void Serialize(Serializer &serializer)
|
|
41495
|
+
void Serialize(Serializer &serializer) override {
|
|
44344
41496
|
serializer.WriteString(collation);
|
|
44345
41497
|
}
|
|
44346
41498
|
|
|
@@ -44388,7 +41540,7 @@ public:
|
|
|
44388
41540
|
return child_type == other.child_type;
|
|
44389
41541
|
}
|
|
44390
41542
|
|
|
44391
|
-
void Serialize(Serializer &serializer)
|
|
41543
|
+
void Serialize(Serializer &serializer) override {
|
|
44392
41544
|
child_type.Serialize(serializer);
|
|
44393
41545
|
}
|
|
44394
41546
|
|
|
@@ -44432,7 +41584,7 @@ public:
|
|
|
44432
41584
|
return child_types == other.child_types;
|
|
44433
41585
|
}
|
|
44434
41586
|
|
|
44435
|
-
void Serialize(Serializer &serializer)
|
|
41587
|
+
void Serialize(Serializer &serializer) override {
|
|
44436
41588
|
serializer.Write<uint32_t>(child_types.size());
|
|
44437
41589
|
for (idx_t i = 0; i < child_types.size(); i++) {
|
|
44438
41590
|
serializer.WriteString(child_types[i].first);
|
|
@@ -44514,7 +41666,7 @@ public:
|
|
|
44514
41666
|
return other.user_type_name == user_type_name;
|
|
44515
41667
|
}
|
|
44516
41668
|
|
|
44517
|
-
void Serialize(Serializer &serializer)
|
|
41669
|
+
void Serialize(Serializer &serializer) override {
|
|
44518
41670
|
serializer.WriteString(user_type_name);
|
|
44519
41671
|
}
|
|
44520
41672
|
|
|
@@ -44540,12 +41692,13 @@ LogicalType LogicalType::USER(const string &user_type_name) {
|
|
|
44540
41692
|
// Enum Type
|
|
44541
41693
|
//===--------------------------------------------------------------------===//
|
|
44542
41694
|
struct EnumTypeInfo : public ExtraTypeInfo {
|
|
44543
|
-
explicit EnumTypeInfo(string enum_name_p,
|
|
41695
|
+
explicit EnumTypeInfo(string enum_name_p, Vector &values_insert_order_p, idx_t size)
|
|
44544
41696
|
: ExtraTypeInfo(ExtraTypeInfoType::ENUM_TYPE_INFO), enum_name(move(enum_name_p)),
|
|
44545
|
-
values_insert_order(
|
|
41697
|
+
values_insert_order(values_insert_order_p), size(size) {
|
|
44546
41698
|
}
|
|
44547
41699
|
string enum_name;
|
|
44548
|
-
|
|
41700
|
+
Vector values_insert_order;
|
|
41701
|
+
idx_t size;
|
|
44549
41702
|
TypeCatalogEntry *catalog_entry = nullptr;
|
|
44550
41703
|
|
|
44551
41704
|
public:
|
|
@@ -44558,33 +41711,42 @@ public:
|
|
|
44558
41711
|
return false;
|
|
44559
41712
|
}
|
|
44560
41713
|
auto &other = (EnumTypeInfo &)*other_p;
|
|
44561
|
-
|
|
44562
|
-
if
|
|
44563
|
-
|
|
41714
|
+
|
|
41715
|
+
// We must check if both enums have the same size
|
|
41716
|
+
if (other.size != size) {
|
|
41717
|
+
return false;
|
|
44564
41718
|
}
|
|
44565
|
-
|
|
41719
|
+
auto other_vector_ptr = FlatVector::GetData<string_t>(other.values_insert_order);
|
|
41720
|
+
auto this_vector_ptr = FlatVector::GetData<string_t>(values_insert_order);
|
|
41721
|
+
|
|
41722
|
+
// Now we must check if all strings are the same
|
|
41723
|
+
for (idx_t i = 0; i < size; i++) {
|
|
41724
|
+
if (!Equals::Operation(other_vector_ptr[i], this_vector_ptr[i])) {
|
|
41725
|
+
return false;
|
|
41726
|
+
}
|
|
41727
|
+
}
|
|
41728
|
+
return true;
|
|
44566
41729
|
}
|
|
44567
|
-
void Serialize(Serializer &serializer)
|
|
44568
|
-
serializer.Write<uint32_t>(
|
|
41730
|
+
void Serialize(Serializer &serializer) override {
|
|
41731
|
+
serializer.Write<uint32_t>(size);
|
|
44569
41732
|
serializer.WriteString(enum_name);
|
|
44570
|
-
|
|
41733
|
+
values_insert_order.Serialize(size, serializer);
|
|
44571
41734
|
}
|
|
44572
41735
|
};
|
|
44573
41736
|
|
|
44574
41737
|
template <class T>
|
|
44575
41738
|
struct EnumTypeInfoTemplated : public EnumTypeInfo {
|
|
44576
|
-
explicit EnumTypeInfoTemplated(const string &enum_name_p,
|
|
44577
|
-
: EnumTypeInfo(enum_name_p, values_insert_order_p) {
|
|
44578
|
-
idx_t count = 0;
|
|
44579
|
-
|
|
44580
|
-
values[value] = count++;
|
|
41739
|
+
explicit EnumTypeInfoTemplated(const string &enum_name_p, Vector &values_insert_order_p, idx_t size_p)
|
|
41740
|
+
: EnumTypeInfo(enum_name_p, values_insert_order_p, size_p) {
|
|
41741
|
+
for (idx_t count = 0; count < size_p; count++) {
|
|
41742
|
+
values[values_insert_order_p.GetValue(count).ToString()] = count;
|
|
44581
41743
|
}
|
|
44582
41744
|
}
|
|
44583
|
-
static shared_ptr<EnumTypeInfoTemplated> Deserialize(Deserializer &source) {
|
|
41745
|
+
static shared_ptr<EnumTypeInfoTemplated> Deserialize(Deserializer &source, uint32_t size) {
|
|
44584
41746
|
auto enum_name = source.Read<string>();
|
|
44585
|
-
|
|
44586
|
-
|
|
44587
|
-
return make_shared<EnumTypeInfoTemplated>(move(enum_name),
|
|
41747
|
+
Vector values_insert_order(LogicalType::VARCHAR, size);
|
|
41748
|
+
values_insert_order.Deserialize(size, source);
|
|
41749
|
+
return make_shared<EnumTypeInfoTemplated>(move(enum_name), values_insert_order, size);
|
|
44588
41750
|
}
|
|
44589
41751
|
unordered_map<string, T> values;
|
|
44590
41752
|
};
|
|
@@ -44596,20 +41758,19 @@ const string &EnumType::GetTypeName(const LogicalType &type) {
|
|
|
44596
41758
|
return ((EnumTypeInfo &)*info).enum_name;
|
|
44597
41759
|
}
|
|
44598
41760
|
|
|
44599
|
-
LogicalType LogicalType::ENUM(const string &enum_name,
|
|
44600
|
-
auto size = ordered_data.size();
|
|
41761
|
+
LogicalType LogicalType::ENUM(const string &enum_name, Vector &ordered_data, idx_t size) {
|
|
44601
41762
|
// Generate EnumTypeInfo
|
|
44602
41763
|
shared_ptr<ExtraTypeInfo> info;
|
|
44603
41764
|
auto enum_internal_type = EnumType::GetPhysicalType(size);
|
|
44604
41765
|
switch (enum_internal_type) {
|
|
44605
41766
|
case PhysicalType::UINT8:
|
|
44606
|
-
info = make_shared<EnumTypeInfoTemplated<uint8_t>>(enum_name, ordered_data);
|
|
41767
|
+
info = make_shared<EnumTypeInfoTemplated<uint8_t>>(enum_name, ordered_data, size);
|
|
44607
41768
|
break;
|
|
44608
41769
|
case PhysicalType::UINT16:
|
|
44609
|
-
info = make_shared<EnumTypeInfoTemplated<uint16_t>>(enum_name, ordered_data);
|
|
41770
|
+
info = make_shared<EnumTypeInfoTemplated<uint16_t>>(enum_name, ordered_data, size);
|
|
44610
41771
|
break;
|
|
44611
41772
|
case PhysicalType::UINT32:
|
|
44612
|
-
info = make_shared<EnumTypeInfoTemplated<uint32_t>>(enum_name, ordered_data);
|
|
41773
|
+
info = make_shared<EnumTypeInfoTemplated<uint32_t>>(enum_name, ordered_data, size);
|
|
44613
41774
|
break;
|
|
44614
41775
|
default:
|
|
44615
41776
|
throw InternalException("Invalid Physical Type for ENUMs");
|
|
@@ -44640,22 +41801,22 @@ int64_t EnumType::GetPos(const LogicalType &type, const string &key) {
|
|
|
44640
41801
|
}
|
|
44641
41802
|
}
|
|
44642
41803
|
|
|
44643
|
-
const string
|
|
41804
|
+
const string EnumType::GetValue(const Value &val) {
|
|
44644
41805
|
auto info = val.type().AuxInfo();
|
|
44645
|
-
|
|
41806
|
+
auto &values_insert_order = ((EnumTypeInfo &)*info).values_insert_order;
|
|
44646
41807
|
switch (val.type().InternalType()) {
|
|
44647
41808
|
case PhysicalType::UINT8:
|
|
44648
|
-
return values_insert_order
|
|
41809
|
+
return values_insert_order.GetValue(val.value_.utinyint).ToString();
|
|
44649
41810
|
case PhysicalType::UINT16:
|
|
44650
|
-
return values_insert_order
|
|
41811
|
+
return values_insert_order.GetValue(val.value_.usmallint).ToString();
|
|
44651
41812
|
case PhysicalType::UINT32:
|
|
44652
|
-
return values_insert_order
|
|
41813
|
+
return values_insert_order.GetValue(val.value_.uinteger).ToString();
|
|
44653
41814
|
default:
|
|
44654
41815
|
throw InternalException("Invalid Internal Type for ENUMs");
|
|
44655
41816
|
}
|
|
44656
41817
|
}
|
|
44657
41818
|
|
|
44658
|
-
|
|
41819
|
+
Vector &EnumType::GetValuesInsertOrder(const LogicalType &type) {
|
|
44659
41820
|
D_ASSERT(type.id() == LogicalTypeId::ENUM);
|
|
44660
41821
|
auto info = type.AuxInfo();
|
|
44661
41822
|
D_ASSERT(info);
|
|
@@ -44666,7 +41827,7 @@ idx_t EnumType::GetSize(const LogicalType &type) {
|
|
|
44666
41827
|
D_ASSERT(type.id() == LogicalTypeId::ENUM);
|
|
44667
41828
|
auto info = type.AuxInfo();
|
|
44668
41829
|
D_ASSERT(info);
|
|
44669
|
-
return ((EnumTypeInfo &)*info).
|
|
41830
|
+
return ((EnumTypeInfo &)*info).size;
|
|
44670
41831
|
}
|
|
44671
41832
|
|
|
44672
41833
|
void EnumType::SetCatalog(LogicalType &type, TypeCatalogEntry *catalog_entry) {
|
|
@@ -44721,14 +41882,15 @@ shared_ptr<ExtraTypeInfo> ExtraTypeInfo::Deserialize(Deserializer &source) {
|
|
|
44721
41882
|
case ExtraTypeInfoType::USER_TYPE_INFO:
|
|
44722
41883
|
return UserTypeInfo::Deserialize(source);
|
|
44723
41884
|
case ExtraTypeInfoType::ENUM_TYPE_INFO: {
|
|
44724
|
-
auto
|
|
41885
|
+
auto enum_size = source.Read<uint32_t>();
|
|
41886
|
+
auto enum_internal_type = EnumType::GetPhysicalType(enum_size);
|
|
44725
41887
|
switch (enum_internal_type) {
|
|
44726
41888
|
case PhysicalType::UINT8:
|
|
44727
|
-
return EnumTypeInfoTemplated<uint8_t>::Deserialize(source);
|
|
41889
|
+
return EnumTypeInfoTemplated<uint8_t>::Deserialize(source, enum_size);
|
|
44728
41890
|
case PhysicalType::UINT16:
|
|
44729
|
-
return EnumTypeInfoTemplated<uint16_t>::Deserialize(source);
|
|
41891
|
+
return EnumTypeInfoTemplated<uint16_t>::Deserialize(source, enum_size);
|
|
44730
41892
|
case PhysicalType::UINT32:
|
|
44731
|
-
return EnumTypeInfoTemplated<uint32_t>::Deserialize(source);
|
|
41893
|
+
return EnumTypeInfoTemplated<uint32_t>::Deserialize(source, enum_size);
|
|
44732
41894
|
default:
|
|
44733
41895
|
throw InternalException("Invalid Physical Type for ENUMs");
|
|
44734
41896
|
}
|
|
@@ -47848,7 +45010,9 @@ void FillEnum(Vector &source, Vector &result, idx_t count) {
|
|
|
47848
45010
|
|
|
47849
45011
|
result.SetVectorType(VectorType::FLAT_VECTOR);
|
|
47850
45012
|
|
|
47851
|
-
auto str_vec = EnumType::GetValuesInsertOrder(source.GetType());
|
|
45013
|
+
auto &str_vec = EnumType::GetValuesInsertOrder(source.GetType());
|
|
45014
|
+
auto str_vec_ptr = FlatVector::GetData<string_t>(str_vec);
|
|
45015
|
+
|
|
47852
45016
|
auto res_enum_type = result.GetType();
|
|
47853
45017
|
|
|
47854
45018
|
VectorData vdata;
|
|
@@ -47867,7 +45031,7 @@ void FillEnum(Vector &source, Vector &result, idx_t count) {
|
|
|
47867
45031
|
result_mask.SetInvalid(i);
|
|
47868
45032
|
continue;
|
|
47869
45033
|
}
|
|
47870
|
-
auto str =
|
|
45034
|
+
auto str = str_vec_ptr[source_data[src_idx]].GetString();
|
|
47871
45035
|
auto key = EnumType::GetPos(res_enum_type, str);
|
|
47872
45036
|
if (key == -1) {
|
|
47873
45037
|
// key doesn't exist on result enum
|
|
@@ -47901,13 +45065,17 @@ void EnumToVarchar(Vector &source, Vector &result, idx_t count, PhysicalType enu
|
|
|
47901
45065
|
} else {
|
|
47902
45066
|
result.SetVectorType(VectorType::FLAT_VECTOR);
|
|
47903
45067
|
}
|
|
45068
|
+
auto &str_vec = EnumType::GetValuesInsertOrder(source.GetType());
|
|
45069
|
+
auto str_vec_ptr = FlatVector::GetData<string_t>(str_vec);
|
|
45070
|
+
auto res_vec_ptr = FlatVector::GetData<string_t>(result);
|
|
45071
|
+
|
|
47904
45072
|
for (idx_t i = 0; i < count; i++) {
|
|
47905
45073
|
auto src_val = source.GetValue(i);
|
|
47906
45074
|
if (src_val.is_null) {
|
|
47907
45075
|
result.SetValue(i, Value());
|
|
47908
45076
|
continue;
|
|
47909
45077
|
}
|
|
47910
|
-
|
|
45078
|
+
|
|
47911
45079
|
uint64_t enum_idx;
|
|
47912
45080
|
switch (enum_physical_type) {
|
|
47913
45081
|
case PhysicalType::UINT8:
|
|
@@ -47922,7 +45090,7 @@ void EnumToVarchar(Vector &source, Vector &result, idx_t count, PhysicalType enu
|
|
|
47922
45090
|
default:
|
|
47923
45091
|
throw InternalException("ENUM can only have unsigned integers (except UINT64) as physical types");
|
|
47924
45092
|
}
|
|
47925
|
-
|
|
45093
|
+
res_vec_ptr[i] = str_vec_ptr[enum_idx];
|
|
47926
45094
|
}
|
|
47927
45095
|
}
|
|
47928
45096
|
|
|
@@ -69885,9 +67053,14 @@ protected:
|
|
|
69885
67053
|
} // namespace duckdb
|
|
69886
67054
|
|
|
69887
67055
|
|
|
67056
|
+
|
|
69888
67057
|
namespace duckdb {
|
|
69889
67058
|
|
|
69890
67059
|
unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalExport &op) {
|
|
67060
|
+
auto &config = DBConfig::GetConfig(context);
|
|
67061
|
+
if (!config.enable_external_access) {
|
|
67062
|
+
throw PermissionException("Export is disabled through configuration");
|
|
67063
|
+
}
|
|
69891
67064
|
auto export_node = make_unique<PhysicalExport>(op.types, op.function, move(op.copy_info), op.estimated_cardinality,
|
|
69892
67065
|
op.exported_tables);
|
|
69893
67066
|
// plan the underlying copy statements, if any
|
|
@@ -81434,6 +78607,7 @@ void PragmaFunctions::RegisterFunction(BuiltinFunctions &set) {
|
|
|
81434
78607
|
|
|
81435
78608
|
|
|
81436
78609
|
|
|
78610
|
+
|
|
81437
78611
|
namespace duckdb {
|
|
81438
78612
|
|
|
81439
78613
|
string PragmaTableInfo(ClientContext &context, const FunctionParameters ¶meters) {
|
|
@@ -81474,6 +78648,10 @@ string PragmaVersion(ClientContext &context, const FunctionParameters ¶meter
|
|
|
81474
78648
|
}
|
|
81475
78649
|
|
|
81476
78650
|
string PragmaImportDatabase(ClientContext &context, const FunctionParameters ¶meters) {
|
|
78651
|
+
auto &config = DBConfig::GetConfig(context);
|
|
78652
|
+
if (!config.enable_external_access) {
|
|
78653
|
+
throw PermissionException("Import is disabled through configuration");
|
|
78654
|
+
}
|
|
81477
78655
|
auto &fs = FileSystem::GetFileSystem(context);
|
|
81478
78656
|
auto *opener = FileSystem::GetFileOpener(context);
|
|
81479
78657
|
|
|
@@ -97084,6 +94262,7 @@ void CSVCopyFunction::RegisterFunction(BuiltinFunctions &set) {
|
|
|
97084
94262
|
|
|
97085
94263
|
|
|
97086
94264
|
|
|
94265
|
+
|
|
97087
94266
|
namespace duckdb {
|
|
97088
94267
|
|
|
97089
94268
|
struct GlobFunctionBindData : public TableFunctionData {
|
|
@@ -97095,6 +94274,10 @@ static unique_ptr<FunctionData> GlobFunctionBind(ClientContext &context, vector<
|
|
|
97095
94274
|
vector<LogicalType> &input_table_types,
|
|
97096
94275
|
vector<string> &input_table_names, vector<LogicalType> &return_types,
|
|
97097
94276
|
vector<string> &names) {
|
|
94277
|
+
auto &config = DBConfig::GetConfig(context);
|
|
94278
|
+
if (!config.enable_external_access) {
|
|
94279
|
+
throw PermissionException("Globbing is disabled through configuration");
|
|
94280
|
+
}
|
|
97098
94281
|
auto result = make_unique<GlobFunctionBindData>();
|
|
97099
94282
|
auto &fs = FileSystem::GetFileSystem(context);
|
|
97100
94283
|
result->files = fs.Glob(inputs[0].str_value);
|
|
@@ -97795,42 +94978,6 @@ void BuiltinFunctions::RegisterTableFunctions() {
|
|
|
97795
94978
|
|
|
97796
94979
|
|
|
97797
94980
|
|
|
97798
|
-
//===----------------------------------------------------------------------===//
|
|
97799
|
-
// DuckDB
|
|
97800
|
-
//
|
|
97801
|
-
// duckdb/parser/expression/constant_expression.hpp
|
|
97802
|
-
//
|
|
97803
|
-
//
|
|
97804
|
-
//===----------------------------------------------------------------------===//
|
|
97805
|
-
|
|
97806
|
-
|
|
97807
|
-
|
|
97808
|
-
|
|
97809
|
-
|
|
97810
|
-
|
|
97811
|
-
namespace duckdb {
|
|
97812
|
-
|
|
97813
|
-
//! ConstantExpression represents a constant value in the query
|
|
97814
|
-
class ConstantExpression : public ParsedExpression {
|
|
97815
|
-
public:
|
|
97816
|
-
explicit ConstantExpression(Value val);
|
|
97817
|
-
|
|
97818
|
-
//! The constant value referenced
|
|
97819
|
-
Value value;
|
|
97820
|
-
|
|
97821
|
-
public:
|
|
97822
|
-
string ToString() const override;
|
|
97823
|
-
|
|
97824
|
-
static bool Equals(const ConstantExpression *a, const ConstantExpression *b);
|
|
97825
|
-
hash_t Hash() const override;
|
|
97826
|
-
|
|
97827
|
-
unique_ptr<ParsedExpression> Copy() const override;
|
|
97828
|
-
|
|
97829
|
-
void Serialize(Serializer &serializer) override;
|
|
97830
|
-
static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
|
|
97831
|
-
};
|
|
97832
|
-
|
|
97833
|
-
} // namespace duckdb
|
|
97834
94981
|
|
|
97835
94982
|
|
|
97836
94983
|
//===----------------------------------------------------------------------===//
|
|
@@ -97885,6 +95032,10 @@ static unique_ptr<FunctionData> ReadCSVBind(ClientContext &context, vector<Value
|
|
|
97885
95032
|
unordered_map<string, Value> &named_parameters,
|
|
97886
95033
|
vector<LogicalType> &input_table_types, vector<string> &input_table_names,
|
|
97887
95034
|
vector<LogicalType> &return_types, vector<string> &names) {
|
|
95035
|
+
auto &config = DBConfig::GetConfig(context);
|
|
95036
|
+
if (!config.enable_external_access) {
|
|
95037
|
+
throw PermissionException("Scanning CSV files is disabled through configuration");
|
|
95038
|
+
}
|
|
97888
95039
|
auto result = make_unique<ReadCSVData>();
|
|
97889
95040
|
auto &options = result->options;
|
|
97890
95041
|
|
|
@@ -100920,21 +98071,26 @@ static vector<TestType> GetTestTypes() {
|
|
|
100920
98071
|
Value("\\x00\\x00\\x00a"));
|
|
100921
98072
|
|
|
100922
98073
|
// enums
|
|
100923
|
-
|
|
100924
|
-
|
|
100925
|
-
|
|
100926
|
-
|
|
98074
|
+
Vector small_enum(LogicalType::VARCHAR, 2);
|
|
98075
|
+
auto small_enum_ptr = FlatVector::GetData<string_t>(small_enum);
|
|
98076
|
+
small_enum_ptr[0] = StringVector::AddStringOrBlob(small_enum, "DUCK_DUCK_ENUM");
|
|
98077
|
+
small_enum_ptr[1] = StringVector::AddStringOrBlob(small_enum, "GOOSE");
|
|
98078
|
+
result.emplace_back(LogicalType::ENUM("small_enum", small_enum, 2), "small_enum");
|
|
98079
|
+
|
|
98080
|
+
Vector medium_enum(LogicalType::VARCHAR, 300);
|
|
98081
|
+
auto medium_enum_ptr = FlatVector::GetData<string_t>(medium_enum);
|
|
100927
98082
|
for (idx_t i = 0; i < 300; i++) {
|
|
100928
|
-
medium_enum
|
|
98083
|
+
medium_enum_ptr[i] = StringVector::AddStringOrBlob(medium_enum, string("enum_") + to_string(i));
|
|
100929
98084
|
}
|
|
100930
|
-
result.emplace_back(LogicalType::ENUM("medium_enum", medium_enum), "medium_enum");
|
|
98085
|
+
result.emplace_back(LogicalType::ENUM("medium_enum", medium_enum, 300), "medium_enum");
|
|
100931
98086
|
|
|
100932
98087
|
// this is a big one... not sure if we should push this one here, but it's required for completeness
|
|
100933
|
-
|
|
98088
|
+
Vector large_enum(LogicalType::VARCHAR, 70000);
|
|
98089
|
+
auto large_enum_ptr = FlatVector::GetData<string_t>(large_enum);
|
|
100934
98090
|
for (idx_t i = 0; i < 70000; i++) {
|
|
100935
|
-
large_enum
|
|
98091
|
+
large_enum_ptr[i] = StringVector::AddStringOrBlob(large_enum, string("enum_") + to_string(i));
|
|
100936
98092
|
}
|
|
100937
|
-
result.emplace_back(LogicalType::ENUM("large_enum", large_enum), "large_enum");
|
|
98093
|
+
result.emplace_back(LogicalType::ENUM("large_enum", large_enum, 70000), "large_enum");
|
|
100938
98094
|
|
|
100939
98095
|
// arrays
|
|
100940
98096
|
auto int_list_type = LogicalType::LIST(LogicalType::INTEGER);
|
|
@@ -113742,7 +110898,7 @@ const vector<string> ExtensionHelper::PATH_COMPONENTS = {".duckdb", "extensions"
|
|
|
113742
110898
|
void ExtensionHelper::InstallExtension(DatabaseInstance &db, const string &extension, bool force_install) {
|
|
113743
110899
|
auto &config = DBConfig::GetConfig(db);
|
|
113744
110900
|
if (!config.enable_external_access) {
|
|
113745
|
-
throw
|
|
110901
|
+
throw PermissionException("Installing extensions is disabled through configuration");
|
|
113746
110902
|
}
|
|
113747
110903
|
auto &fs = FileSystem::GetFileSystem(db);
|
|
113748
110904
|
|
|
@@ -113881,7 +111037,7 @@ static T LoadFunctionFromDLL(void *dll, const string &function_name, const strin
|
|
|
113881
111037
|
void ExtensionHelper::LoadExternalExtension(DatabaseInstance &db, const string &extension) {
|
|
113882
111038
|
auto &config = DBConfig::GetConfig(db);
|
|
113883
111039
|
if (!config.enable_external_access) {
|
|
113884
|
-
throw
|
|
111040
|
+
throw PermissionException("Loading external extensions is disabled through configuration");
|
|
113885
111041
|
}
|
|
113886
111042
|
auto &fs = FileSystem::GetFileSystem(db);
|
|
113887
111043
|
auto filename = fs.ConvertSeparators(extension);
|
|
@@ -114956,6 +112112,7 @@ void SetArrowFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, co
|
|
|
114956
112112
|
case LogicalTypeId::DOUBLE:
|
|
114957
112113
|
child.format = "g";
|
|
114958
112114
|
break;
|
|
112115
|
+
case LogicalTypeId::UUID:
|
|
114959
112116
|
case LogicalTypeId::VARCHAR:
|
|
114960
112117
|
child.format = "u";
|
|
114961
112118
|
break;
|
|
@@ -115050,6 +112207,29 @@ void SetArrowFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, co
|
|
|
115050
112207
|
SetArrowMapFormat(root_holder, child, type);
|
|
115051
112208
|
break;
|
|
115052
112209
|
}
|
|
112210
|
+
case LogicalTypeId::ENUM: {
|
|
112211
|
+
switch (EnumType::GetPhysicalType(EnumType::GetSize(type))) {
|
|
112212
|
+
case PhysicalType::UINT8:
|
|
112213
|
+
child.format = "C";
|
|
112214
|
+
break;
|
|
112215
|
+
case PhysicalType::UINT16:
|
|
112216
|
+
child.format = "S";
|
|
112217
|
+
break;
|
|
112218
|
+
case PhysicalType::UINT32:
|
|
112219
|
+
child.format = "I";
|
|
112220
|
+
break;
|
|
112221
|
+
default:
|
|
112222
|
+
throw InternalException("Unsupported Enum Internal Type");
|
|
112223
|
+
}
|
|
112224
|
+
root_holder.nested_children.emplace_back();
|
|
112225
|
+
root_holder.nested_children.back().resize(1);
|
|
112226
|
+
root_holder.nested_children_ptr.emplace_back();
|
|
112227
|
+
root_holder.nested_children_ptr.back().push_back(&root_holder.nested_children.back()[0]);
|
|
112228
|
+
InitializeChild(root_holder.nested_children.back()[0]);
|
|
112229
|
+
child.dictionary = root_holder.nested_children_ptr.back()[0];
|
|
112230
|
+
child.dictionary->format = "u";
|
|
112231
|
+
break;
|
|
112232
|
+
}
|
|
115053
112233
|
default:
|
|
115054
112234
|
throw InternalException("Unsupported Arrow type " + type.ToString());
|
|
115055
112235
|
}
|
|
@@ -117755,10 +114935,11 @@ Value DisabledOptimizersSetting::GetSetting(ClientContext &context) {
|
|
|
117755
114935
|
// Enable External Access
|
|
117756
114936
|
//===--------------------------------------------------------------------===//
|
|
117757
114937
|
void EnableExternalAccessSetting::SetGlobal(DatabaseInstance *db, DBConfig &config, const Value &input) {
|
|
117758
|
-
|
|
114938
|
+
auto new_value = input.GetValue<bool>();
|
|
114939
|
+
if (db && new_value) {
|
|
117759
114940
|
throw InvalidInputException("Cannot change enable_external_access setting while database is running");
|
|
117760
114941
|
}
|
|
117761
|
-
config.enable_external_access =
|
|
114942
|
+
config.enable_external_access = new_value;
|
|
117762
114943
|
}
|
|
117763
114944
|
|
|
117764
114945
|
Value EnableExternalAccessSetting::GetSetting(ClientContext &context) {
|
|
@@ -124799,8 +121980,11 @@ bool AreMatchesPossible(LogicalType &left, LogicalType &right) {
|
|
|
124799
121980
|
small_enum = &right;
|
|
124800
121981
|
big_enum = &left;
|
|
124801
121982
|
}
|
|
124802
|
-
auto string_vec = EnumType::GetValuesInsertOrder(*small_enum);
|
|
124803
|
-
|
|
121983
|
+
auto &string_vec = EnumType::GetValuesInsertOrder(*small_enum);
|
|
121984
|
+
auto string_vec_ptr = FlatVector::GetData<string_t>(string_vec);
|
|
121985
|
+
auto size = EnumType::GetSize(*small_enum);
|
|
121986
|
+
for (idx_t i = 0; i < size; i++) {
|
|
121987
|
+
auto key = string_vec_ptr[i].GetString();
|
|
124804
121988
|
if (EnumType::GetPos(*big_enum, key) != -1) {
|
|
124805
121989
|
return true;
|
|
124806
121990
|
}
|
|
@@ -134595,6 +131779,22 @@ unique_ptr<AlterInfo> AlterInfo::Deserialize(Deserializer &source) {
|
|
|
134595
131779
|
}
|
|
134596
131780
|
}
|
|
134597
131781
|
|
|
131782
|
+
//===--------------------------------------------------------------------===//
|
|
131783
|
+
// ChangeOwnershipInfo
|
|
131784
|
+
//===--------------------------------------------------------------------===//
|
|
131785
|
+
|
|
131786
|
+
CatalogType ChangeOwnershipInfo::GetCatalogType() {
|
|
131787
|
+
return entry_catalog_type;
|
|
131788
|
+
}
|
|
131789
|
+
|
|
131790
|
+
unique_ptr<AlterInfo> ChangeOwnershipInfo::Copy() const {
|
|
131791
|
+
return make_unique_base<AlterInfo, ChangeOwnershipInfo>(entry_catalog_type, schema, name, owner_schema, owner_name);
|
|
131792
|
+
}
|
|
131793
|
+
|
|
131794
|
+
//===--------------------------------------------------------------------===//
|
|
131795
|
+
// AlterTableInfo
|
|
131796
|
+
//===--------------------------------------------------------------------===//
|
|
131797
|
+
|
|
134598
131798
|
void AlterTableInfo::Serialize(Serializer &serializer) {
|
|
134599
131799
|
AlterInfo::Serialize(serializer);
|
|
134600
131800
|
serializer.Write<AlterTableType>(alter_table_type);
|
|
@@ -134779,7 +131979,6 @@ unique_ptr<AlterInfo> RenameViewInfo::Deserialize(Deserializer &source, string s
|
|
|
134779
131979
|
auto new_name = source.Read<string>();
|
|
134780
131980
|
return make_unique<RenameViewInfo>(move(schema), move(view), new_name);
|
|
134781
131981
|
}
|
|
134782
|
-
|
|
134783
131982
|
} // namespace duckdb
|
|
134784
131983
|
|
|
134785
131984
|
|
|
@@ -140448,6 +137647,8 @@ private:
|
|
|
140448
137647
|
unique_ptr<CreateStatement> TransformCreateFunction(duckdb_libpgquery::PGNode *node);
|
|
140449
137648
|
//! Transform a Postgres duckdb_libpgquery::T_PGCreateEnumStmt node into CreateStatement
|
|
140450
137649
|
unique_ptr<CreateStatement> TransformCreateEnum(duckdb_libpgquery::PGNode *node);
|
|
137650
|
+
//! Transform a Postgres duckdb_libpgquery::T_PGAlterSeqStmt node into CreateStatement
|
|
137651
|
+
unique_ptr<AlterStatement> TransformAlterSequence(duckdb_libpgquery::PGNode *node);
|
|
140451
137652
|
//! Transform a Postgres duckdb_libpgquery::T_PGDropStmt node into a Drop[Table,Schema]Statement
|
|
140452
137653
|
unique_ptr<SQLStatement> TransformDrop(duckdb_libpgquery::PGNode *node);
|
|
140453
137654
|
//! Transform a Postgres duckdb_libpgquery::T_PGInsertStmt node into a InsertStatement
|
|
@@ -145244,6 +142445,67 @@ LogicalType Transformer::TransformTypeName(duckdb_libpgquery::PGTypeName *type_n
|
|
|
145244
142445
|
|
|
145245
142446
|
|
|
145246
142447
|
|
|
142448
|
+
namespace duckdb {
|
|
142449
|
+
|
|
142450
|
+
unique_ptr<AlterStatement> Transformer::TransformAlterSequence(duckdb_libpgquery::PGNode *node) {
|
|
142451
|
+
auto stmt = reinterpret_cast<duckdb_libpgquery::PGAlterSeqStmt *>(node);
|
|
142452
|
+
D_ASSERT(stmt);
|
|
142453
|
+
auto result = make_unique<AlterStatement>();
|
|
142454
|
+
|
|
142455
|
+
auto qname = TransformQualifiedName(stmt->sequence);
|
|
142456
|
+
auto sequence_schema = qname.schema;
|
|
142457
|
+
auto sequence_name = qname.name;
|
|
142458
|
+
|
|
142459
|
+
if (!stmt->options) {
|
|
142460
|
+
throw InternalException("Expected an argument for ALTER SEQUENCE.");
|
|
142461
|
+
}
|
|
142462
|
+
|
|
142463
|
+
duckdb_libpgquery::PGListCell *cell = nullptr;
|
|
142464
|
+
for_each_cell(cell, stmt->options->head) {
|
|
142465
|
+
auto *def_elem = reinterpret_cast<duckdb_libpgquery::PGDefElem *>(cell->data.ptr_value);
|
|
142466
|
+
string opt_name = string(def_elem->defname);
|
|
142467
|
+
|
|
142468
|
+
if (opt_name == "owned_by") {
|
|
142469
|
+
auto val = (duckdb_libpgquery::PGValue *)def_elem->arg;
|
|
142470
|
+
if (!val) {
|
|
142471
|
+
throw InternalException("Expected an argument for option %s", opt_name);
|
|
142472
|
+
}
|
|
142473
|
+
D_ASSERT(val);
|
|
142474
|
+
if (val->type != duckdb_libpgquery::T_PGList) {
|
|
142475
|
+
throw InternalException("Expected a string argument for option %s", opt_name);
|
|
142476
|
+
}
|
|
142477
|
+
auto opt_values = vector<string>();
|
|
142478
|
+
|
|
142479
|
+
auto opt_value_list = (duckdb_libpgquery::PGList *)(val);
|
|
142480
|
+
for (auto c = opt_value_list->head; c != nullptr; c = lnext(c)) {
|
|
142481
|
+
auto target = (duckdb_libpgquery::PGResTarget *)(c->data.ptr_value);
|
|
142482
|
+
opt_values.emplace_back(target->name);
|
|
142483
|
+
}
|
|
142484
|
+
D_ASSERT(!opt_values.empty());
|
|
142485
|
+
string owner_schema = "";
|
|
142486
|
+
string owner_name = "";
|
|
142487
|
+
if (opt_values.size() == 2) {
|
|
142488
|
+
owner_schema = opt_values[0];
|
|
142489
|
+
owner_name = opt_values[1];
|
|
142490
|
+
} else if (opt_values.size() == 1) {
|
|
142491
|
+
owner_schema = DEFAULT_SCHEMA;
|
|
142492
|
+
owner_name = opt_values[0];
|
|
142493
|
+
} else {
|
|
142494
|
+
throw InternalException("Wrong argument for %s. Expected either <schema>.<name> or <name>", opt_name);
|
|
142495
|
+
}
|
|
142496
|
+
auto info = make_unique<ChangeOwnershipInfo>(CatalogType::SEQUENCE_ENTRY, sequence_schema, sequence_name,
|
|
142497
|
+
owner_schema, owner_name);
|
|
142498
|
+
result->info = move(info);
|
|
142499
|
+
} else {
|
|
142500
|
+
throw NotImplementedException("ALTER SEQUENCE option not supported yet!");
|
|
142501
|
+
}
|
|
142502
|
+
}
|
|
142503
|
+
return result;
|
|
142504
|
+
}
|
|
142505
|
+
} // namespace duckdb
|
|
142506
|
+
|
|
142507
|
+
|
|
142508
|
+
|
|
145247
142509
|
|
|
145248
142510
|
|
|
145249
142511
|
namespace duckdb {
|
|
@@ -145447,6 +142709,7 @@ unique_ptr<CopyStatement> Transformer::TransformCopy(duckdb_libpgquery::PGNode *
|
|
|
145447
142709
|
|
|
145448
142710
|
|
|
145449
142711
|
|
|
142712
|
+
|
|
145450
142713
|
namespace duckdb {
|
|
145451
142714
|
|
|
145452
142715
|
vector<string> ReadPgListToString(duckdb_libpgquery::PGList *column_list) {
|
|
@@ -145461,14 +142724,36 @@ vector<string> ReadPgListToString(duckdb_libpgquery::PGList *column_list) {
|
|
|
145461
142724
|
return result;
|
|
145462
142725
|
}
|
|
145463
142726
|
|
|
142727
|
+
Vector ReadPgListToVector(duckdb_libpgquery::PGList *column_list, idx_t &size) {
|
|
142728
|
+
if (!column_list) {
|
|
142729
|
+
Vector result(LogicalType::VARCHAR);
|
|
142730
|
+
return result;
|
|
142731
|
+
}
|
|
142732
|
+
// First we discover the size of this list
|
|
142733
|
+
for (auto c = column_list->head; c != nullptr; c = lnext(c)) {
|
|
142734
|
+
size++;
|
|
142735
|
+
}
|
|
142736
|
+
|
|
142737
|
+
Vector result(LogicalType::VARCHAR, size);
|
|
142738
|
+
auto result_ptr = FlatVector::GetData<string_t>(result);
|
|
142739
|
+
|
|
142740
|
+
size = 0;
|
|
142741
|
+
for (auto c = column_list->head; c != nullptr; c = lnext(c)) {
|
|
142742
|
+
auto target = (duckdb_libpgquery::PGResTarget *)(c->data.ptr_value);
|
|
142743
|
+
result_ptr[size++] = StringVector::AddStringOrBlob(result, target->name);
|
|
142744
|
+
}
|
|
142745
|
+
return result;
|
|
142746
|
+
}
|
|
142747
|
+
|
|
145464
142748
|
unique_ptr<CreateStatement> Transformer::TransformCreateEnum(duckdb_libpgquery::PGNode *node) {
|
|
145465
142749
|
auto stmt = reinterpret_cast<duckdb_libpgquery::PGCreateEnumStmt *>(node);
|
|
145466
142750
|
D_ASSERT(stmt);
|
|
145467
142751
|
auto result = make_unique<CreateStatement>();
|
|
145468
142752
|
auto info = make_unique<CreateTypeInfo>();
|
|
145469
142753
|
info->name = ReadPgListToString(stmt->typeName)[0];
|
|
145470
|
-
|
|
145471
|
-
|
|
142754
|
+
idx_t size = 0;
|
|
142755
|
+
auto ordered_array = ReadPgListToVector(stmt->vals, size);
|
|
142756
|
+
info->type = make_unique<LogicalType>(LogicalType::ENUM(info->name, ordered_array, size));
|
|
145472
142757
|
result->info = move(info);
|
|
145473
142758
|
return result;
|
|
145474
142759
|
}
|
|
@@ -147081,6 +144366,8 @@ unique_ptr<SQLStatement> Transformer::TransformStatement(duckdb_libpgquery::PGNo
|
|
|
147081
144366
|
return TransformLoad(stmt);
|
|
147082
144367
|
case duckdb_libpgquery::T_PGCreateEnumStmt:
|
|
147083
144368
|
return TransformCreateEnum(stmt);
|
|
144369
|
+
case duckdb_libpgquery::T_PGAlterSeqStmt:
|
|
144370
|
+
return TransformAlterSequence(stmt);
|
|
147084
144371
|
default:
|
|
147085
144372
|
throw NotImplementedException(NodetypeToString(stmt->type));
|
|
147086
144373
|
}
|
|
@@ -150920,7 +148207,7 @@ BoundStatement Binder::BindCopyTo(CopyStatement &stmt) {
|
|
|
150920
148207
|
// COPY TO a file
|
|
150921
148208
|
auto &config = DBConfig::GetConfig(context);
|
|
150922
148209
|
if (!config.enable_external_access) {
|
|
150923
|
-
throw
|
|
148210
|
+
throw PermissionException("COPY TO is disabled by configuration");
|
|
150924
148211
|
}
|
|
150925
148212
|
BoundStatement result;
|
|
150926
148213
|
result.types = {LogicalType::BIGINT};
|
|
@@ -150950,7 +148237,7 @@ BoundStatement Binder::BindCopyTo(CopyStatement &stmt) {
|
|
|
150950
148237
|
BoundStatement Binder::BindCopyFrom(CopyStatement &stmt) {
|
|
150951
148238
|
auto &config = DBConfig::GetConfig(context);
|
|
150952
148239
|
if (!config.enable_external_access) {
|
|
150953
|
-
throw
|
|
148240
|
+
throw PermissionException("COPY FROM is disabled by configuration");
|
|
150954
148241
|
}
|
|
150955
148242
|
BoundStatement result;
|
|
150956
148243
|
result.types = {LogicalType::BIGINT};
|
|
@@ -151782,7 +149069,7 @@ BoundStatement Binder::Bind(ExportStatement &stmt) {
|
|
|
151782
149069
|
// COPY TO a file
|
|
151783
149070
|
auto &config = DBConfig::GetConfig(context);
|
|
151784
149071
|
if (!config.enable_external_access) {
|
|
151785
|
-
throw
|
|
149072
|
+
throw PermissionException("COPY TO is disabled through configuration");
|
|
151786
149073
|
}
|
|
151787
149074
|
BoundStatement result;
|
|
151788
149075
|
result.types = {LogicalType::BOOLEAN};
|