- /*
- * rules for processing nested queries
- * nest type NJ
- */
- #include <global.h>
- #include "trlinter.h"
- #include "seman.h"
- static int
- simple (TXTREF node)
- {
- if (CODE_TRN(node) ==COLPTR) return 1;
- return 0;
- }
- static TXTREF list_scan =TNULL; /* TblPtr list */
- static int
- sav_list_scan (TXTREF node) /* save first TblPtr */
- {
- list_scan = node; /* TABL_DESC (node); */
- return 1;
- }
- static int
- ext_ref (TXTREF node)
- {
- TXTREF p;
- /* checking ext ref */
- if ( CODE_TRN (node) == COLPTR)
- {
- for (p =list_scan; p; p =RIGHT_TRN (p))
- if (COL_TBL (OBJ_DESC (node)) == TABL_DESC (p)) return 1;
- }
- return 0;
- }
- #(Rule "Type_N"
- (Query:where_f:subquery_f:9
- { (From:1 )
- (Selection)
- (Where:3 { (In:7
- { (ColPtr:4)
- (SubQuery:8
- { (From :2 )
- (Result:10 { (ColPtr:5) } )
- (Where:6 )
- } )
- } )
- } )
- } )
- ""
- {
- (Op:1
- {
- (DOWN:list (Op:1))
- (DOWN:list (Op:2)) ;; don`t need to create new scan !
- })
- (Op:3
- { (And
- { (Equ
- { (Op:4)
- (Op:5)
- })
- (DOWN (Op:6) )
- } )
- })
- (REMOVE Op:2)
- (REMOVE Op:7)
- (REMOVE Op:6)
- (REMOVE Op:10)
- Op:9
- }
- )
- /*
- * nest type JA
- */
- static void
- local_rule(TXTREF result,TXTREF *Rop)
- { /* add tmptable ref in glob vcb */
- TXTREF p, cl;
- i4_t i;
- p =gen_node (TMPTABLE);
- XVCB_TRN (p, 4) =VCB_ROOT; /* next */
- TBL_NCOLS (p) = ARITY_TRN (result);
- VCB_ROOT =p;
- VIEW_QUERY (p) =*Rop;
- /* columns chain */
- for (cl =DOWN_TRN (result), i=0; cl; cl =RIGHT_TRN (cl),i++)
- {
- p =gen_node (COLUMN);
- COL_NO (p) =i;
- COL_TBL (p) =VCB_ROOT;
- COL_NEXT (p) =TBL_COLS (VCB_ROOT);
- TBL_COLS (VCB_ROOT) =p;
- if (CODE_TRN (cl) ==COLPTR) COL_TYPE (p) =COL_TYPE (OBJ_DESC(cl));
- else COL_TYPE (p) =OPRN_TYPE (cl);
- }
- }
- #(Rule "Type_JA"
- (Query:where_f:subquery_f:9 {
- (From { (Op "sav_list_scan") -- } )
- (Selection)
- (Where:3 {
- (Op:7 "Is_Predicate" {
- (ColPtr:4)
- (SubQuery:8 {
- (From :2 { (Op:12) } )
- (Result:11 { (Op:5 "Is_Function") } )
- (Where:6 {
- (Op "Is_Predicate" {
- (Op:1:exist_op "ext_ref" )
- (Op:10:exist_op)
- } )
- } )
- } )
- } )
- } )
- } )
- ""
- {
- (Query {
- (COPY (Op:2))
- (Selection:11 {(COPY (Op:10)) (COPY (Op:5 )) })
- (Group {(COPY (Op:10)) })
- } )
- (C_code ("local_rule(Op[11],&Rop);"))
- }
- )