File: sqlcmps.h

package info (click to toggle)
virtuoso-opensource 6.1.6+dfsg2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 260,992 kB
  • ctags: 125,220
  • sloc: ansic: 652,748; sql: 458,419; xml: 282,834; java: 61,031; sh: 40,031; cpp: 36,890; cs: 25,240; php: 12,692; yacc: 9,523; lex: 7,018; makefile: 6,157; jsp: 4,484; awk: 1,643; perl: 1,013; ruby: 1,003; python: 326
file content (649 lines) | stat: -rw-r--r-- 22,933 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
/*
 *  sqlcmps.h
 *
 *  $Id$
 *
 *  SQL Compiler Data Structures
 *
 *  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 *  project.
 *
 *  Copyright (C) 1998-2012 OpenLink Software
 *
 *  This project is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; only version 2 of the License, dated June 1991.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 *
 */

#ifndef _SQLCMPS_H
#define _SQLCMPS_H

#define MAX_REMOTE_TEXT_SZ 20000

typedef struct comp_table_t
  {
    struct sql_comp_s *	ct_sc;
    caddr_t		ct_name;
    caddr_t		ct_prefix;
    caddr_t		ct_vdb_prefix;  /* fictional prefix for vdb tables in
					 * generated code */
    int			ct_is_vdb_dml; /* if table of update/delete in vdb */
    table_source_t *	ct_ts;
    remote_table_source_t *ct_rts;
    dbe_table_t *	ct_table;
    dbe_key_t *		ct_index;
    dk_set_t		ct_out_crrs;
    dk_set_t		ct_out_cols;
    dk_set_t		ct_col_preds;
    dk_set_t		ct_rlocal_preds; /* preds resolved locally on a remote
					    table */
    dk_set_t		ct_non_col_preds;
    dk_set_t		ct_join_preds;	/* if explicit JOIN cond */
    dk_set_t		ct_derived_preds; /* predicates moved into derived from
					     containing WHERE */
    ST *		ct_join_cond;
    dk_set_t		ct_precompute;
    dk_set_t		ct_after_test;
    dk_set_t		ct_after_join_test;
    ST *		ct_derived;	/* select_stmt tree of derived table
					   or view */
    int			ct_generated;
    int			ct_is_unique;
    dk_set_t		ct_order_cols;
    int			ct_order;
    ST *		ct_r_funrefs;
    dk_set_t		ct_fused_cts;  /* remote cts on same dsn handled in
					  same remote stmt */
    char		ct_is_outer;
    oid_t		ct_u_id; /* uid/gid of the view owner if table from view, else those of the user */
    oid_t		ct_g_id;

    struct predicate_s *	ct_ancestor_pred;
    char		ct_ancestor_order;
    char		ct_ancestor_refd;  /* mist join to main row if driving is non pk even if no other main row refs */

    struct predicate_s *	ct_text_pred;
    struct predicate_s *	ct_xpath_pred;
    char		ct_is_text_order;
    char		ct_text_only;
    data_source_t *	ct_text_node;
    data_source_t *	ct_xpath_node;
    state_slot_t *	ct_text_score_ssl;
    state_slot_t *	ct_main_range_out_ssl;	/* Only ranges in main text, e.g. for compatibility with existing applications. */
    state_slot_t *	ct_attr_range_out_ssl;	/* Only ranges in attributes */
    state_slot_t **	ct_text_offband_ssls;
    state_slot_t *	ct_text_start_ssl;
    state_slot_t *	ct_text_end_ssl;
    state_slot_t *	ct_text_score_limit_ssl;
    state_slot_t *	ct_text_desc_ssl;
    dk_set_t		ct_text_pre_code;
    state_slot_t *	ct_xpath_value_ssl;
    state_slot_t *	ct_text_ssl;
    state_slot_t *	ct_base_uri_ssl;
    int 		ct_is_xcontains;
    int			ct_gb_order;
    ST *		ct_jt_tree;
    dk_set_t		ct_jt_preds;	/* if outer join */
  } comp_table_t;



#define CT_ID(ct, str) \
  snprintf (str, sizeof (str), "<%s %s>", ct->ct_name ? ct->ct_name : "", ct->ct_prefix ? ct->ct_prefix : "")


typedef struct col_ref_rec_s
  {
    ST *		crr_col_ref;
    comp_table_t *	crr_ct;
    dbe_column_t *	crr_dbe_col;
    state_slot_t *	crr_ssl;
    int			crr_is_generated;
    int			crr_order;	/* if appears n order by, asc/desc */
    int			crr_is_as_alias;
    int			crr_proc_table_mode;
  } col_ref_rec_t;


/* crr_proc_table_mode, do predicates in the outer query get passed in */
#define CRR_PT_RESULT 0
#define CRR_PT_IN_EQU 1
#define CRR_PT_IN_ANY 2




typedef int (*sqlc_exp_print_hook_t) (struct sql_comp_s *, comp_table_t * ct, ST * exp,
				      char * text, size_t len, int * fill);

typedef struct rdf_inf_slots_s
{
  state_slot_t *	ris_s;
  state_slot_t *	ris_p;
  state_slot_t *	ris_o;
} rdf_inf_slots_t;


typedef struct sql_comp_s
  {
    comp_context_t *	sc_cc;
    struct sql_comp_s *	sc_super;
    struct predicate_s *sc_predicate;	/*!< The superquery's predicate this
					   subquery is part of */
    dk_set_t		sc_subq_compilations;
    					/*!< plist from the subq's 'select' node
					 to the query_t */
    comp_table_t **	sc_tables;

    dk_set_t		sc_temp_place;	/*!< state_slot_t's for interm. results */
    dk_set_t		sc_col_ref_recs;
    int			sc_last_label;
    dk_set_t		sc_preds;
    client_connection_t *sc_client;
    int			sc_is_proc;
    dk_set_t		sc_routine_code;
    id_hash_t *		sc_name_to_label;
    id_hash_t *		sc_decl_name_to_label;
    data_source_t *	sc_sorter;	/*!< a sort_node_t * if the ORDER BY
					   requires sorting */
    setp_node_t *	sc_sort_insert_node;
    data_source_t *	sc_sort_read_node;
    fun_ref_node_t *	sc_fref; /* when generating non-group aggregates this is the fref node */
    int			sc_no_current_of; /*!< no subsequent where current of
					     to cursor */
    dk_set_t		sc_fun_ref_defaults;
    dk_set_t		sc_fun_ref_default_ssls;
    dk_set_t		sc_fun_ref_temps;
    int			sc_temp_in_qst;
    comp_table_t *	sc_super_ct;	/*!< use in scope resolution in producing
					   a remote subq predicate for a
					   remote_table_source_t */
    dk_set_t		sc_subq_initial_crrs;
    					/*!< when this sc is a super_sc, the
					 subq gets the initial
					 sc_col_ref_recs from this */
    dk_set_t		sc_union_lists;	/*!< list of lists. The sublists are
					   combined in UNION ALL. The terms of
					   each sublist are joined by UNION */
    int			sc_store_procs;	/*!< true if generate code to store proc,
					   view, trigger etc definitions.
					   if not, just defines them in RAM */
    const char *	sc_text;	/*!< outermost sc, text of SQL source */
    key_id_t		sc_next_temp_key_id;
    dk_set_t		sc_gb_refs;	/*!< if group by, copy of selection w/
					   null for gb col & ammsc for f ref */
    ST **		sc_org_selection;/*!< org. selection, if group by */
    dk_set_t		sc_fun_ref_code;

    comp_table_t *	sc_generating_remote_ct; /*!< see sqlc_ct_is_local */
    int			sc_last_cn_no; /*!< last used vdb correlation name number */
    dk_set_t		sc_temp_trees; /*!< list of trees to free at free of sc */
    caddr_t		sc_exp_col_name;
    sql_type_t          sc_exp_sqt; /*!< in vdb, comp time type of generated exp */
    state_slot_t *	sc_exp_param;
    int			sc_no_remote; /*!< for a scroll crsr compile remotes as local for index selection */
    ST **		sc_select_as_list;
    int			sc_check_view_sec;
    sqlc_exp_print_hook_t 	sc_exp_print_hook;
    void *			sc_exp_print_cd;
    ST *			sc_top;
    select_node_t *		sc_top_sel_node;
    dk_set_t			sc_tie_oby;

    struct sql_comp_s * 	sc_scroll_super;
    dk_set_t *			sc_scroll_param_cols;
    ST *		sc_derived_opt;

    state_slot_t *		sc_sqlstate;
    state_slot_t *		sc_sqlmessage;
    struct sqlo_s *	sc_so;
    dk_set_t			sc_jt_preds;

    dk_set_t		sc_compound_scopes;
    int 		sc_is_trigger_decl;
    int 		sc_in_cursor_def;
    state_slot_t *	sc_grouping;
    ST **		sc_groupby_set;
    int		sc_is_update;
    char	sc_is_union;
    char	sc_order; /* If order of result rows is not important, like in filling a hash */
    char	sc_any_clb; /* any multi-state cluster node with a clb */
    dk_hash_t *	sc_qn_to_dpipe; /* if a dpipe is to be added before the node, it is marked here */
    dk_hash_t *	sc_ssl_eqs;
    update_node_t * 	sc_update_keyset;
    id_hash_t *	sc_sample_cache;
    state_slot_t **	sc_sel_out;
    dk_set_t		sc_agg_state_slot; /* when making an aggregate, this is the list of slots that hold the aggregation state */
    state_slot_t *	sc_set_no_ssl; /* for multistate qr with aggregate, top, distinct etc, set no of input */
    trans_node_t *	sc_trans; /* the tn while forming the step dt */
    dk_set_t		sc_dfg_stages;
    query_frag_t *	sc_qf;
    fun_ref_node_t *	sc_outer_fref;
    char		sc_in_dfg_subq;
    char		sc_fref_nesting; /* if nested gby/oby, true if colocating the gby */
    char		sc_qf_n_temp_trees; /* how many gb/oby temps in qf.  If many, make shorter batches to save mem */
    rdf_inf_slots_t *	sc_rdf_inf_slots;
    caddr_t * sc_big_ssl_consts;	/*!< Vector of saved values for SSL consts of unusual types (like vectors) or just too big to fit into SQL text in a plain way */
  } sql_comp_t;



#define SC_UPD_PLACE 1
#define SC_UPD_INS 2

#define TS_ORDER_KEY 0 /* generate results in key order and add key cols */
#define TS_ORDER_PLACE 1 /* generate the results in any order but add key cols for subsequent searched upd or del */
#define TS_ORDER_NONE 2  /* generate the resulsts in any order */



#define SC_G_ID(sc) \
  (sc->sc_client->cli_user ? sc->sc_client->cli_user->usr_g_id : G_ID_DBA)

#define SC_U_ID(sc) \
  (sc->sc_client->cli_user ? sc->sc_client->cli_user->usr_id : U_ID_DBA)


#if 0
#define SC_NO_EXCEPT(sc) \
{ \
  dk_set_t olde = sc->sc_except; \
  sc->sc_except = NULL;

#define SC_OLD_EXCEPT(sc) \
  sc->sc_except = olde; \
}
#else
#define SC_NO_EXCEPT(sc)
#define SC_OLD_EXCEPT(sc)
#endif

typedef struct subq_compilation_s
  {
    ST *		sqc_tree;
    query_t *		sqc_query;
    caddr_t		sqc_name;	/* cursor name if this is a cursor made
					   with declare cursor */
    state_slot_t *	sqc_ssl;	/* state slot holding ts_current_of */
    state_slot_t *	sqc_cr_state_ssl;
    dk_set_t		sqc_fetches;	/* fetch instructions referencing this
					   cr */
    char		sqc_is_cursor;	/* in declare .. cursor for ... */
    char		sqc_is_current_of;
					/* if cursor ref'd in where current of
					 * in same proc. */
    char		sqc_is_generated;/* set when actually ref'd in open or
					    pred */
    dbe_table_t *	sqc_remote_co_table;
    					/* prime keys of this added to selection
					 * for use in where current of */
    caddr_t		sqc_remote_prefix;  /* corr. name for PK cols in remotes
					     * where c/of */
    state_slot_t **	sqc_scroll_params;	/* state slots holding the scrollable params */
  } subq_compilation_t;


typedef struct predicate_s
  {
    dk_set_t		pred_tables;
    sql_tree_t *	pred_text;
    int			pred_generated;
  } predicate_t;


typedef struct col_pred_s
  {
    int			colp_op;
    dbe_column_t *	colp_col;
    caddr_t		colp_name; /* if proc table arg, there is no dbe_col */
    state_slot_t *	colp_ssl;
    int			colp_is_generated;
    char 		colp_like_escape;
  } col_pred_t;


typedef struct trig_cols_s
  {
    int			tc_is_trigger;
    ST **		tc_selection;
    dbe_table_t *	tc_table;
    caddr_t *		tc_cols;
    ST **		tc_vals;
    state_slot_t **	tc_slots;
    int			tc_pk_added;
    int			tc_n_before_pk;
  } trig_cols_t;


state_slot_t * col_ref_col (sql_comp_t * sc, caddr_t ref);

void comp_scalar_exp (sql_comp_t *sc, dk_set_t * code_vec, sql_tree_t * tree,
    state_slot_t * res);

comp_table_t * sqlc_is_col_pred (predicate_t * pred);
void sqlc_insert_view (sql_comp_t * sc, sql_tree_t * view, sql_tree_t * tree, dbe_table_t * tb);

void sqlc_make_and_list (sql_tree_t * tree, dk_set_t * res);

void pred_gen_1 (sql_comp_t * sc, ST* tree, dk_set_t * code,
    int succ, int fail, int unkn);

void sqlc_generate_preds (sql_comp_t * sc, comp_table_t * ct, dk_set_t * preds);

int ts_predicate_p (ptrlong p);

state_slot_t * scalar_exp_generate (sql_comp_t * sc, ST* tree,  dk_set_t * code);
void pred_list_generate (sql_comp_t * sc, dk_set_t pred_list, dk_set_t * code);


state_slot_t * select_ref_generate (sql_comp_t * sc, ST* tree,  dk_set_t * code,
    dk_set_t * fun_ref_acc_code, int * is_fun_ref);

col_ref_rec_t * sqlc_col_or_param (sql_comp_t * sc, ST * tree,
    int is_recursive);

col_ref_rec_t *  sqlc_col_ref_rec (sql_comp_t * sc, ST * col_ref,
    int err_if_not);

col_ref_rec_t * sqlc_find_crr (sql_comp_t * sc, ST * ref);


subq_compilation_t * sqlc_subquery_1 (sql_comp_t * super_sc, predicate_t * pred,
    ST** ptree, int mode, ST **params);

subq_compilation_t * sqlc_subquery (sql_comp_t * super_sc, predicate_t * pred,
    ST** ptree);

subq_compilation_t * sqlc_subq_compilation (sql_comp_t * sc, ST* tree,
    char * name);
subq_compilation_t *
sqlc_subq_compilation_1 (sql_comp_t * sc, ST * tree,
    char *name, int scrollables);

void sqlc_decl_variable_list (sql_comp_t * sc, ST ** params, int is_arg_list);
void sqlc_decl_variable_list_1 (sql_comp_t * sc, ST ** params, int is_arg_list, dk_set_t *ref_recs);
void sqlc_insert (sql_comp_t * sc, ST * tree);

void sqlc_update_pos (sql_comp_t * sc, ST * tree,
    subq_compilation_t * cursor_sqc);

void sqlc_update_searched (sql_comp_t * sc, ST * tree);

void sqlc_delete_pos (sql_comp_t * sc, ST * tree,
    subq_compilation_t * cursor_sqc);

void sqlc_delete_searched (sql_comp_t * sc, ST * tree);

void sqlc_routine_qr (sql_comp_t * sc);

void sqlc_proc_stmt (sql_comp_t * sc, ST ** pstmt);

code_vec_t code_to_cv (sql_comp_t * sc, dk_set_t code);
code_vec_t code_to_cv_1 (sql_comp_t * sc, dk_set_t code, int trim_one_long_cv);

dbe_table_t * table_ref_table (sql_comp_t * sc, ST* tref);

state_slot_t * sqlc_col_ref_ssl (sql_comp_t * sc, ST* col_ref);

setp_node_t *  sqlc_add_distinct_node (sql_comp_t * sc, data_source_t ** head,
    state_slot_t ** ssl_out, long nrows);


void ct_make_ts (sql_comp_t * sc, comp_table_t * ct);
void ct_generate_col_test (sql_comp_t * sc, comp_table_t * ct, predicate_t * pred);

void sqlc_mark_pred_deps (sql_comp_t * sc,  predicate_t * pred, sql_tree_t * tree);
void sql_node_append (data_source_t ** head, data_source_t * node);
void sqlc_copy_ssl_if_constant (sql_comp_t * sc, state_slot_t ** ssl_ret);

data_source_t *sqlc_add_sort_nodes (sql_comp_t * sc, data_source_t * old_head);

void sqlc_user_aggregate_decl (sql_comp_t * sc, ST * tree);
void sqlc_routine_decl (sql_comp_t * sc, ST * tree);
void sqlc_module_decl (sql_comp_t * sc, ST * tree);

void sqlc_trigger_decl (sql_comp_t * sc, ST * tree);

void sqlc_sch_list (sql_comp_t * sc, ST * tree);

void sqlc_call_exp (sql_comp_t * sc, dk_set_t * code, state_slot_t * ret,
    ST * tree);

void sqlc_table_ref (sql_comp_t *sc, ST* ref);

void sqlc_table_ref_list (sql_comp_t *sc, ST** refs);

caddr_t * sel_expand_stars (sql_comp_t * sc, ST ** selection, ST** from);

int cv_is_local_1 (code_vec_t cv, int is_cluster);
#define cv_is_local(cv) cv_is_local_1 (cv, 0)

#define CV_IS_LOCAL_CLUSTER 1 /* check funcs are partitionable and not aggregates */
#define CV_IS_LOCAL_AGG 2 /* check that funcs are partitionable, allow aggrs */
#define CV_IS_LOCAL_CN 3 /* when checking code node with subqs.  Accept the subqs but reject non locatable funcs */

dk_set_t cv_assigned_slots (code_vec_t cv);
void sqlc_ct_generate (sql_comp_t * sc, comp_table_t * ct);

state_slot_t * sqlc_asg_stmt (sql_comp_t * sc, ST * stmt, dk_set_t * code);

state_slot_t * sqlc_new_temp (sql_comp_t * sc, const char * name, dtp_t dtp);

state_slot_t * sqlc_mark_param_ref (sql_comp_t * sc, ST* param);

state_slot_t * sqlc_col_ref_rec_ssl (sql_comp_t * sc, col_ref_rec_t * cr);

void sc_free (sql_comp_t * sc);

void sqlc_select_strip_as (ST** selection, caddr_t *** as_list, int keep);
ST * sqlc_strip_as (ST * tree);

void sqlc_select_as (state_slot_t ** sls, caddr_t ** as_list);

caddr_t * ins_tb_all_cols (dbe_table_t * tb);

void dk_set_append_1 (dk_set_t * res, void *item);
void st_and (ST ** cond, ST * pred);
void t_st_and (ST ** cond, ST * pred);



struct remote_table_s * find_remote_table (char * name, int create);




/* sqlview.c */
void sqlc_union_stmt (sql_comp_t * sc, ST** ptree);
void sqlc_union_order (sql_comp_t * sc, ST ** ptree);
ST * sqlc_union_dt_wrap (ST * tree);

void sqlc_ct_generate_derived (sql_comp_t * sc, comp_table_t * ct);

key_id_t sqlc_new_temp_key_id (sql_comp_t * sc);
void sqlc_update_view (sql_comp_t * sc, ST* view, ST * tree, dbe_table_t * tb);
void sqlc_delete_view (sql_comp_t * sc, ST* view, ST * tree);
void sqlc_derived_order_by (sql_comp_t * sc, comp_table_t * ct);
void sqlc_table_used (sql_comp_t * sc, dbe_table_t * tb);
void sqlc_trig_const_params (sql_comp_t * sc, state_slot_t ** params,
    dk_set_t * code);
void sqlc_update_set_keyset (sql_comp_t * sc, table_source_t * ts);


void tc_init (trig_cols_t * tc, int event, dbe_table_t * tb, caddr_t * cols,
    ST ** vals, int add_pk);
void tc_free (trig_cols_t * tc);
int tc_new_value_inx (trig_cols_t * tc, char *col_name);
int tc_pk_value_inx (trig_cols_t * tc, char *col_name);

state_slot_t **sqlc_ins_triggers_1 (sql_comp_t * sc, dbe_table_t * tb,
    oid_t * col_ids, dk_set_t values, dk_set_t * code);
void sqlc_temp_tree (sql_comp_t * sc, caddr_t tree);

void ks_set_search_params (comp_context_t * cc, comp_table_t * ct, key_source_t * ks);
void inx_op_set_search_params (comp_context_t * cc, comp_table_t * ct, inx_op_t * iop);

ST * sqlc_ct_col_ref (comp_table_t * ct, char *col_name);

void sqlc_resignal (sql_comp_t * sc, caddr_t err);

void sql_stmt_comp (sql_comp_t * sc, ST ** ptree);
void qr_set_local_code_and_funref_flag (query_t * qr);


state_slot_t * scalar_exp_generate_typed (sql_comp_t * sc,
    ST * tree, dk_set_t * code, sql_type_t * expect);


sql_type_t * sqlc_stmt_nth_col_type (sql_comp_t * sc, dbe_table_t * tb, ST * tree, int nth);

void sqlc_union_constants (ST * sel);

/* sqlcr.c */
void sqlc_cursor (sql_comp_t * sc, ST ** ptree, int cr_type);

ST * sql_tree_and (ST * tree, ST * cond);
ptrlong cmp_op_inverse (ptrlong op);
caddr_t box_append_1 (caddr_t box, caddr_t elt);
caddr_t t_box_append_1 (caddr_t box, caddr_t elt);

col_ref_rec_t * sqlc_virtual_col_crr (sql_comp_t * sc, comp_table_t * ct, char * name, dtp_t dtp);


typedef void (*sqlc_meta_hook_t) (sql_comp_t * sc, ST * tree);
#define TA_SQLC_META 1006
void sqlc_meta_data_hook (sql_comp_t * sc, ST * tree);
void sqlc_proc_table_cols (sql_comp_t * sc, comp_table_t * ct);

void sqlc_top_select_dt (sql_comp_t * sc, ST * tree);
ST ** sqlc_selection_names (ST * tree, int only_edit_tree);

#define P_NO_MATCH 0
#define P_EXACT 1
#define P_PARTIAL 2


int sqlc_pref_match (char * crr_pref, char * ref_pref);
int indexable_predicate_p (int p);
unsigned char bop_to_dvc (int op);
void sqlc_select_top (sql_comp_t * sc, select_node_t * sel, ST * tree, 		 dk_set_t * code);
void sqlc_select_unique_ssls (sql_comp_t * sc, select_node_t * sel, dk_set_t *sel_set);
data_source_t * sqlc_make_sort_out_node (sql_comp_t * sc, dk_set_t out_cols, dk_set_t out_slots, dk_set_t out_always_null);
setp_node_t * setp_node_keys (sql_comp_t * sc, select_node_t * sel, caddr_t * cols);
void qr_replace_node (query_t * qr, data_source_t * to_replace,
		      data_source_t * replace_with);

void setp_distinct_hash (sql_comp_t * sc, setp_node_t * setp, long n_rows);
void setp_after_deserialize (setp_node_t * setp);
void ha_free (hash_area_t * ha);

#ifdef BIF_XML
ST ** sqlc_ancestor_args (ST * tree);
ST ** sqlc_contains_args (ST * tree, int * ctype);
ST ** sqlc_geo_args (ST * tree, int * ctype);
char sqlc_contains_fn_to_char (const char *name);
void upd_arrange_misc (sql_comp_t * sc, update_node_t * upd);
void ins_arrange_misc (sql_comp_t * sc, insert_node_t * upd);
int sqlc_xpath (sql_comp_t * sc, char * str, caddr_t * err_ret);
void  sqlc_text_node (sql_comp_t * sc, comp_table_t * ct);
void sqlc_is_text_only (sql_comp_t * sc, comp_table_t * ct);
void  sqlc_xpath_node (sql_comp_t * sc, comp_table_t * ct);
void sqlc_implied_columns (sql_comp_t * sc);

void ks_ancestor_scan (sql_comp_t * sc, comp_table_t * ct, key_source_t * ks);
ST * sqlc_embedded_xpath (sql_comp_t * sc, char * str2, caddr_t * err_ret);

#endif

caddr_t sqlo_iri_constant_name_1 (ST* tree);
extern int32 sqlo_compiler_exceeds_run_factor;

/* sqlcr.c */
query_t *
sql_compile_st (ST ** ptree, client_connection_t * cli,
		caddr_t * err, sql_comp_t *super_sc);

/* sqltype.c */
query_t *sqlc_udt_store_method_def (sql_comp_t *sc, client_connection_t *cli,
    int cr_type, query_t *qr, const char * string2, caddr_t *err);
query_t *sqlc_make_proc_store_qr (client_connection_t * cli, query_t * proc_or_trig,
    const char * text);


#define CL_QF_BREAK 1 /* this qn can't pass to cluster remote inside a qf */

void qn_refd_slots (sql_comp_t * sc, data_source_t * qn, dk_hash_t * res, dk_hash_t * all_res, int * non_cl_local);
void sqlg_cl_dml (sql_comp_t * sc, data_source_t * dml);
void sqlg_qn_env (sql_comp_t * sc, data_source_t * qn, dk_set_t qn_stack, dk_hash_t * refs);
void sqlg_qr_env (sql_comp_t * sc, query_t * qr);
void cv_refd_slots (sql_comp_t * sc, code_vec_t cv, dk_hash_t * res, dk_hash_t * all_res, int * non_cl_local);
extern int sqlg_count_qr_global_refs;
void ins_assigned (instruction_t * ins, dk_set_t * res);

extern int sqlg_count_qr_global_refs;

#define REF_SSL(res, ssl) \
  {if (res && ssl && SSL_CONSTANT != ssl->ssl_type \
       && (sqlg_count_qr_global_refs||  !ssl->ssl_qr_global)  && SSL_PLACEHOLDER != ssl->ssl_type && SSL_ITC != ssl->ssl_type) \
sethash ((void*)ssl, res, (void*)1); }

void  ref_ssl_list (dk_hash_t * ht, dk_set_t ssls);

#define ASG_SSL(res, all_res, ssl) \
  if (IS_REAL_SSL (ssl)) \
    { \
      sqlc_asg_mark (ssl); \
      sqlg_asg_ssl (res, all_res, ssl); \
    }


void sqlg_asg_ssl (dk_hash_t * res, dk_hash_t * all_res, state_slot_t * ssl);
void sqlc_asg_mark (state_slot_t * ssl);
void asg_ssl_array (dk_hash_t * res, dk_hash_t * all_res, state_slot_t ** ssls);
void ts_set_local_code (table_source_t * ts, int is_cluster);
void sqlg_cl_insert (sql_comp_t * sc, comp_context_t * cc, insert_node_t * ins, ST * tree, dk_set_t * code);
ST * sqlc_pos_to_searched_where (sql_comp_t * sc, subq_compilation_t * sqc, char * cr_name,
			    dbe_table_t * tb);
caddr_t * ht_keys_to_array (dk_hash_t * ht);
void sqlg_multistate_code (sql_comp_t * sc, data_source_t ** head, int in_order);
int qr_is_multistate (query_t * qr);
int qn_seq_is_multistate (data_source_t * qn);
data_source_t * qn_prev (data_source_t ** head , data_source_t * qn);
void sqlg_cl_multistate_simple_agg (sql_comp_t * sc,  dk_set_t * com_code);
void sqlg_multistate_query (sql_comp_t * sc, query_t * qr, set_ctr_node_t * sctr);
state_slot_t * sqlg_set_no_if_needed (sql_comp_t * sc, data_source_t ** head);
void setp_set_ssa (sql_comp_t * sc, setp_node_t * setp, dk_set_t * list_ret);
dk_set_t  ha_save (hash_area_t *);
void sqlg_cl_multistate_group (sql_comp_t * sc);
void ssa_init (sql_comp_t * sc, setp_save_t * ssa, state_slot_t * set_no_ssl);
dk_set_t  sqlg_continue_list (data_source_t * qn);


extern int cl_rdf_inf_inited;
extern du_thread_t * cl_rdf_inf_init_thread;


#define OUTSIDE_PARSE_SEM \
  { \
      int is_sem = sqlc_inside_sem; \
      if (is_sem) \
	semaphore_leave (parse_sem); 


#define END_OUTSIDE_PARSE_SEM \
      if (is_sem) \
	semaphore_enter (parse_sem); \
  }


#endif /* _SQLCMPS_H */