common_catalog/
consts.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use const_format::concatcp;
16
17pub const SYSTEM_CATALOG_NAME: &str = "system";
18pub const INFORMATION_SCHEMA_NAME: &str = "information_schema";
19pub const PG_CATALOG_NAME: &str = "pg_catalog";
20pub const SYSTEM_CATALOG_TABLE_NAME: &str = "system_catalog";
21pub const DEFAULT_CATALOG_NAME: &str = env!("DEFAULT_CATALOG_NAME");
22pub const DEFAULT_SCHEMA_NAME: &str = "public";
23pub const DEFAULT_PRIVATE_SCHEMA_NAME: &str = concatcp!(DEFAULT_CATALOG_NAME, "_private");
24
25/// Reserves [0,MIN_USER_FLOW_ID) for internal usage.
26/// User defined table id starts from this value.
27pub const MIN_USER_FLOW_ID: u32 = 1024;
28/// Reserves [0,MIN_USER_TABLE_ID) for internal usage.
29/// User defined table id starts from this value.
30pub const MIN_USER_TABLE_ID: u32 = 1024;
31/// the max system table id
32pub const MAX_SYS_TABLE_ID: u32 = MIN_USER_TABLE_ID - 1;
33/// system_catalog table id
34pub const SYSTEM_CATALOG_TABLE_ID: u32 = 0;
35/// scripts table id
36pub const SCRIPTS_TABLE_ID: u32 = 1;
37/// numbers table id
38pub const NUMBERS_TABLE_ID: u32 = 2;
39
40/// ----- Begin of information_schema tables -----
41/// id for information_schema.tables
42pub const INFORMATION_SCHEMA_TABLES_TABLE_ID: u32 = 3;
43/// id for information_schema.columns
44pub const INFORMATION_SCHEMA_COLUMNS_TABLE_ID: u32 = 4;
45/// id for information_schema.engines
46pub const INFORMATION_SCHEMA_ENGINES_TABLE_ID: u32 = 5;
47/// id for information_schema.column_privileges
48pub const INFORMATION_SCHEMA_COLUMN_PRIVILEGES_TABLE_ID: u32 = 6;
49/// id for information_schema.column_statistics
50pub const INFORMATION_SCHEMA_COLUMN_STATISTICS_TABLE_ID: u32 = 7;
51/// id for information_schema.build_info
52pub const INFORMATION_SCHEMA_BUILD_INFO_TABLE_ID: u32 = 8;
53/// id for information_schema.CHARACTER_SETS
54pub const INFORMATION_SCHEMA_CHARACTER_SETS_TABLE_ID: u32 = 9;
55/// id for information_schema.COLLATIONS
56pub const INFORMATION_SCHEMA_COLLATIONS_TABLE_ID: u32 = 10;
57/// id for information_schema.COLLATIONS
58pub const INFORMATION_SCHEMA_COLLATION_CHARACTER_SET_APPLICABILITY_TABLE_ID: u32 = 11;
59/// id for information_schema.CHECK_CONSTRAINTS
60pub const INFORMATION_SCHEMA_CHECK_CONSTRAINTS_TABLE_ID: u32 = 12;
61/// id for information_schema.EVENTS
62pub const INFORMATION_SCHEMA_EVENTS_TABLE_ID: u32 = 13;
63/// id for information_schema.FILES
64pub const INFORMATION_SCHEMA_FILES_TABLE_ID: u32 = 14;
65/// id for information_schema.SCHEMATA
66pub const INFORMATION_SCHEMA_SCHEMATA_TABLE_ID: u32 = 15;
67/// id for information_schema.KEY_COLUMN_USAGE
68pub const INFORMATION_SCHEMA_KEY_COLUMN_USAGE_TABLE_ID: u32 = 16;
69/// id for information_schema.OPTIMIZER_TRACE
70pub const INFORMATION_SCHEMA_OPTIMIZER_TRACE_TABLE_ID: u32 = 17;
71/// id for information_schema.PARAMETERS
72pub const INFORMATION_SCHEMA_PARAMETERS_TABLE_ID: u32 = 18;
73/// id for information_schema.PROFILING
74pub const INFORMATION_SCHEMA_PROFILING_TABLE_ID: u32 = 19;
75/// id for information_schema.REFERENTIAL_CONSTRAINTS
76pub const INFORMATION_SCHEMA_REFERENTIAL_CONSTRAINTS_TABLE_ID: u32 = 20;
77/// id for information_schema.ROUTINES
78pub const INFORMATION_SCHEMA_ROUTINES_TABLE_ID: u32 = 21;
79/// id for information_schema.SCHEMA_PRIVILEGES
80pub const INFORMATION_SCHEMA_SCHEMA_PRIVILEGES_TABLE_ID: u32 = 22;
81/// id for information_schema.TABLE_PRIVILEGES
82pub const INFORMATION_SCHEMA_TABLE_PRIVILEGES_TABLE_ID: u32 = 23;
83/// id for information_schema.TRIGGERS (for mysql)
84pub const INFORMATION_SCHEMA_TRIGGERS_TABLE_ID: u32 = 24;
85/// id for information_schema.GLOBAL_STATUS
86pub const INFORMATION_SCHEMA_GLOBAL_STATUS_TABLE_ID: u32 = 25;
87/// id for information_schema.SESSION_STATUS
88pub const INFORMATION_SCHEMA_SESSION_STATUS_TABLE_ID: u32 = 26;
89/// id for information_schema.RUNTIME_METRICS
90pub const INFORMATION_SCHEMA_RUNTIME_METRICS_TABLE_ID: u32 = 27;
91/// id for information_schema.PARTITIONS
92pub const INFORMATION_SCHEMA_PARTITIONS_TABLE_ID: u32 = 28;
93/// id for information_schema.REGION_PEERS
94pub const INFORMATION_SCHEMA_REGION_PEERS_TABLE_ID: u32 = 29;
95/// id for information_schema.columns
96pub const INFORMATION_SCHEMA_TABLE_CONSTRAINTS_TABLE_ID: u32 = 30;
97/// id for information_schema.cluster_info
98pub const INFORMATION_SCHEMA_CLUSTER_INFO_TABLE_ID: u32 = 31;
99/// id for information_schema.VIEWS
100pub const INFORMATION_SCHEMA_VIEW_TABLE_ID: u32 = 32;
101/// id for information_schema.FLOWS
102pub const INFORMATION_SCHEMA_FLOW_TABLE_ID: u32 = 33;
103/// id for information_schema.procedure_info
104pub const INFORMATION_SCHEMA_PROCEDURE_INFO_TABLE_ID: u32 = 34;
105/// id for information_schema.region_statistics
106pub const INFORMATION_SCHEMA_REGION_STATISTICS_TABLE_ID: u32 = 35;
107/// id for information_schema.process_list
108pub const INFORMATION_SCHEMA_PROCESS_LIST_TABLE_ID: u32 = 36;
109/// id for information_schema.ssts_manifest
110pub const INFORMATION_SCHEMA_SSTS_MANIFEST_TABLE_ID: u32 = 37;
111/// id for information_schema.ssts_storage
112pub const INFORMATION_SCHEMA_SSTS_STORAGE_TABLE_ID: u32 = 38;
113/// id for information_schema.ssts_index_meta
114pub const INFORMATION_SCHEMA_SSTS_INDEX_META_TABLE_ID: u32 = 39;
115
116// ----- End of information_schema tables -----
117
118/// ----- Begin of pg_catalog tables -----
119pub const PG_CATALOG_TABLE_ID_START: u32 = 256;
120// Please leave at 128 table ids for Postgres
121// ----- End of pg_catalog tables -----
122
123pub const MITO_ENGINE: &str = "mito";
124pub const MITO2_ENGINE: &str = "mito2";
125pub const METRIC_ENGINE: &str = "metric";
126
127pub fn default_engine() -> &'static str {
128    MITO_ENGINE
129}
130
131pub const FILE_ENGINE: &str = "file";
132
133pub const SEMANTIC_TYPE_PRIMARY_KEY: &str = "TAG";
134pub const SEMANTIC_TYPE_FIELD: &str = "FIELD";
135pub const SEMANTIC_TYPE_TIME_INDEX: &str = "TIMESTAMP";
136
137pub fn is_readonly_schema(schema: &str) -> bool {
138    matches!(schema, INFORMATION_SCHEMA_NAME)
139}
140
141// ---- special table and fields ----
142pub const TRACE_ID_COLUMN: &str = "trace_id";
143pub const SPAN_ID_COLUMN: &str = "span_id";
144pub const SPAN_NAME_COLUMN: &str = "span_name";
145pub const SERVICE_NAME_COLUMN: &str = "service_name";
146pub const PARENT_SPAN_ID_COLUMN: &str = "parent_span_id";
147pub const TRACE_TABLE_NAME: &str = "opentelemetry_traces";
148pub const TRACE_TABLE_NAME_SESSION_KEY: &str = "trace_table_name";
149// ---- End of special table and fields ----
150
151/// Generate the trace services table name from the trace table name by adding `_services` suffix.
152pub fn trace_services_table_name(trace_table_name: &str) -> String {
153    format!("{}_services", trace_table_name)
154}
155
156/// Generate the trace operations table name from the trace table name by adding `_operations` suffix.
157pub fn trace_operations_table_name(trace_table_name: &str) -> String {
158    format!("{}_operations", trace_table_name)
159}
160// ---- End of special table and fields ----