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
17namespace duckdb {
18
19//! inline std directives that we use frequently
20using std::move;
21using std::shared_ptr;
22using std::string;
23using std::unique_ptr;
24using data_ptr = unique_ptr<char[]>;
25using std::make_shared;
26using 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
43typedef uint64_t idx_t;
44
45//! The type used for row identifiers
46typedef int64_t row_t;
47
48//! The type used for hashes
49typedef uint64_t hash_t;
50
51//! The value used to signify an invalid index entry
52extern const idx_t INVALID_INDEX;
53
54//! data pointers
55typedef uint8_t data_t;
56typedef data_t *data_ptr_t;
57typedef const data_t *const_data_ptr_t;
58
59//! Type used to represent dates
60typedef int32_t date_t;
61//! Type used to represent time
62typedef int32_t dtime_t;
63//! Type used to represent timestamps
64typedef int64_t timestamp_t;
65//! Type used for the selection vector
66typedef uint16_t sel_t;
67//! Type used for transaction timestamps
68typedef idx_t transaction_t;
69
70//! Type used for column identifiers
71typedef idx_t column_t;
72//! Special value used to signify the ROW ID of a table
73extern const column_t COLUMN_IDENTIFIER_ROW_ID;
74
75//! The maximum row identifier used in tables
76extern const row_t MAX_ROW_ID;
77
78//! Zero selection vector: completely filled with the value 0 [READ ONLY]
79extern const sel_t ZERO_VECTOR[STANDARD_VECTOR_SIZE];
80
81extern const transaction_t TRANSACTION_ID_START;
82extern const transaction_t MAXIMUM_QUERY_ID;
83extern const transaction_t NOT_DELETED_ID;
84
85extern const double PI;
86
87struct 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 BLOCK_HEADER_SIZE = 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 FILE_HEADER_SIZE = 4096;
100};
101
102uint64_t NextPowerOfTwo(uint64_t v);
103
104} // namespace duckdb
105