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
30extern int catalog_version;
31
32typedef 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
43extern sql_trans *gtrans;
44extern list *active_sessions;
45extern ATOMIC_TYPE store_nr_active;
46extern store_type active_store_type;
47extern int store_readonly;
48extern int store_singleuser;
49extern int store_initialized;
50
51/* relational interface */
52typedef oid (*column_find_row_fptr)(sql_trans *tr, sql_column *c, const void *value, ...);
53typedef void *(*column_find_value_fptr)(sql_trans *tr, sql_column *c, oid rid);
54typedef int (*column_update_value_fptr)(sql_trans *tr, sql_column *c, oid rid, void *value);
55typedef int (*table_insert_fptr)(sql_trans *tr, sql_table *t, ...);
56typedef int (*table_delete_fptr)(sql_trans *tr, sql_table *t, oid rid);
57typedef int (*table_vacuum_fptr)(sql_trans *tr, sql_table *t);
58
59typedef struct rids {
60 BUN cur;
61 void *data;
62} rids;
63
64typedef 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 */
72typedef 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 */
75typedef rids *(*rids_orderby_fptr)( sql_trans *tr, rids *r, sql_column *orderby_col);
76
77typedef rids *(*rids_join_fptr)( sql_trans *tr, rids *l, sql_column *lc, rids *r, sql_column *rc);
78typedef 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 */
81typedef oid (*rids_next_fptr)(rids *r);
82
83/* clean up the resources taken by the result of table_select */
84typedef void (*rids_destroy_fptr)(rids *r);
85typedef int (*rids_empty_fptr)(rids *r);
86
87typedef 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 */
90typedef oid (*subrids_next_fptr)(subrids *r);
91typedef sqlid (*subrids_nextid_fptr)(subrids *r);
92
93/* clean up the resources taken by the result of table_select */
94typedef void (*subrids_destroy_fptr)(subrids *r);
95
96typedef 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
118sqlstore_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*/
123typedef void *(*bind_col_fptr) (sql_trans *tr, sql_column *c, int access);
124typedef void *(*bind_idx_fptr) (sql_trans *tr, sql_idx *i, int access);
125typedef void *(*bind_del_fptr) (sql_trans *tr, sql_table *t, int access);
126
127/*
128-- append/update to columns and indices
129*/
130typedef int (*append_col_fptr) (sql_trans *tr, sql_column *c, void *d, int t);
131typedef int (*append_idx_fptr) (sql_trans *tr, sql_idx *i, void *d, int t);
132typedef int (*update_col_fptr) (sql_trans *tr, sql_column *c, void *tids, void *d, int t);
133typedef int (*update_idx_fptr) (sql_trans *tr, sql_idx *i, void *tids, void *d, int t);
134typedef 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 */
140typedef size_t (*count_del_fptr) (sql_trans *tr, sql_table *t);
141typedef size_t (*count_upd_fptr) (sql_trans *tr, sql_table *t);
142typedef size_t (*count_col_fptr) (sql_trans *tr, sql_column *c, int all /* all or new only */);
143typedef size_t (*count_col_upd_fptr) (sql_trans *tr, sql_column *c);
144typedef size_t (*count_idx_fptr) (sql_trans *tr, sql_idx *i, int all /* all or new only */);
145typedef size_t (*dcount_col_fptr) (sql_trans *tr, sql_column *c);
146typedef 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*/
152typedef int (*create_col_fptr) (sql_trans *tr, sql_column *c);
153typedef int (*create_idx_fptr) (sql_trans *tr, sql_idx *i);
154typedef 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*/
163typedef int (*upgrade_col_fptr) (sql_column *c);
164typedef int (*upgrade_idx_fptr) (sql_idx *i);
165typedef 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*/
171typedef int (*dup_col_fptr) (sql_trans *tr, sql_column *oc, sql_column *c);
172typedef int (*dup_idx_fptr) (sql_trans *tr, sql_idx *oi, sql_idx *i );
173typedef 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*/
179typedef int (*destroy_col_fptr) (sql_trans *tr, sql_column *c);
180typedef int (*destroy_idx_fptr) (sql_trans *tr, sql_idx *i);
181typedef 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*/
187typedef BUN (*clear_col_fptr) (sql_trans *tr, sql_column *c);
188typedef BUN (*clear_idx_fptr) (sql_trans *tr, sql_idx *i);
189typedef 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*/
195typedef 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*/
201typedef 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*/
207typedef int (*col_ins_fptr) (sql_trans *tr, sql_column *c, void *data);
208typedef int (*col_upd_fptr) (sql_trans *tr, sql_column *c, void *rows, void *data);
209typedef int (*idx_ins_fptr) (sql_trans *tr, sql_idx *c, void *data);
210typedef 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*/
215typedef int (*del_fptr) (sql_trans *tr, sql_table *c, void *rows);
216typedef int (*snapshot_fptr) ( sql_table *t );
217typedef int (*cleanup_fptr) ();
218
219/* backing struct for this interface */
220typedef 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
299sqlstore_export store_functions store_funcs;
300
301typedef int (*logger_create_fptr) (int debug, const char *logdir, int catalog_version);
302
303typedef void (*logger_destroy_fptr) (void);
304typedef int (*logger_restart_fptr) (void);
305typedef int (*logger_cleanup_fptr) (void);
306typedef void (*logger_with_ids_fptr) (void);
307
308typedef int (*logger_changes_fptr)(void);
309typedef int (*logger_get_sequence_fptr) (int seq, lng *id);
310typedef lng (*logger_read_last_transaction_id_fptr)(void);
311typedef lng (*logger_get_transaction_drift_fptr)(void);
312
313typedef int (*log_isnew_fptr)(void);
314typedef bool (*log_needs_update_fptr)(void);
315typedef int (*log_tstart_fptr) (void);
316typedef int (*log_tend_fptr) (void);
317typedef 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*/
332typedef gdk_return (*logger_get_snapshot_files_fptr)(stream *plan);
333
334typedef void *(*log_find_table_value_fptr)(const char *, const char *, const void *, ...);
335typedef 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
357sqlstore_export logger_functions logger_funcs;
358
359/* we need to add an interface for result_tables later */
360
361extern 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);
362extern 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
364extern void res_table_destroy(res_table *t);
365
366extern res_table *res_tables_remove(res_table *results, res_table *t);
367extern void res_tables_destroy(res_table *results);
368extern res_table *res_tables_find(res_table *results, int res_id);
369
370extern int store_init(int debug, store_type store, int readonly, int singleuser, backend_stack stk);
371extern void store_exit(void);
372
373extern int store_apply_deltas(bool locked);
374extern void store_flush_log(void);
375extern void store_suspend_log(void);
376extern void store_resume_log(void);
377extern lng store_hot_snapshot(str tarfile);
378
379extern void store_manager(void);
380extern void idle_manager(void);
381
382extern void store_lock(void);
383extern void store_unlock(void);
384extern int store_next_oid(void);
385
386extern sql_trans *sql_trans_create(backend_stack stk, sql_trans *parent, const char *name, bool try_spare);
387extern sql_trans *sql_trans_destroy(sql_trans *tr, bool try_spare);
388extern bool sql_trans_validate(sql_trans *tr);
389extern int sql_trans_commit(sql_trans *tr);
390extern int sql_save_snapshots(sql_trans *tr);
391
392extern sql_type *sql_trans_create_type(sql_trans *tr, sql_schema *s, const char *sqlname, int digits, int scale, int radix, const char *impl);
393extern int sql_trans_drop_type(sql_trans *tr, sql_schema * s, sqlid id, int drop_action);
394
395extern 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
397extern int sql_trans_drop_func(sql_trans *tr, sql_schema *s, sqlid id, int drop_action);
398extern int sql_trans_drop_all_func(sql_trans *tr, sql_schema *s, list *list_func, int drop_action);
399
400extern void sql_trans_update_tables(sql_trans *tr, sql_schema *s);
401extern void sql_trans_update_schemas(sql_trans *tr);
402
403extern void reset_functions(sql_trans *tr);
404
405extern sql_schema *sql_trans_create_schema(sql_trans *tr, const char *name, sqlid auth_id, sqlid owner);
406extern sql_schema *sql_trans_rename_schema(sql_trans *tr, sqlid id, const char *new_name);
407extern int sql_trans_drop_schema(sql_trans *tr, sqlid id, int drop_action);
408
409extern 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
411extern int sql_trans_set_partition_table(sql_trans *tr, sql_table *t);
412extern sql_table *sql_trans_add_table(sql_trans *tr, sql_table *mt, sql_table *pt);
413extern 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);
414extern 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
416extern sql_table *sql_trans_rename_table(sql_trans *tr, sql_schema *s, sqlid id, const char *new_name);
417extern sql_table *sql_trans_set_table_schema(sql_trans *tr, sqlid id, sql_schema *os, sql_schema *ns);
418extern sql_table *sql_trans_del_table(sql_trans *tr, sql_table *mt, sql_table *pt, int drop_action);
419
420extern int sql_trans_drop_table(sql_trans *tr, sql_schema *s, sqlid id, int drop_action);
421extern BUN sql_trans_clear_table(sql_trans *tr, sql_table *t);
422extern sql_table *sql_trans_alter_access(sql_trans *tr, sql_table *t, sht access);
423
424extern sql_column *sql_trans_create_column(sql_trans *tr, sql_table *t, const char *name, sql_subtype *tpe);
425extern sql_column *sql_trans_rename_column(sql_trans *tr, sql_table *t, const char *old_name, const char *new_name);
426extern int sql_trans_drop_column(sql_trans *tr, sql_table *t, sqlid id, int drop_action);
427extern sql_column *sql_trans_alter_null(sql_trans *tr, sql_column *col, int isnull);
428extern sql_column *sql_trans_alter_default(sql_trans *tr, sql_column *col, char *val);
429extern sql_column *sql_trans_alter_storage(sql_trans *tr, sql_column *col, char *storage);
430extern int sql_trans_is_sorted(sql_trans *tr, sql_column *col);
431extern size_t sql_trans_dist_count(sql_trans *tr, sql_column *col);
432extern int sql_trans_ranges(sql_trans *tr, sql_column *col, char **min, char **max);
433
434extern sql_key *sql_trans_create_ukey(sql_trans *tr, sql_table *t, const char *name, key_type kt);
435extern sql_key * sql_trans_key_done(sql_trans *tr, sql_key *k);
436
437extern 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);
438extern sql_key *sql_trans_create_kc(sql_trans *tr, sql_key *k, sql_column *c /*, extra options such as trunc */ );
439extern sql_fkey *sql_trans_create_fkc(sql_trans *tr, sql_fkey *k, sql_column *c /*, extra options such as trunc */ );
440extern int sql_trans_drop_key(sql_trans *tr, sql_schema *s, sqlid id, int drop_action);
441
442extern sql_idx *sql_trans_create_idx(sql_trans *tr, sql_table *t, const char *name, idx_type it);
443extern sql_idx *sql_trans_create_ic(sql_trans *tr, sql_idx * i, sql_column *c /*, extra options such as trunc */ );
444extern int sql_trans_drop_idx(sql_trans *tr, sql_schema *s, sqlid id, int drop_action);
445
446extern 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 );
447extern sql_trigger * sql_trans_create_tc(sql_trans *tr, sql_trigger * i, sql_column *c /*, extra options such as trunc */ );
448extern int sql_trans_drop_trigger(sql_trans *tr, sql_schema *s, sqlid id, int drop_action);
449
450extern 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);
451extern 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);
452extern void sql_trans_drop_sequence(sql_trans *tr, sql_schema *s, sql_sequence *seq, int drop_action);
453extern sql_sequence *sql_trans_alter_sequence(sql_trans *tr, sql_sequence *seq, lng min, lng max, lng inc, lng cache, bit cycle);
454extern sql_sequence *sql_trans_sequence_restart(sql_trans *tr, sql_sequence *seq, lng start);
455extern sql_sequence *sql_trans_seqbulk_restart(sql_trans *tr, seqbulk *sb, lng start);
456
457extern sql_session * sql_session_create(backend_stack stk, int autocommit);
458extern void sql_session_destroy(sql_session *s);
459extern int sql_session_reset(sql_session *s, int autocommit);
460extern int sql_trans_begin(sql_session *s);
461extern void sql_trans_end(sql_session *s);
462
463extern list* sql_trans_schema_user_dependencies(sql_trans *tr, sqlid schema_id);
464extern void sql_trans_create_dependency(sql_trans *tr, sqlid id, sqlid depend_id, sql_dependency depend_type);
465extern void sql_trans_drop_dependencies(sql_trans *tr, sqlid depend_id);
466extern void sql_trans_drop_dependency(sql_trans *tr, sqlid id, sqlid depend_id, sql_dependency depend_type);
467extern list* sql_trans_get_dependencies(sql_trans *tr, sqlid id, sql_dependency depend_type, list *ignore_ids);
468extern int sql_trans_get_dependency_type(sql_trans *tr, sqlid depend_id, sql_dependency depend_type);
469extern int sql_trans_check_dependency(sql_trans *tr, sqlid id, sqlid depend_id, sql_dependency depend_type);
470extern list* sql_trans_owner_schema_dependencies(sql_trans *tr, sqlid id);
471
472extern sql_table *create_sql_table(sql_allocator *sa, const char *name, sht type, bit system, int persistence, int commit_action, bit properties);
473extern sql_column *create_sql_column(sql_allocator *sa, sql_table *t, const char *name, sql_subtype *tpe);
474extern sql_ukey *create_sql_ukey(sql_allocator *sa, sql_table *t, const char *nme, key_type kt);
475extern 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 );
476extern sql_key *create_sql_kc(sql_allocator *sa, sql_key *k, sql_column *c);
477extern sql_key * key_create_done(sql_allocator *sa, sql_key *k);
478
479extern sql_idx *create_sql_idx(sql_allocator *sa, sql_table *t, const char *nme, idx_type it);
480extern sql_idx *create_sql_ic(sql_allocator *sa, sql_idx *i, sql_column *c);
481extern 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 */
484extern sql_table *dup_sql_table(sql_allocator *sa, sql_table *t);
485extern void drop_sql_column(sql_table *t, sqlid id, int drop_action);
486extern void drop_sql_idx(sql_table *t, sqlid id);
487extern void drop_sql_key(sql_table *t, sqlid id, int drop_action);
488
489extern sql_column *sql_trans_copy_column(sql_trans *tr, sql_table *t, sql_column *c);
490extern sql_key *sql_trans_copy_key(sql_trans *tr, sql_table *t, sql_key *k);
491extern sql_idx *sql_trans_copy_idx(sql_trans *tr, sql_table *t, sql_idx *i);
492extern sql_trigger *sql_trans_copy_trigger(sql_trans *tr, sql_table *t, sql_trigger *tri);
493extern sql_part *sql_trans_copy_part(sql_trans *tr, sql_table *t, sql_part *pt);
494
495extern void sql_trans_drop_any_comment(sql_trans *tr, sqlid id);
496
497#endif /*SQL_STORAGE_H */
498