| 1 | //===----------------------------------------------------------------------===// |
|---|---|
| 2 | // DuckDB |
| 3 | // |
| 4 | // duckdb/planner/constraints/bound_unique_constraint.hpp |
| 5 | // |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | #include "duckdb/common/unordered_set.hpp" |
| 12 | #include "duckdb/planner/bound_constraint.hpp" |
| 13 | #include "duckdb/common/index_map.hpp" |
| 14 | |
| 15 | namespace duckdb { |
| 16 | |
| 17 | class BoundUniqueConstraint : public BoundConstraint { |
| 18 | public: |
| 19 | static constexpr const ConstraintType TYPE = ConstraintType::UNIQUE; |
| 20 | |
| 21 | public: |
| 22 | BoundUniqueConstraint(vector<LogicalIndex> keys, logical_index_set_t key_set, bool is_primary_key) |
| 23 | : BoundConstraint(ConstraintType::UNIQUE), keys(std::move(keys)), key_set(std::move(key_set)), |
| 24 | is_primary_key(is_primary_key) { |
| 25 | #ifdef DEBUG |
| 26 | D_ASSERT(keys.size() == key_set.size()); |
| 27 | for (auto &key : keys) { |
| 28 | D_ASSERT(key_set.find(key) != key_set.end()); |
| 29 | } |
| 30 | #endif |
| 31 | } |
| 32 | |
| 33 | //! The keys that define the unique constraint |
| 34 | vector<LogicalIndex> keys; |
| 35 | //! The same keys but stored as an unordered set |
| 36 | logical_index_set_t key_set; |
| 37 | //! Whether or not the unique constraint is a primary key |
| 38 | bool is_primary_key; |
| 39 | }; |
| 40 | |
| 41 | } // namespace duckdb |
| 42 |