| 1 | /* |
| 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | * |
| 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V. |
| 7 | */ |
| 8 | |
| 9 | #ifndef SQL_STORAGE_H |
| 10 | #define SQL_STORAGE_H |
| 11 | |
| 12 | #include "sql_catalog.h" |
| 13 | #include "gdk_logger.h" |
| 14 | #include "store_sequence.h" |
| 15 | |
| 16 | #define COLSIZE 1024 |
| 17 | |
| 18 | #define LOG_OK 0 |
| 19 | #define LOG_ERR (-1) |
| 20 | |
| 21 | #define isTemp(x) (isNew((x)->t)||(x)->t->persistence!=SQL_PERSIST) |
| 22 | #define isTempTable(x) ((x)->persistence!=SQL_PERSIST) |
| 23 | #define isGlobal(x) ((x)->persistence!=SQL_LOCAL_TEMP && \ |
| 24 | (x)->persistence!=SQL_DECLARED_TABLE) |
| 25 | #define isGlobalTemp(x) ((x)->persistence==SQL_GLOBAL_TEMP) |
| 26 | #define isTempSchema(x) (strcmp((x)->base.name, "tmp") == 0 || \ |
| 27 | strcmp((x)->base.name, dt_schema) == 0) |
| 28 | #define isDeclaredTable(x) ((x)->persistence==SQL_DECLARED_TABLE) |
| 29 | |
| 30 | extern int catalog_version; |
| 31 | |
| 32 | typedef enum store_type { |
| 33 | store_bat, /* delta bats, ie multi user read/write */ |
| 34 | store_tst, |
| 35 | store_mem |
| 36 | } store_type; |
| 37 | |
| 38 | #define STORE_READONLY (store_readonly) |
| 39 | |
| 40 | /* builtin functions have ids less than this */ |
| 41 | #define FUNC_OIDS 2000 |
| 42 | |
| 43 | extern sql_trans *gtrans; |
| 44 | extern list *active_sessions; |
| 45 | extern ATOMIC_TYPE store_nr_active; |
| 46 | extern store_type active_store_type; |
| 47 | extern int store_readonly; |
| 48 | extern int store_singleuser; |
| 49 | extern int store_initialized; |
| 50 | |
| 51 | /* relational interface */ |
| 52 | typedef oid (*column_find_row_fptr)(sql_trans *tr, sql_column *c, const void *value, ...); |
| 53 | typedef void *(*column_find_value_fptr)(sql_trans *tr, sql_column *c, oid rid); |
| 54 | typedef int (*column_update_value_fptr)(sql_trans *tr, sql_column *c, oid rid, void *value); |
| 55 | typedef int (*table_insert_fptr)(sql_trans *tr, sql_table *t, ...); |
| 56 | typedef int (*table_delete_fptr)(sql_trans *tr, sql_table *t, oid rid); |
| 57 | typedef int (*table_vacuum_fptr)(sql_trans *tr, sql_table *t); |
| 58 | |
| 59 | typedef struct rids { |
| 60 | BUN cur; |
| 61 | void *data; |
| 62 | } rids; |
| 63 | |
| 64 | typedef struct subrids { |
| 65 | BUN pos; |
| 66 | sqlid id; |
| 67 | void *ids; |
| 68 | void *rids; |
| 69 | } subrids; |
| 70 | |
| 71 | /* returns table rids, for the given select ranges */ |
| 72 | typedef rids *(*rids_select_fptr)( sql_trans *tr, sql_column *key, const void *key_value_low, const void *key_value_high, ...); |
| 73 | |
| 74 | /* order rids by orderby_column values */ |
| 75 | typedef rids *(*rids_orderby_fptr)( sql_trans *tr, rids *r, sql_column *orderby_col); |
| 76 | |
| 77 | typedef rids *(*rids_join_fptr)( sql_trans *tr, rids *l, sql_column *lc, rids *r, sql_column *rc); |
| 78 | typedef rids *(*rids_diff_fptr)( sql_trans *tr, rids *l, sql_column *lc, subrids *r, sql_column *rc); |
| 79 | |
| 80 | /* return table rids from result of table_select, return (-1) when done */ |
| 81 | typedef oid (*rids_next_fptr)(rids *r); |
| 82 | |
| 83 | /* clean up the resources taken by the result of table_select */ |
| 84 | typedef void (*rids_destroy_fptr)(rids *r); |
| 85 | typedef int (*rids_empty_fptr)(rids *r); |
| 86 | |
| 87 | typedef subrids *(*subrids_create_fptr)( sql_trans *tr, rids *l, sql_column *jc1, sql_column *jc2, sql_column *obc); |
| 88 | |
| 89 | /* return table rids from result of table_select, return (-1) when done */ |
| 90 | typedef oid (*subrids_next_fptr)(subrids *r); |
| 91 | typedef sqlid (*subrids_nextid_fptr)(subrids *r); |
| 92 | |
| 93 | /* clean up the resources taken by the result of table_select */ |
| 94 | typedef void (*subrids_destroy_fptr)(subrids *r); |
| 95 | |
| 96 | typedef struct table_functions { |
| 97 | column_find_row_fptr column_find_row; |
| 98 | column_find_value_fptr column_find_value; |
| 99 | column_update_value_fptr column_update_value; |
| 100 | table_insert_fptr table_insert; |
| 101 | table_delete_fptr table_delete; |
| 102 | table_vacuum_fptr table_vacuum; |
| 103 | |
| 104 | rids_select_fptr rids_select; |
| 105 | rids_orderby_fptr rids_orderby; |
| 106 | rids_join_fptr rids_join; |
| 107 | rids_next_fptr rids_next; |
| 108 | rids_destroy_fptr rids_destroy; |
| 109 | rids_empty_fptr rids_empty; |
| 110 | |
| 111 | subrids_create_fptr subrids_create; |
| 112 | subrids_next_fptr subrids_next; |
| 113 | subrids_nextid_fptr subrids_nextid; |
| 114 | subrids_destroy_fptr subrids_destroy; |
| 115 | rids_diff_fptr rids_diff; |
| 116 | } table_functions; |
| 117 | |
| 118 | sqlstore_export table_functions table_funcs; |
| 119 | |
| 120 | /* delta table setup (ie readonly col + ins + upd + del) |
| 121 | -- binds for column,idx (rdonly, inserts, updates) and delets |
| 122 | */ |
| 123 | typedef void *(*bind_col_fptr) (sql_trans *tr, sql_column *c, int access); |
| 124 | typedef void *(*bind_idx_fptr) (sql_trans *tr, sql_idx *i, int access); |
| 125 | typedef void *(*bind_del_fptr) (sql_trans *tr, sql_table *t, int access); |
| 126 | |
| 127 | /* |
| 128 | -- append/update to columns and indices |
| 129 | */ |
| 130 | typedef int (*append_col_fptr) (sql_trans *tr, sql_column *c, void *d, int t); |
| 131 | typedef int (*append_idx_fptr) (sql_trans *tr, sql_idx *i, void *d, int t); |
| 132 | typedef int (*update_col_fptr) (sql_trans *tr, sql_column *c, void *tids, void *d, int t); |
| 133 | typedef int (*update_idx_fptr) (sql_trans *tr, sql_idx *i, void *tids, void *d, int t); |
| 134 | typedef int (*delete_tab_fptr) (sql_trans *tr, sql_table *t, void *d, int tpe); |
| 135 | |
| 136 | /* |
| 137 | -- count number of rows in column (excluding the deletes) |
| 138 | -- check for sortedness |
| 139 | */ |
| 140 | typedef size_t (*count_del_fptr) (sql_trans *tr, sql_table *t); |
| 141 | typedef size_t (*count_upd_fptr) (sql_trans *tr, sql_table *t); |
| 142 | typedef size_t (*count_col_fptr) (sql_trans *tr, sql_column *c, int all /* all or new only */); |
| 143 | typedef size_t (*count_col_upd_fptr) (sql_trans *tr, sql_column *c); |
| 144 | typedef size_t (*count_idx_fptr) (sql_trans *tr, sql_idx *i, int all /* all or new only */); |
| 145 | typedef size_t (*dcount_col_fptr) (sql_trans *tr, sql_column *c); |
| 146 | typedef int (*prop_col_fptr) (sql_trans *tr, sql_column *c); |
| 147 | |
| 148 | /* |
| 149 | -- create the necessary storage resources for columns, indices and tables |
| 150 | -- returns LOG_OK, LOG_ERR |
| 151 | */ |
| 152 | typedef int (*create_col_fptr) (sql_trans *tr, sql_column *c); |
| 153 | typedef int (*create_idx_fptr) (sql_trans *tr, sql_idx *i); |
| 154 | typedef int (*create_del_fptr) (sql_trans *tr, sql_table *t); |
| 155 | |
| 156 | /* |
| 157 | -- upgrade the necessary storage resources for columns, indices and tables |
| 158 | -- needed for the upgrade of the logger structure (ie user tables are |
| 159 | -- now stored using the object ids, no longer the names). This allows |
| 160 | -- renames. |
| 161 | -- returns LOG_OK, LOG_ERR |
| 162 | */ |
| 163 | typedef int (*upgrade_col_fptr) (sql_column *c); |
| 164 | typedef int (*upgrade_idx_fptr) (sql_idx *i); |
| 165 | typedef int (*upgrade_del_fptr) (sql_table *t); |
| 166 | |
| 167 | /* |
| 168 | -- duplicate the necessary storage resources for columns, indices and tables |
| 169 | -- returns LOG_OK, LOG_ERR |
| 170 | */ |
| 171 | typedef int (*dup_col_fptr) (sql_trans *tr, sql_column *oc, sql_column *c); |
| 172 | typedef int (*dup_idx_fptr) (sql_trans *tr, sql_idx *oi, sql_idx *i ); |
| 173 | typedef int (*dup_del_fptr) (sql_trans *tr, sql_table *ot, sql_table *t); |
| 174 | |
| 175 | /* |
| 176 | -- free the storage resources for columns, indices and tables |
| 177 | -- returns LOG_OK, LOG_ERR |
| 178 | */ |
| 179 | typedef int (*destroy_col_fptr) (sql_trans *tr, sql_column *c); |
| 180 | typedef int (*destroy_idx_fptr) (sql_trans *tr, sql_idx *i); |
| 181 | typedef int (*destroy_del_fptr) (sql_trans *tr, sql_table *t); |
| 182 | |
| 183 | /* |
| 184 | -- clear any storage resources for columns, indices and tables |
| 185 | -- returns number of removed tuples |
| 186 | */ |
| 187 | typedef BUN (*clear_col_fptr) (sql_trans *tr, sql_column *c); |
| 188 | typedef BUN (*clear_idx_fptr) (sql_trans *tr, sql_idx *i); |
| 189 | typedef BUN (*clear_del_fptr) (sql_trans *tr, sql_table *t); |
| 190 | |
| 191 | /* |
| 192 | -- update_table rollforward the changes made from table ft to table tt |
| 193 | -- returns LOG_OK, LOG_ERR |
| 194 | */ |
| 195 | typedef int (*update_table_fptr) (sql_trans *tr, sql_table *ft, sql_table *tt); |
| 196 | |
| 197 | /* |
| 198 | -- gtrans_update push ibats and ubats |
| 199 | -- returns LOG_OK, LOG_ERR |
| 200 | */ |
| 201 | typedef int (*gtrans_update_fptr) (sql_trans *tr); |
| 202 | |
| 203 | /* |
| 204 | -- handle inserts and updates of columns and indices |
| 205 | -- returns LOG_OK, LOG_ERR |
| 206 | */ |
| 207 | typedef int (*col_ins_fptr) (sql_trans *tr, sql_column *c, void *data); |
| 208 | typedef int (*col_upd_fptr) (sql_trans *tr, sql_column *c, void *rows, void *data); |
| 209 | typedef int (*idx_ins_fptr) (sql_trans *tr, sql_idx *c, void *data); |
| 210 | typedef int (*idx_upd_fptr) (sql_trans *tr, sql_idx *c, void *rows, void *data); |
| 211 | /* |
| 212 | -- handle deletes |
| 213 | -- returns LOG_OK, LOG_ERR |
| 214 | */ |
| 215 | typedef int (*del_fptr) (sql_trans *tr, sql_table *c, void *rows); |
| 216 | typedef int (*snapshot_fptr) ( sql_table *t ); |
| 217 | typedef int (*cleanup_fptr) (); |
| 218 | |
| 219 | /* backing struct for this interface */ |
| 220 | typedef struct store_functions { |
| 221 | |
| 222 | bind_col_fptr bind_col; |
| 223 | bind_idx_fptr bind_idx; |
| 224 | bind_del_fptr bind_del; |
| 225 | |
| 226 | append_col_fptr append_col; |
| 227 | append_idx_fptr append_idx; |
| 228 | update_col_fptr update_col; |
| 229 | update_idx_fptr update_idx; |
| 230 | delete_tab_fptr delete_tab; |
| 231 | |
| 232 | count_del_fptr count_del; |
| 233 | count_upd_fptr count_upd; |
| 234 | count_col_fptr count_col; |
| 235 | count_col_upd_fptr count_col_upd; |
| 236 | count_idx_fptr count_idx; |
| 237 | dcount_col_fptr dcount_col; |
| 238 | prop_col_fptr sorted_col; |
| 239 | prop_col_fptr double_elim_col; /* varsize col with double elimination */ |
| 240 | |
| 241 | create_col_fptr create_col; |
| 242 | create_idx_fptr create_idx; |
| 243 | create_del_fptr create_del; |
| 244 | |
| 245 | upgrade_col_fptr upgrade_col; |
| 246 | upgrade_idx_fptr upgrade_idx; |
| 247 | upgrade_del_fptr upgrade_del; |
| 248 | |
| 249 | dup_col_fptr dup_col; |
| 250 | dup_idx_fptr dup_idx; |
| 251 | dup_del_fptr dup_del; |
| 252 | |
| 253 | destroy_col_fptr destroy_col; |
| 254 | destroy_idx_fptr destroy_idx; |
| 255 | destroy_del_fptr destroy_del; |
| 256 | |
| 257 | clear_col_fptr clear_col; |
| 258 | clear_idx_fptr clear_idx; |
| 259 | clear_del_fptr clear_del; |
| 260 | |
| 261 | /* functions for logging */ |
| 262 | create_col_fptr log_create_col; |
| 263 | create_idx_fptr log_create_idx; |
| 264 | create_del_fptr log_create_del; |
| 265 | |
| 266 | destroy_col_fptr log_destroy_col; |
| 267 | destroy_idx_fptr log_destroy_idx; |
| 268 | destroy_del_fptr log_destroy_del; |
| 269 | |
| 270 | /* functions for snapshots */ |
| 271 | create_col_fptr snapshot_create_col; |
| 272 | create_idx_fptr snapshot_create_idx; |
| 273 | create_del_fptr snapshot_create_del; |
| 274 | |
| 275 | destroy_col_fptr snapshot_destroy_col; |
| 276 | destroy_idx_fptr snapshot_destroy_idx; |
| 277 | destroy_del_fptr snapshot_destroy_del; |
| 278 | |
| 279 | snapshot_fptr save_snapshot; |
| 280 | |
| 281 | /* rollforward the changes, first snapshot, then log and finaly apply */ |
| 282 | update_table_fptr snapshot_table; |
| 283 | update_table_fptr log_table; |
| 284 | update_table_fptr update_table; |
| 285 | gtrans_update_fptr gtrans_update; |
| 286 | gtrans_update_fptr gtrans_minmax; |
| 287 | |
| 288 | col_ins_fptr col_ins; |
| 289 | col_upd_fptr col_upd; |
| 290 | |
| 291 | idx_ins_fptr idx_ins; |
| 292 | idx_upd_fptr idx_upd; |
| 293 | |
| 294 | del_fptr del; |
| 295 | |
| 296 | cleanup_fptr cleanup; |
| 297 | } store_functions; |
| 298 | |
| 299 | sqlstore_export store_functions store_funcs; |
| 300 | |
| 301 | typedef int (*logger_create_fptr) (int debug, const char *logdir, int catalog_version); |
| 302 | |
| 303 | typedef void (*logger_destroy_fptr) (void); |
| 304 | typedef int (*logger_restart_fptr) (void); |
| 305 | typedef int (*logger_cleanup_fptr) (void); |
| 306 | typedef void (*logger_with_ids_fptr) (void); |
| 307 | |
| 308 | typedef int (*logger_changes_fptr)(void); |
| 309 | typedef int (*logger_get_sequence_fptr) (int seq, lng *id); |
| 310 | typedef lng (*logger_read_last_transaction_id_fptr)(void); |
| 311 | typedef lng (*logger_get_transaction_drift_fptr)(void); |
| 312 | |
| 313 | typedef int (*log_isnew_fptr)(void); |
| 314 | typedef bool (*log_needs_update_fptr)(void); |
| 315 | typedef int (*log_tstart_fptr) (void); |
| 316 | typedef int (*log_tend_fptr) (void); |
| 317 | typedef int (*log_sequence_fptr) (int seq, lng id); |
| 318 | |
| 319 | /* |
| 320 | -- List which parts of which files must be included in a hot snapshot. |
| 321 | -- This is written to the given stream in the following format: |
| 322 | -- - The first line is the absolute path of the db dir. All other paths |
| 323 | -- are relative to this. |
| 324 | -- - Every other line is either "c %ld %s\n" or "w %ld %s\n". The long |
| 325 | -- is always the number of bytes to write. The %s is the relative path of the |
| 326 | -- destination. For "c" lines (copy), it is also the relative path of the |
| 327 | -- source file. For "w" lines (write), the %ld bytes to write follow directly |
| 328 | -- after the newline. |
| 329 | -- Using a stream (buffer) instead of a list data structure simplifies debugging |
| 330 | -- and avoids a lot of tiny allocations and pointer manipulations. |
| 331 | */ |
| 332 | typedef gdk_return (*logger_get_snapshot_files_fptr)(stream *plan); |
| 333 | |
| 334 | typedef void *(*log_find_table_value_fptr)(const char *, const char *, const void *, ...); |
| 335 | typedef struct logger_functions { |
| 336 | logger_create_fptr create; |
| 337 | logger_destroy_fptr destroy; |
| 338 | logger_restart_fptr restart; |
| 339 | logger_cleanup_fptr cleanup; |
| 340 | logger_with_ids_fptr with_ids; |
| 341 | |
| 342 | logger_changes_fptr changes; |
| 343 | logger_get_sequence_fptr get_sequence; |
| 344 | logger_read_last_transaction_id_fptr read_last_transaction_id; |
| 345 | logger_get_transaction_drift_fptr get_transaction_drift; |
| 346 | |
| 347 | logger_get_snapshot_files_fptr get_snapshot_files; |
| 348 | |
| 349 | log_isnew_fptr log_isnew; |
| 350 | log_needs_update_fptr log_needs_update; |
| 351 | log_tstart_fptr log_tstart; |
| 352 | log_tend_fptr log_tend; |
| 353 | log_sequence_fptr log_sequence; |
| 354 | log_find_table_value_fptr log_find_table_value; |
| 355 | } logger_functions; |
| 356 | |
| 357 | sqlstore_export logger_functions logger_funcs; |
| 358 | |
| 359 | /* we need to add an interface for result_tables later */ |
| 360 | |
| 361 | extern res_table *res_table_create(sql_trans *tr, int res_id, oid query_id, int nr_cols, sql_query_t querytype, res_table *next, void *order); |
| 362 | extern res_col *res_col_create(sql_trans *tr, res_table *t, const char *tn, const char *name, const char *typename, int digits, int scale, int mtype, void *v); |
| 363 | |
| 364 | extern void res_table_destroy(res_table *t); |
| 365 | |
| 366 | extern res_table *res_tables_remove(res_table *results, res_table *t); |
| 367 | extern void res_tables_destroy(res_table *results); |
| 368 | extern res_table *res_tables_find(res_table *results, int res_id); |
| 369 | |
| 370 | extern int store_init(int debug, store_type store, int readonly, int singleuser, backend_stack stk); |
| 371 | extern void store_exit(void); |
| 372 | |
| 373 | extern int store_apply_deltas(bool locked); |
| 374 | extern void store_flush_log(void); |
| 375 | extern void store_suspend_log(void); |
| 376 | extern void store_resume_log(void); |
| 377 | extern lng store_hot_snapshot(str tarfile); |
| 378 | |
| 379 | extern void store_manager(void); |
| 380 | extern void idle_manager(void); |
| 381 | |
| 382 | extern void store_lock(void); |
| 383 | extern void store_unlock(void); |
| 384 | extern int store_next_oid(void); |
| 385 | |
| 386 | extern sql_trans *sql_trans_create(backend_stack stk, sql_trans *parent, const char *name, bool try_spare); |
| 387 | extern sql_trans *sql_trans_destroy(sql_trans *tr, bool try_spare); |
| 388 | extern bool sql_trans_validate(sql_trans *tr); |
| 389 | extern int sql_trans_commit(sql_trans *tr); |
| 390 | extern int sql_save_snapshots(sql_trans *tr); |
| 391 | |
| 392 | extern sql_type *sql_trans_create_type(sql_trans *tr, sql_schema *s, const char *sqlname, int digits, int scale, int radix, const char *impl); |
| 393 | extern int sql_trans_drop_type(sql_trans *tr, sql_schema * s, sqlid id, int drop_action); |
| 394 | |
| 395 | extern sql_func *sql_trans_create_func(sql_trans *tr, sql_schema *s, const char *func, list *args, list *res, sql_ftype type, sql_flang lang, const char *mod, const char *impl, const char *query, bit varres, bit vararg, bit system); |
| 396 | |
| 397 | extern int sql_trans_drop_func(sql_trans *tr, sql_schema *s, sqlid id, int drop_action); |
| 398 | extern int sql_trans_drop_all_func(sql_trans *tr, sql_schema *s, list *list_func, int drop_action); |
| 399 | |
| 400 | extern void sql_trans_update_tables(sql_trans *tr, sql_schema *s); |
| 401 | extern void sql_trans_update_schemas(sql_trans *tr); |
| 402 | |
| 403 | extern void reset_functions(sql_trans *tr); |
| 404 | |
| 405 | extern sql_schema *sql_trans_create_schema(sql_trans *tr, const char *name, sqlid auth_id, sqlid owner); |
| 406 | extern sql_schema *sql_trans_rename_schema(sql_trans *tr, sqlid id, const char *new_name); |
| 407 | extern int sql_trans_drop_schema(sql_trans *tr, sqlid id, int drop_action); |
| 408 | |
| 409 | extern sql_table *sql_trans_create_table(sql_trans *tr, sql_schema *s, const char *name, const char *sql, int tt, bit system, int persistence, int commit_action, int sz, bit properties); |
| 410 | |
| 411 | extern int sql_trans_set_partition_table(sql_trans *tr, sql_table *t); |
| 412 | extern sql_table *sql_trans_add_table(sql_trans *tr, sql_table *mt, sql_table *pt); |
| 413 | extern int sql_trans_add_range_partition(sql_trans *tr, sql_table *mt, sql_table *pt, sql_subtype tpe, ptr min, ptr max, int with_nills, int update, sql_part** err); |
| 414 | extern int sql_trans_add_value_partition(sql_trans *tr, sql_table *mt, sql_table *pt, sql_subtype tpe, list* vals, int with_nills, int update, sql_part **err); |
| 415 | |
| 416 | extern sql_table *sql_trans_rename_table(sql_trans *tr, sql_schema *s, sqlid id, const char *new_name); |
| 417 | extern sql_table *sql_trans_set_table_schema(sql_trans *tr, sqlid id, sql_schema *os, sql_schema *ns); |
| 418 | extern sql_table *sql_trans_del_table(sql_trans *tr, sql_table *mt, sql_table *pt, int drop_action); |
| 419 | |
| 420 | extern int sql_trans_drop_table(sql_trans *tr, sql_schema *s, sqlid id, int drop_action); |
| 421 | extern BUN sql_trans_clear_table(sql_trans *tr, sql_table *t); |
| 422 | extern sql_table *sql_trans_alter_access(sql_trans *tr, sql_table *t, sht access); |
| 423 | |
| 424 | extern sql_column *sql_trans_create_column(sql_trans *tr, sql_table *t, const char *name, sql_subtype *tpe); |
| 425 | extern sql_column *sql_trans_rename_column(sql_trans *tr, sql_table *t, const char *old_name, const char *new_name); |
| 426 | extern int sql_trans_drop_column(sql_trans *tr, sql_table *t, sqlid id, int drop_action); |
| 427 | extern sql_column *sql_trans_alter_null(sql_trans *tr, sql_column *col, int isnull); |
| 428 | extern sql_column *sql_trans_alter_default(sql_trans *tr, sql_column *col, char *val); |
| 429 | extern sql_column *sql_trans_alter_storage(sql_trans *tr, sql_column *col, char *storage); |
| 430 | extern int sql_trans_is_sorted(sql_trans *tr, sql_column *col); |
| 431 | extern size_t sql_trans_dist_count(sql_trans *tr, sql_column *col); |
| 432 | extern int sql_trans_ranges(sql_trans *tr, sql_column *col, char **min, char **max); |
| 433 | |
| 434 | extern sql_key *sql_trans_create_ukey(sql_trans *tr, sql_table *t, const char *name, key_type kt); |
| 435 | extern sql_key * sql_trans_key_done(sql_trans *tr, sql_key *k); |
| 436 | |
| 437 | extern sql_fkey *sql_trans_create_fkey(sql_trans *tr, sql_table *t, const char *name, key_type kt, sql_key *rkey, int on_delete, int on_update); |
| 438 | extern sql_key *sql_trans_create_kc(sql_trans *tr, sql_key *k, sql_column *c /*, extra options such as trunc */ ); |
| 439 | extern sql_fkey *sql_trans_create_fkc(sql_trans *tr, sql_fkey *k, sql_column *c /*, extra options such as trunc */ ); |
| 440 | extern int sql_trans_drop_key(sql_trans *tr, sql_schema *s, sqlid id, int drop_action); |
| 441 | |
| 442 | extern sql_idx *sql_trans_create_idx(sql_trans *tr, sql_table *t, const char *name, idx_type it); |
| 443 | extern sql_idx *sql_trans_create_ic(sql_trans *tr, sql_idx * i, sql_column *c /*, extra options such as trunc */ ); |
| 444 | extern int sql_trans_drop_idx(sql_trans *tr, sql_schema *s, sqlid id, int drop_action); |
| 445 | |
| 446 | extern sql_trigger * sql_trans_create_trigger(sql_trans *tr, sql_table *t, const char *name, sht time, sht orientation, sht event, const char *old_name, const char *new_name, const char *condition, const char *statement ); |
| 447 | extern sql_trigger * sql_trans_create_tc(sql_trans *tr, sql_trigger * i, sql_column *c /*, extra options such as trunc */ ); |
| 448 | extern int sql_trans_drop_trigger(sql_trans *tr, sql_schema *s, sqlid id, int drop_action); |
| 449 | |
| 450 | extern sql_sequence *create_sql_sequence(sql_allocator *sa, sql_schema *s, const char *name, lng start, lng min, lng max, lng inc, lng cacheinc, bit cycle); |
| 451 | extern sql_sequence * sql_trans_create_sequence(sql_trans *tr, sql_schema *s, const char *name, lng start, lng min, lng max, lng inc, lng cacheinc, bit cycle, bit bedropped); |
| 452 | extern void sql_trans_drop_sequence(sql_trans *tr, sql_schema *s, sql_sequence *seq, int drop_action); |
| 453 | extern sql_sequence *sql_trans_alter_sequence(sql_trans *tr, sql_sequence *seq, lng min, lng max, lng inc, lng cache, bit cycle); |
| 454 | extern sql_sequence *sql_trans_sequence_restart(sql_trans *tr, sql_sequence *seq, lng start); |
| 455 | extern sql_sequence *sql_trans_seqbulk_restart(sql_trans *tr, seqbulk *sb, lng start); |
| 456 | |
| 457 | extern sql_session * sql_session_create(backend_stack stk, int autocommit); |
| 458 | extern void sql_session_destroy(sql_session *s); |
| 459 | extern int sql_session_reset(sql_session *s, int autocommit); |
| 460 | extern int sql_trans_begin(sql_session *s); |
| 461 | extern void sql_trans_end(sql_session *s); |
| 462 | |
| 463 | extern list* sql_trans_schema_user_dependencies(sql_trans *tr, sqlid schema_id); |
| 464 | extern void sql_trans_create_dependency(sql_trans *tr, sqlid id, sqlid depend_id, sql_dependency depend_type); |
| 465 | extern void sql_trans_drop_dependencies(sql_trans *tr, sqlid depend_id); |
| 466 | extern void sql_trans_drop_dependency(sql_trans *tr, sqlid id, sqlid depend_id, sql_dependency depend_type); |
| 467 | extern list* sql_trans_get_dependencies(sql_trans *tr, sqlid id, sql_dependency depend_type, list *ignore_ids); |
| 468 | extern int sql_trans_get_dependency_type(sql_trans *tr, sqlid depend_id, sql_dependency depend_type); |
| 469 | extern int sql_trans_check_dependency(sql_trans *tr, sqlid id, sqlid depend_id, sql_dependency depend_type); |
| 470 | extern list* sql_trans_owner_schema_dependencies(sql_trans *tr, sqlid id); |
| 471 | |
| 472 | extern sql_table *create_sql_table(sql_allocator *sa, const char *name, sht type, bit system, int persistence, int commit_action, bit properties); |
| 473 | extern sql_column *create_sql_column(sql_allocator *sa, sql_table *t, const char *name, sql_subtype *tpe); |
| 474 | extern sql_ukey *create_sql_ukey(sql_allocator *sa, sql_table *t, const char *nme, key_type kt); |
| 475 | extern sql_fkey *create_sql_fkey(sql_allocator *sa, sql_table *t, const char *nme, key_type kt, sql_key *rkey, int on_delete, int on_update ); |
| 476 | extern sql_key *create_sql_kc(sql_allocator *sa, sql_key *k, sql_column *c); |
| 477 | extern sql_key * key_create_done(sql_allocator *sa, sql_key *k); |
| 478 | |
| 479 | extern sql_idx *create_sql_idx(sql_allocator *sa, sql_table *t, const char *nme, idx_type it); |
| 480 | extern sql_idx *create_sql_ic(sql_allocator *sa, sql_idx *i, sql_column *c); |
| 481 | extern sql_func *create_sql_func(sql_allocator *sa, const char *func, list *args, list *res, sql_ftype type, sql_flang lang, const char *mod, const char *impl, const char *query, bit varres, bit vararg, bit system); |
| 482 | |
| 483 | /* for alter we need to duplicate a table */ |
| 484 | extern sql_table *dup_sql_table(sql_allocator *sa, sql_table *t); |
| 485 | extern void drop_sql_column(sql_table *t, sqlid id, int drop_action); |
| 486 | extern void drop_sql_idx(sql_table *t, sqlid id); |
| 487 | extern void drop_sql_key(sql_table *t, sqlid id, int drop_action); |
| 488 | |
| 489 | extern sql_column *sql_trans_copy_column(sql_trans *tr, sql_table *t, sql_column *c); |
| 490 | extern sql_key *sql_trans_copy_key(sql_trans *tr, sql_table *t, sql_key *k); |
| 491 | extern sql_idx *sql_trans_copy_idx(sql_trans *tr, sql_table *t, sql_idx *i); |
| 492 | extern sql_trigger *sql_trans_copy_trigger(sql_trans *tr, sql_table *t, sql_trigger *tri); |
| 493 | extern sql_part *sql_trans_copy_part(sql_trans *tr, sql_table *t, sql_part *pt); |
| 494 | |
| 495 | extern void (sql_trans *tr, sqlid id); |
| 496 | |
| 497 | #endif /*SQL_STORAGE_H */ |
| 498 | |