1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/common/constants.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include <memory>
12#include "duckdb/common/string.hpp"
13#include "duckdb/common/winapi.hpp"
14#include "duckdb/common/unique_ptr.hpp"
15#include "duckdb/common/typedefs.hpp"
16
17namespace duckdb {
18class Serializer;
19class Deserializer;
20
21//! inline std directives that we use frequently
22#ifndef DUCKDB_DEBUG_MOVE
23using std::move;
24#endif
25
26// NOTE: there is a copy of this in the Postgres' parser grammar (gram.y)
27#define DEFAULT_SCHEMA "main"
28#define INVALID_SCHEMA ""
29#define INVALID_CATALOG ""
30#define SYSTEM_CATALOG "system"
31#define TEMP_CATALOG "temp"
32
33DUCKDB_API bool IsInvalidSchema(const string &str);
34DUCKDB_API bool IsInvalidCatalog(const string &str);
35
36//! Special value used to signify the ROW ID of a table
37DUCKDB_API extern const column_t COLUMN_IDENTIFIER_ROW_ID;
38DUCKDB_API bool IsRowIdColumnId(column_t column_id);
39
40//! The maximum row identifier used in tables
41extern const row_t MAX_ROW_ID;
42
43extern const transaction_t TRANSACTION_ID_START;
44extern const transaction_t MAX_TRANSACTION_ID;
45extern const transaction_t MAXIMUM_QUERY_ID;
46extern const transaction_t NOT_DELETED_ID;
47
48extern const double PI;
49
50struct DConstants {
51 //! The value used to signify an invalid index entry
52 static constexpr const idx_t INVALID_INDEX = idx_t(-1);
53};
54
55struct Storage {
56 //! The size of a hard disk sector, only really needed for Direct IO
57 constexpr static int SECTOR_SIZE = 4096;
58 //! Block header size for blocks written to the storage
59 constexpr static int BLOCK_HEADER_SIZE = sizeof(uint64_t);
60 // Size of a memory slot managed by the StorageManager. This is the quantum of allocation for Blocks on DuckDB. We
61 // default to 256KB. (1 << 18)
62 constexpr static int BLOCK_ALLOC_SIZE = 262144;
63 //! The actual memory space that is available within the blocks
64 constexpr static int BLOCK_SIZE = BLOCK_ALLOC_SIZE - BLOCK_HEADER_SIZE;
65 //! The size of the headers. This should be small and written more or less atomically by the hard disk. We default
66 //! to the page size, which is 4KB. (1 << 12)
67 constexpr static int FILE_HEADER_SIZE = 4096;
68};
69
70struct LogicalIndex {
71 explicit LogicalIndex(idx_t index) : index(index) {
72 }
73
74 idx_t index;
75
76 inline bool operator==(const LogicalIndex &rhs) const {
77 return index == rhs.index;
78 };
79 inline bool operator!=(const LogicalIndex &rhs) const {
80 return index != rhs.index;
81 };
82 inline bool operator<(const LogicalIndex &rhs) const {
83 return index < rhs.index;
84 };
85 bool IsValid() {
86 return index != DConstants::INVALID_INDEX;
87 }
88};
89
90struct PhysicalIndex {
91 explicit PhysicalIndex(idx_t index) : index(index) {
92 }
93
94 idx_t index;
95
96 inline bool operator==(const PhysicalIndex &rhs) const {
97 return index == rhs.index;
98 };
99 inline bool operator!=(const PhysicalIndex &rhs) const {
100 return index != rhs.index;
101 };
102 inline bool operator<(const PhysicalIndex &rhs) const {
103 return index < rhs.index;
104 };
105 bool IsValid() {
106 return index != DConstants::INVALID_INDEX;
107 }
108};
109
110DUCKDB_API bool IsPowerOfTwo(uint64_t v);
111DUCKDB_API uint64_t NextPowerOfTwo(uint64_t v);
112DUCKDB_API uint64_t PreviousPowerOfTwo(uint64_t v);
113
114} // namespace duckdb
115