Update of /cvsroot/monetdb/sql/src/server
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23123/src/server
Modified Files:
sql_schema.mx sql_select.mx sql_statement.mx sql_updates.mx
Log Message:
added another column in the catalog for function side effect administration
Functions which have side effects (such as rand and next_value (sequences)),
are now called once per row, even if the function doesn't have arguments.
The last case expects functions/procs to be available with one argument
which isn't used (needed for the multiplex call).
order by needs selection columns (ie no relaxed semantics if there are
group by's)
this fixes bugs
[ 1723863 ] SQL Query Crashes Server - CRITICAL
[ 1723791 ] rand() is not executed for every row
Index: sql_schema.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_schema.mx,v
retrieving revision 1.129
retrieving revision 1.130
diff -u -d -r1.129 -r1.130
--- sql_schema.mx 10 May 2007 08:22:28 -0000 1.129
+++ sql_schema.mx 23 May 2007 22:05:59 -0000 1.130
@@ -1274,7 +1274,7 @@
next value for, this should be called once
foreach new value.
*/
- res = stmt_append(stmt_bat(cs,
stmt_basetable(t, t->base.name), INS),
push_project(stmt_bat(mvc_first_column(sql, t), stmt_basetable(t,
t->base.name), RDONLY), val));
+ res = stmt_append(stmt_bat(cs,
stmt_basetable(t, t->base.name), INS),
stmt_const(stmt_bat(mvc_first_column(sql, t), stmt_basetable(t, t->base.name),
RDONLY), val));
}
if (!res) {
return sql_error(sql, 02, "ALTER TABLE: failed
to create default value '%s'\n", cs->def ? cs->def : "NULL");
Index: sql_statement.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_statement.mx,v
retrieving revision 1.145
retrieving revision 1.146
diff -u -d -r1.145 -r1.146
--- sql_statement.mx 1 Apr 2007 22:08:57 -0000 1.145
+++ sql_statement.mx 23 May 2007 22:05:59 -0000 1.146
@@ -1171,8 +1171,8 @@
return s;
}
-stmt *
-stmt_const(stmt *s, stmt *val)
+static stmt *
+stmt_const_(stmt *s, stmt *val)
{
stmt *ns = stmt_create(st_const);
@@ -1185,6 +1185,87 @@
return ns;
}
+static stmt *
+push_project(stmt *rows, stmt *val)
+{
+ switch (val->type) {
+ case st_convert:
+ val->op1.stval = push_project(rows, val->op1.stval);
+ break;
+ case st_binop:
+ if (val->op4.funcval->func->side_effect) {
+ val->op1.stval = stmt_const_(stmt_dup(rows),
val->op1.stval);
+ } else {
+ val->op1.stval = push_project(rows, val->op1.stval);
+ val->op2.stval = push_project(rows, val->op2.stval);
+ }
+ break;
+ case st_unop:
+ if (val->op4.funcval->func->side_effect) {
+ val->op1.stval = stmt_const_(stmt_dup(rows),
val->op1.stval);
+ } else {
+ val->op1.stval = push_project(rows, val->op1.stval);
+ }
+ break;
+ case st_op:
+ if (val->op4.funcval->func->side_effect) {
+ /* change into a st_unop */
+ val->type = st_unop;
+ val->op1.stval = stmt_const_(stmt_dup(rows),
stmt_atom_int(0));
+ } else {
+ val = stmt_const_(stmt_dup(rows), val);
+ }
+ break;
+ default:
+ if (!val->nrcols)
+ val = stmt_const_(stmt_dup(rows), val);
+ return val;
+ }
+ val->nrcols = rows->nrcols;
+ return val;
+}
+
+static int
+has_side_effect(stmt *val)
+{
+ int se = 0;
+
+ switch (val->type) {
+ case st_convert:
+ se = has_side_effect(val->op1.stval);
+ break;
+ case st_binop:
+ se = val->op4.funcval->func->side_effect;
+ if (!se)
+ se = has_side_effect(val->op1.stval) +
+ has_side_effect(val->op2.stval);
+ break;
+ case st_unop:
+ se = val->op4.funcval->func->side_effect;
+ if (!se)
+ se = has_side_effect(val->op1.stval);
+ break;
+ case st_op:
+ se = val->op4.funcval->func->side_effect;
+ break;
+ default:
+ return se;
+ }
+ return se;
+}
+
+stmt *
+stmt_const(stmt *rows, stmt *val)
+{
+ if (has_side_effect(val)) {
+ stmt *x = push_project(rows, val);
+ stmt_destroy(rows);
+ return x;
+ } else {
+ return stmt_const_(rows, val);
+ }
+}
+
/* BEWARE stmt_mark marks the head, this while the mil mark is a mark tail
* Current implementation adds the reverses in stmt_mark nolonger in
* the generated code.
Index: sql_select.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_select.mx,v
retrieving revision 1.189
retrieving revision 1.190
diff -u -d -r1.189 -r1.190
--- sql_select.mx 19 May 2007 12:18:15 -0000 1.189
+++ sql_select.mx 23 May 2007 22:05:59 -0000 1.190
@@ -69,7 +69,6 @@
extern stmt *sql_and(mvc *sql, scope *scp, stmt *ls, stmt *rs, int f);
extern stmt *sql_Nop_(mvc *sql, char *fname, stmt *a1, stmt *a2, stmt *a3);
-
#endif /*_SQL_SELECT_H_*/
@c
@@ -1410,7 +1409,7 @@
dnode *o = orderby->data.lval->h;
/* first sort the groups */
- if (grp)
+ if (!sel && grp)
cur = stmt_order(stmt_dup(grp->grp), 1);
while (o) {
symbol *order = o->data.sym;
@@ -1425,7 +1424,7 @@
/* fall back to column references, ie those not in
the selection result */
- if (!sc) {
+ if (!sc && !grp) {
/* reset error */
sql->errstr[0] = '\0';
sql->session->status = 0;
@@ -3972,7 +3971,7 @@
}
if (s && subset && sn->orderby) {
- order = query_orderby(sql, scp, sn->orderby, s, subset, NULL);
+ order = query_orderby(sql, scp, sn->orderby, s, subset, grp);
if (!order) {
sql_select_cleanup(sql, s, subset, grp);
return sql_error(sql, 02, "SELECT: subquery result
missing");
Index: sql_updates.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_updates.mx,v
retrieving revision 1.122
retrieving revision 1.123
diff -u -d -r1.122 -r1.123
--- sql_updates.mx 13 May 2007 20:46:17 -0000 1.122
+++ sql_updates.mx 23 May 2007 22:05:59 -0000 1.123
@@ -37,9 +37,6 @@
extern stmt *sql_delete(mvc *sql, tvar *tv, sql_schema *schema, sql_table *t,
stmt *s, int output, int all);
extern stmt *sql_update(mvc *sql, sql_schema *schema, sql_table *t, stmt
**updates, list *l);
-/* the single result value needs to be multiplexed count(rows) times */
-extern stmt *push_project(stmt *rows, stmt *val);
-
#endif /*_SQL_UPDATES_H_*/
@c
@@ -1179,22 +1176,6 @@
return stmt_list(l);
}
-stmt *
-push_project(stmt *rows, stmt *val)
-{
- switch (val->type) {
- case st_binop:
- val->op2.stval = push_project(rows, val->op2.stval);
- case st_unop:
- case st_convert:
- val->op1.stval = push_project(rows, val->op1.stval);
- val->nrcols = rows->nrcols;
- return val;
- default:
- return stmt_const(stmt_dup(rows), val);
- }
-}
-
static stmt *
insert_into(mvc *sql, scope *scp, dlist *qname, dlist *columns, symbol
*val_or_q)
{
@@ -1396,7 +1377,7 @@
return sql_error(sql, 02,
"INSERT INTO: column '%s' has no valid default value", c->base.name);
}
if (ic && !(ic->key && ic->nrcols == 0))
- s = push_project(ic, s);
+ s = stmt_const(stmt_dup(ic), s);
inserts[i] = stmt_append(stmt_bat(c,
stmt_dup(tv->s), INS), s);
}
}
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins