1 | //===----------------------------------------------------------------------===// |
2 | // DuckDB |
3 | // |
4 | // duckdb/common/constants.hpp |
5 | // |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #pragma once |
10 | |
11 | #include <cstdlib> |
12 | #include <memory> |
13 | #include <string> |
14 | #include <vector> |
15 | #include <cmath> |
16 | |
17 | namespace duckdb { |
18 | |
19 | //! inline std directives that we use frequently |
20 | using std::move; |
21 | using std::shared_ptr; |
22 | using std::string; |
23 | using std::unique_ptr; |
24 | using data_ptr = unique_ptr<char[]>; |
25 | using std::make_shared; |
26 | using std::vector; |
27 | |
28 | // NOTE: there is a copy of this in the Postgres' parser grammar (gram.y) |
29 | #define DEFAULT_SCHEMA "main" |
30 | #define TEMP_SCHEMA "temp" |
31 | #define INVALID_SCHEMA "" |
32 | |
33 | //! The vector size used in the execution engine |
34 | #ifndef STANDARD_VECTOR_SIZE |
35 | #define STANDARD_VECTOR_SIZE 1024 |
36 | #endif |
37 | |
38 | #if ((STANDARD_VECTOR_SIZE & (STANDARD_VECTOR_SIZE - 1)) != 0) |
39 | #error Vector size should be a power of two |
40 | #endif |
41 | |
42 | //! a saner size_t for loop indices etc |
43 | typedef uint64_t idx_t; |
44 | |
45 | //! The type used for row identifiers |
46 | typedef int64_t row_t; |
47 | |
48 | //! The type used for hashes |
49 | typedef uint64_t hash_t; |
50 | |
51 | //! The value used to signify an invalid index entry |
52 | extern const idx_t INVALID_INDEX; |
53 | |
54 | //! data pointers |
55 | typedef uint8_t data_t; |
56 | typedef data_t *data_ptr_t; |
57 | typedef const data_t *const_data_ptr_t; |
58 | |
59 | //! Type used to represent dates |
60 | typedef int32_t date_t; |
61 | //! Type used to represent time |
62 | typedef int32_t dtime_t; |
63 | //! Type used to represent timestamps |
64 | typedef int64_t timestamp_t; |
65 | //! Type used for the selection vector |
66 | typedef uint16_t sel_t; |
67 | //! Type used for transaction timestamps |
68 | typedef idx_t transaction_t; |
69 | |
70 | //! Type used for column identifiers |
71 | typedef idx_t column_t; |
72 | //! Special value used to signify the ROW ID of a table |
73 | extern const column_t COLUMN_IDENTIFIER_ROW_ID; |
74 | |
75 | //! The maximum row identifier used in tables |
76 | extern const row_t MAX_ROW_ID; |
77 | |
78 | //! Zero selection vector: completely filled with the value 0 [READ ONLY] |
79 | extern const sel_t ZERO_VECTOR[STANDARD_VECTOR_SIZE]; |
80 | |
81 | extern const transaction_t TRANSACTION_ID_START; |
82 | extern const transaction_t MAXIMUM_QUERY_ID; |
83 | extern const transaction_t NOT_DELETED_ID; |
84 | |
85 | extern const double PI; |
86 | |
87 | struct Storage { |
88 | //! The size of a hard disk sector, only really needed for Direct IO |
89 | constexpr static int SECTOR_SIZE = 4096; |
90 | //! Block header size for blocks written to the storage |
91 | constexpr static int = sizeof(uint64_t); |
92 | // Size of a memory slot managed by the StorageManager. This is the quantum of allocation for Blocks on DuckDB. We |
93 | // default to 256KB. (1 << 18) |
94 | constexpr static int BLOCK_ALLOC_SIZE = 262144; |
95 | //! The actual memory space that is available within the blocks |
96 | constexpr static int BLOCK_SIZE = BLOCK_ALLOC_SIZE - BLOCK_HEADER_SIZE; |
97 | //! The size of the headers. This should be small and written more or less atomically by the hard disk. We default |
98 | //! to the page size, which is 4KB. (1 << 12) |
99 | constexpr static int = 4096; |
100 | }; |
101 | |
102 | uint64_t NextPowerOfTwo(uint64_t v); |
103 | |
104 | } // namespace duckdb |
105 | |