Update of /cvsroot/monetdb/pathfinder/compiler/sql
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv12708/sql
Modified Files:
lalg2sql.brg sql.c sqlprint.c
Log Message:
-- instead of creating a seperate table for the values list resulting from
guide-style path summaries,
we include it into the corresponding from-clause
with the following syntax
... FROM (VALUES (1), ..., (n)) as tab(guide) ...
For this purpose we introduce a new alias_def-operator for aliases with
annotated column list.
Index: sql.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/sql/sql.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- sql.c 6 Dec 2007 08:42:43 -0000 1.43
+++ sql.c 11 Dec 2007 13:15:15 -0000 1.44
@@ -235,6 +235,17 @@
}
/**
+ * Construct a SQL tree node representing a definition of an alias name
+ * with columnlist.
+ */
+PFsql_t * PFsql_alias_def (PFsql_aident_t name, PFsql_t *columnlist)
+{
+ PFsql_t *ret = wire1 (sql_alias_def, columnlist);
+ ret->sem.alias.name = name;
+ return ret;
+}
+
+/**
* Collate a schema and a table_name, to identify a table in a database.
*/
PFsql_t *
@@ -292,8 +303,6 @@
return ret;
}
-
-
/* .......... Columns .......... */
/**
Index: lalg2sql.brg
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/sql/lalg2sql.brg,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -d -r1.95 -r1.96
--- lalg2sql.brg 6 Dec 2007 08:42:42 -0000 1.95
+++ lalg2sql.brg 11 Dec 2007 13:15:15 -0000 1.96
@@ -737,7 +737,7 @@
struct sql_from_list_t
{
PFsql_t *table;
- PFsql_aident_t alias;
+ PFsql_t *alias;
};
typedef struct sql_from_list_t sql_from_list_t;
@@ -790,7 +790,7 @@
/* check for a NULL value */
from_clause.table
? from_clause.table : tbl,
- alias (from_clause.alias)));
+ from_clause.alias));
}
return fromlist;
@@ -921,8 +921,8 @@
replace the old aliases in the from list */
for (unsigned int i = 0; i < count; i++) {
map[i].new = new_alias ();
- map[i].old = (from_list_at (FROMLIST(p), i)).alias;
- (from_list_at (FROMLIST(p), i)).alias = map[i].new;
+ map[i].old = (from_list_at (FROMLIST(p), i)).alias->sem.alias.name;
+ (from_list_at (FROMLIST(p), i)).alias->sem.alias.name = map[i].new;
/* Copy the expressions in the fromlist */
(from_list_at (FROMLIST(p), i)).table
@@ -966,7 +966,7 @@
PFsql_t *fragment)
{
PFsql_aident_t par = new_alias ();
- from_list_add (FROMLIST(p), fragment, par);
+ from_list_add (FROMLIST(p), fragment, alias (par));
/* parent step */
/* ctx.pre > par.pre and par.pre + par.size >= ctx.pre */
@@ -1246,7 +1246,6 @@
{
assert (p);
- PFsql_tident_t newtable = new_table_name ();
PFsql_aident_t newalias = new_alias ();
PFsql_t **list = PFmalloc (count * sizeof (PFsql_t *));
@@ -1254,16 +1253,10 @@
for (unsigned int i = 0; i < count; i++)
list[i] = stmt_list (lit_int (guides[i]->guide));
- /* prepare table to dump */
- execute (bind (table_def (
- newtable,
- column_list (GUIDE_)),
- values (PFsql_list_list_ (count, (const PFsql_t **)
list))));
-
/* prepare step node */
- from_list_add (FROMLIST(p), table_name (newtable),
- newalias);
-
+ from_list_add (FROMLIST(p),
+ values (PFsql_list_list_ (count, (const PFsql_t **) list)),
+ alias_def (newalias, column_list (GUIDE_)));
where_list_add (WHERELIST(p),
eq
@@ -1404,7 +1397,7 @@
from_list_add (FROMLIST(p),
table_name (twig_tbl),
- new_root);
+ alias (new_root));
/* mark node p as bound */
BOUND(p) = true;
@@ -1522,7 +1515,7 @@
/* add the new binding to the from list */
from_list_add (FROMLIST(p),
table_name (newtable),
- newalias);
+ alias (newalias));
/* mark node p as bound */
BOUND(p) = true;
@@ -1950,7 +1943,7 @@
doc1 = col_env_lookup_step (COLMAP(query), item, item_ty);
if (doc1 == PF_SQL_ALIAS_UNBOUND) {
doc1 = new_alias ();
- from_list_add (FROMLIST(p), frags, doc1);
+ from_list_add (FROMLIST(p), frags, alias (doc1));
where_list_add (WHERELIST(p),
eq (col_env_lookup (
COLMAP(query), item, item_ty),
@@ -1963,7 +1956,7 @@
doc2 = doc1;
else {
doc2 = new_alias ();
- from_list_add (FROMLIST(p), frags, doc2);
+ from_list_add (FROMLIST(p), frags, alias (doc2));
step_axis (p, doc1, doc2, alg_desc_s, NULL, -1);
orderby = sortkey_list (orderby,
sortkey_item (PRE(doc2),
true));
@@ -2013,7 +2006,7 @@
doc1 = new_alias ();
doc2 = new_alias ();
from = from_list_at (FROMLIST(query), 0);
- from_bind = alias_bind (from.table, alias (from.alias));
+ from_bind = alias_bind (from.table, from.alias);
/* add the axis conditions */
step_axis (p, doc1, doc2, alg_desc_s, NULL, -1);
@@ -2224,7 +2217,7 @@
schema_table_name (
"sysibm",
table_name (PF_SQL_TABLE_SYSDUMMY1)),
- new_alias ());
+ alias (new_alias ()));
} else {
/* literal table has more than one row */
PFsql_tident_t newtable = new_table_name ();
@@ -2263,7 +2256,7 @@
/* prepare the fromlist */
from_list_add (FROMLIST(p),
table_name (newtable),
- newalias);
+ alias (newalias));
/* initialize the list */
list = PFmalloc (ccount * sizeof (PFsql_t *));
@@ -2317,7 +2310,7 @@
/* add the tables "external"/"real" name to the fromlist */
from_list_add (FROMLIST(p),
ref_table_name (p->sem.ref_tbl.name),
- tabalias);
+ alias (tabalias));
/* lookup the "internal" column names (and types) in the
schema info */
@@ -2536,7 +2529,7 @@
from_list_add (right->frommap,
table_name (newtable),
- newalias);
+ alias (newalias));
col_env_add (right->colmap,
att2,
@@ -2656,7 +2649,7 @@
/* start a new from list as a newtable will be bound */
from_list_add (FROMLIST(p),
table_name (newtable),
- newalias);
+ alias (newalias));
/* add the partition criterion to all lists and environments */
if (part) {
@@ -2810,7 +2803,7 @@
/* start a new from list as @a newtable will be bound */
from_list_add (FROMLIST(p),
table_name (newtable),
- newalias);
+ alias (newalias));
/* prepare the selection lists, the column list, and fill in
the new bindings for the column environment */
@@ -3112,7 +3105,7 @@
ext_column_name (newalias, res_col));
/* prepare fromlist */
- from_list_add (FROMLIST(p), table_name(newtable), newalias);
+ from_list_add (FROMLIST(p), table_name(newtable), alias
(newalias));
/* run over the possible types */
for (PFalg_simple_type_t t = 1; t; t <<= 1)
@@ -3189,7 +3182,7 @@
/* start a new from list as @a newtable will be bound */
from_list_add (FROMLIST(p),
table_name (newtable),
- newalias);
+ alias (newalias));
if (att) /* cope with missing att column in case of count */ {
ty = type_of (p, att);
@@ -3338,9 +3331,9 @@
loop = col_env_lookup (COLMAP(RLL(p)), part, part_ty);
part_expr = col_env_lookup (COLMAP(LL(p)), part, part_ty);
from = from_list_at (FROMLIST(RLL(p)), 0);
- loop_from = alias_bind (from.table, alias (from.alias));
+ loop_from = alias_bind (from.table, from.alias);
from = from_list_at (FROMLIST(LL(p)), 0);
- part_from = alias_bind (from.table, alias (from.alias));
+ part_from = alias_bind (from.table, from.alias);
/* create a new table name for binding */
newtable = new_table_name ();
@@ -3349,7 +3342,7 @@
/* start a new from list as @a newtable will be bound */
from_list_add (FROMLIST(p),
table_name (newtable),
- newalias);
+ alias (newalias));
/* PREPARE EVERYTHING FOR THE RESULT ATTRIBUTE */
col_env_add (COLMAP(p), res_att, res_ty,
@@ -3622,7 +3615,7 @@
ctxalias = col_env_lookup_step (COLMAP(p), item, item_ty);
if (ctxalias == PF_SQL_ALIAS_UNBOUND) {
ctxalias = new_alias ();
- from_list_add (FROMLIST(p), FRAG(L(p)), ctxalias);
+ from_list_add (FROMLIST(p), FRAG(L(p)), alias (ctxalias));
where_list_add (WHERELIST(p),
eq (col_env_lookup (COLMAP(p), item, item_ty),
PRE(ctxalias)));
@@ -3632,7 +3625,7 @@
stepalias = new_alias ();
from_list_add (FROMLIST(p),
FRAG(L(p)),
- stepalias);
+ alias (stepalias));
/* add the axis conditions */
step_axis (p,
@@ -3715,7 +3708,7 @@
ctxalias = col_env_lookup_step (COLMAP(p), item, item_ty);
if (ctxalias == PF_SQL_ALIAS_UNBOUND) {
ctxalias = new_alias ();
- from_list_add (FROMLIST(p), FRAG(L(p)), ctxalias);
+ from_list_add (FROMLIST(p), FRAG(L(p)), alias (ctxalias));
where_list_add (WHERELIST(p),
eq (PRE(ctxalias),
col_env_lookup (COLMAP(p), item,
item_ty)));
@@ -3792,7 +3785,7 @@
/* ... and use it to refer to a fresh document relation */
from_list_add (FROMLIST(p),
table_name (PF_SQL_TABLE_FRAG),
- doc_tbl);
+ alias (doc_tbl));
/* add the output columns to the column map */
col_env_add_full (COLMAP(p), iter, iter_ty,
@@ -3976,7 +3969,7 @@
on (left_outer_join (
alias_bind (
name_from.table,
- alias (name_from.alias)),
+ name_from.alias),
alias_bind (
CSIZE(R(p)),
alias (csize_alias))),
@@ -4045,7 +4038,7 @@
also into the list of groupby criteria. */
else {
item_col = EXT_COLUMN_NAME (
- name_from.alias,
+ name_from.alias->sem.alias.name,
item,
type_of (L(p), item));
grpbylist = column_list (iter_col, item_col);
@@ -4072,7 +4065,7 @@
on (left_outer_join (
alias_bind (
name_from.table,
- alias (name_from.alias)),
+ name_from.alias),
alias_bind (
CSIZE(R(p)),
alias (csize_alias))),
@@ -4173,7 +4166,7 @@
/* add the document relation */
ctx = new_alias ();
- from_list_add (FROMLIST(p), NULL, ctx);
+ from_list_add (FROMLIST(p), NULL, alias (ctx));
where_list_add (WHERELIST(p), eq (item_expr, PRE(ctx)));
for (unsigned int i = 0; i < PFarray_last (frags); i++) {
@@ -4203,7 +4196,7 @@
/* add the binding for the new document relation */
step = new_alias ();
- from_list_add (FROMLIST(p), NULL, step);
+ from_list_add (FROMLIST(p), NULL, alias (step));
/* add the axis conditions */
step_axis (p, ctx, step, alg_desc_s, NULL, -1);
Index: sqlprint.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/sql/sqlprint.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- sqlprint.c 6 Dec 2007 08:42:44 -0000 1.42
+++ sqlprint.c 11 Dec 2007 13:15:16 -0000 1.43
@@ -46,6 +46,9 @@
#define L(p) ((p)->child[0])
/** starting from p, make a right step */
#define R(p) ((p)->child[1])
+/** starting from p, make a right step
+ * then a left step */
+#define RL(p) L(R(p))
/* shortcut for pretty printing */
#define pretty_dump(f,i) PFprettyp_extended ((f), 70, (i))
@@ -73,6 +76,7 @@
[sql_ser_mapping] = "ser_mapping",
[sql_ser_type] = "ser_type",
[sql_tbl_def] = "tbl_def",
+ [sql_alias_def] = "alias_def",
[sql_schema_tbl_name] = "schema_tbl_name",
[sql_tbl_name] = "tbl_name",
[sql_ref_tbl_name] = "ref_tbl_name",
@@ -230,7 +234,42 @@
}
+static void
+print_column_name_ (FILE *f, PFsql_t *n)
+{
+ assert ((n->kind == sql_column_name) || (n->kind == sql_ref_column_name));
+
+ if (n->sem.column.alias != PF_SQL_ALIAS_UNBOUND)
+ {
+ fprintf (f, "%s.",
+ PFsql_alias_name_str (n->sem.column.alias));
+
+ }
+
+
+ switch (n->kind)
+ {
+ case sql_column_name:
+
+ fprintf (f, "%s",
+ PFsql_column_name_str (n->sem.column.name));
+ break;
+
+ case sql_ref_column_name:
+
+ fprintf (f, "%s",
+ n->sem.ref_column_name.name);
+ break;
+
+ default:
+
+ PFoops (OOPS_FATAL,
+ "SQL grammar conflict. (Expected: column reference; "
+ "Got: %s)", ID[n->kind]);
+ }
+
+}
static void
print_column_name_list (PFsql_t *n)
@@ -259,6 +298,33 @@
}
static void
+print_column_name_list_ (FILE *f, PFsql_t * n, int i)
+{
+ assert (n);
+
+ switch (n->kind) {
+ case sql_column_list:
+ print_column_name_list_ (f, L(n), i);
+
+ if (R(n)->kind != sql_nil) {
+ fprintf (f, ",");
+ indent (f, i);
+ print_column_name_list_ (f, R(n), i);
+ }
+ break;
+
+ case sql_column_name:
+ print_column_name_ (f, n);
+ break;
+
+ default:
+ PFoops (OOPS_FATAL,
+ "SQL grammar conflict. (Expected: column name list; "
+ "Got: %s)", ID[n->kind]);
+ }
+}
+
+static void
print_table_def (PFsql_t *n)
{
assert (n);
@@ -690,21 +756,30 @@
switch (n->kind) {
case sql_alias_bind:
- assert (R(n)->kind == sql_alias);
+ assert (R(n)->kind == sql_alias ||
+ R(n)->kind == sql_alias_def);
if (L(n)->kind == sql_select || L(n)->kind == sql_union)
/* print nested selection */
print_fullselect (f, L(n), i);
else
print_tablereference (f, L(n), i);
+
fprintf (f, " AS %s", PFsql_alias_name_str (R(n)->sem.alias.name));
+
+ /* printf column list if required */
+ if (R(n)->kind == sql_alias_def) {
+ fprintf (f, "(");
+ print_column_name_list_ (f, RL(n), i);
+ fprintf (f, ")");
+ }
break;
case sql_ref_tbl_name:
/* prettyprint ref table name */
fprintf (f, "%s", n->sem.ref_tbl.name);
break;
- case sql_tbl_name:
+ case sql_tbl_name:
/* prettyprint table name */
fprintf (f, "%s", PFsql_table_str (n->sem.tbl.name));
break;
@@ -716,6 +791,13 @@
PFsql_table_str(L(n)->sem.tbl.name));
break;
+ case sql_values:
+ /* TABLE */
+ fprintf (f, "(VALUES ");
+ print_list_list (f, L(n), i+7);
+ fprintf (f, ")");
+ break;
+
default:
PFoops (OOPS_FATAL,
"SQL grammar conflict. (Expected: table reference; "
@@ -845,13 +927,13 @@
pretty_dump (f, i+7);
}
break;
+
case sql_values:
/* TABLE */
fprintf (f, "VALUES ");
print_list_list (f, L(n), i+7);
break;
-
case sql_union:
print_fullselect (f, L(n), i);
indent (f, i);
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Monetdb-pf-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-pf-checkins