
BASETABLE
	(card MULTI)
	-> exps		is list of column expressions (also used for aliases)
	-> l		(sql_table)

TABLE 	(card MULTI)
	-> flags	(1) TABLE query 
			(2) RELATIONAL subquery (ie wrap function around subquery)
	-> exps		is list of column expressions (also used for aliases)
	-> l 		optional input relation
	-> r		(1) table function expression
			(2) list of input expressions
		

/* Wrapping relational operator, is a big complex top level only 
   operator, which only does DDL kind of statements
 */
DDL 	(card 0!, top of the tree always)
	-> flags	/* OUTPUT, TRANSACTION-types, CREATE/DROP/ALTER* */ 
	-> exps		For 'OUTPUT' is list of output options
			For 'transactions' simple flags
			for CREATE etc full sql string.
	-> l		only used for 'OUTPUT' relation to output
	-> r		(only for DDL_LIST)

SELECT 	(card MULTI or same ...?) 
	-> exps		selection expressions (ie all e_cmp)
	-> l		is relation

LEFT|RIGHT|FULL
JOIN 	(card MULTI)
	-> exps		join expressions (ie all e_cmp)
	-> l		is left relation
	-> r		is rigth relation
	-> flag		LEFT (keep left order, only used during code generation)

SEMI/ANTI 
	(card MULTI)
	-> exps		join expressions (ie all e_cmp)
	-> l		is left relation
	-> r		is rigth relation

APPLY
	(card MULTI)
	-> exps		are the bind variables (from the outer, correlated in the subquery)
	-> l		is outer relation
	-> r		is subquery relation

UNION|EXCEPT|INTERSECT 
	(card ATOM, AGGR or MULTI (same card as lower relation))
	-> exps 	is list of projection expressions
	-> l		is left relation
	-> r		is rigth relation

PROJECT  (card ATOM, AGGR or MULTI (same card as lower relation))
	-> exps 	is list of projection expressions
	-> l		is relation
	-> r		optional, is list of order by expressions 

GROUPBY  (card ATOM (no group by exps), AGGR)
	-> exps		is list of (groupby and) aggregate expressions
	-> l		is relation
	-> r 		is list of group by expressions

TOPN	(card ATOM, AGGR, or MULTI (same card as lower relation))
	-> exps 	(list) int limit, [ int offset ]
	-> l		is relation
	-> flag 	(bounds for limit can be including (1) or excluding (0) (ie later just returns the topN, including will return atleast N)

SAMPLE	(card ATOM, AGGR, or MULTI (same card as lower relation))
	-> exps		int rownumbers, (todo: double between [0,1] for percentage)
	-> l		is relation
	-> flag		(0) no flags

INSERT|DELETE|UPDATE 	(card MULTI)
	-> l 		is relation to modify
	-> r		to be inserted/deleted/updated relation
			For update the ->r projection joins in current
			values for 'none' updated columns.

	-> flag		(if set don't insert (is done already))
only (UPDATE)
	-> exps		
			Named columns to update

INSERT/UPDATE have a special case 	

			for inserts/updates with indices a double
			relation is used as we need to keep access to
			the bottom value relation

Expressions

e_atom 	(card ATOM)
	-> l	literal (-> l = atom)
	or
	-> r	parameter ( ->r = varname, ->type = subtype, ->flag = level)
	or
	-> f	list of atom expressions
	or
	-> 	numbered variable ( ->flag = nr, ->type = subtype)

e_convert
	-> l	sub expression
	-> r	list of from and to subtypes

e_cmp
	-> l	left sub expression
	-> r	right sub expression (f second arg (->f) for range expressions)
	-> flag compare type		
		(       cmp_gt = 0,
        		cmp_gte = 1,
        		cmp_lte = 2,
        		cmp_lt = 3,
        		cmp_equal = 4,
        		cmp_notequal = 5,

        		cmp_filter = 6,		filters			->r is a list of values
        		cmp_or = 7,		or handling  		->l/r are both lists
			cmp_in = 8,		in list handling 	->r is a list of values
			cmp_notin = 9		not in list handling	->r is a list of values

        		cmp_all = 10,		cross product
			cmp_project = 11, 	special case for projection joins
		)

e_func
e_aggr
	-> l 	list of sub expressions (args for the func and aggr)
	-> r	rank operators the list order by expressions (group by in l)
	-> f	func / aggr
for aggr
	-> flag DISTINCT and NO_NIL could be set

e_column
	-> rname alias for the relation (i.e., alias of ->l, used by higher expressions)
	-> name alias for the expression (i.e., alias of ->r, used by higher expressions)
		l,r names of referred expression
	-> l 	optional relation name 
	-> r	expression name
	-> type 

	
e_psm
	-> flag
		psm_declare 	name 
				type
		psm_set		name 
				->l value_exp
		psm_if		->l cond_exp, 
				->r then_exp_list 
				->f else_exp_list
		psm_while	->l cond_exp
				->r loop_exp_list
		psm_return	->l return_exp
		psm_rel		->l relation
