sql_rel * rel_partition(mvc *sql, sql_rel *rel) { (void)sql; if (rel->op == op_basetable) { rel->flag = REL_PARTITION; } else if ((rel->op == op_topn || rel->op == op_sample || rel->op == op_select) && rel->l) { rel_partition(sql, rel->l); } else if (is_modify(rel->op) && rel->card <= CARD_AGGR) { if (rel->r) rel_partition(sql, rel->r); } else if (is_project(rel->op) && rel->l) { rel_partition(sql, rel->l); } else if (rel->op == op_semi && rel->l && rel->r) { rel_partition(sql, rel->l); rel_partition(sql, rel->r); } else if (rel->op == op_anti && rel->l && rel->r) { rel_partition(sql, rel->l); rel_partition(sql, rel->r); } else if (is_join(rel->op)) { if (has_groupby(rel->l) || has_groupby(rel->r)) { rel_partition(sql, rel->l); rel_partition(sql, rel->r); } else _rel_partition(sql, rel); } return rel; }
static int has_groupby(sql_rel *rel) { if (rel->op == op_groupby) return 1; if (is_join(rel->op)) return has_groupby(rel->l) || has_groupby(rel->r); if ((is_select(rel->op) || is_project(rel->op)) && rel->l) return has_groupby(rel->l); return 0; }
/************************************************************************** * *N select_feature_class_relate * *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * Set up the relationships between features and primitives or between * primitives and features (one way only) for a specified feature class. *E *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels DOS Turbo C *E *************************************************************************/ fcrel_type select_feature_class_relate( int fcnum, library_type *library, char *start_table, char *end_table ) { int storage, cov; vpf_table_type fcs; long int i; char path[255], covpath[255]; position_type p; vpf_relate_struct rcell; fcrel_type fcrel; fcrel.nchain = 0; fcrel.table = NULL; fcrel.relate_list = NULL; cov = library->fc[fcnum].coverage; strcpy(covpath,library->cover[cov].path); rightjust(covpath); sprintf( path, "%sfcs", covpath ); /* Feature Class Schema table */ fcs = vpf_open_table( path, disk, "rb", NULL ); fcrel.relate_list = fcs_relate_list( library->fc[fcnum].name, start_table,end_table, fcs ); if (ll_empty(fcrel.relate_list)) { ll_reset(fcrel.relate_list); displaymessage("ERROR in feature class relationship!", start_table,end_table,NULL); return fcrel; } /* Find the number of tables in the relate chain */ p = ll_first(fcrel.relate_list); fcrel.nchain = 0; while (!ll_end(p)) { fcrel.nchain++; p = ll_next(p); } /* Allow for last table2 */ fcrel.nchain++; fcrel.table = (vpf_table_type *) vpfmalloc((fcrel.nchain+1)* sizeof(vpf_table_type)); for (i=0;i<fcrel.nchain+1;i++) vpf_nullify_table( &(fcrel.table[i]) ); p = ll_first(fcrel.relate_list); for (i=0;i<fcrel.nchain-1;i++) { ll_element(p,&rcell); /** Can't open primitive table - may be several under tile **/ /** directories. Open all others **/ if (!is_primitive(rcell.table1)) { sprintf(path,"%s%s",covpath,rcell.table1); if (is_join(rcell.table1)) storage = ram; else storage = disk; fcrel.table[i] = vpf_open_table(path,(storage_type)storage,"rb",NULL); } if (!ll_end(p)) p = ll_next(p); } /* End of relate chain */ i = fcrel.nchain-1; if (!is_primitive(rcell.table2)) { sprintf(path,"%s%s",covpath,rcell.table2); storage = disk; fcrel.table[i] = vpf_open_table(path,(storage_type)storage,"rb",NULL); } vpf_close_table( &fcs ); return fcrel; }