Changeset: a5c4bc890a89 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/a5c4bc890a89
Modified Files:
        sql/server/rel_psm.c
        sql/server/sql_parser.y
Branch: default
Log Message:

implement feature request bug #7500


diffs (237 lines):

diff --git a/sql/server/rel_psm.c b/sql/server/rel_psm.c
--- a/sql/server/rel_psm.c
+++ b/sql/server/rel_psm.c
@@ -614,6 +614,69 @@ has_return( list *l )
 }
 
 static list *
+psm_analyze(sql_query *query, dlist *qname, dlist *columns)
+{
+       mvc *sql = query->sql;
+       const char *sname = qname_schema(qname), *tname = 
qname_schema_object(qname);
+       list *tl = sa_list(sql->sa), *exps = sa_list(sql->sa), *analyze_calls = 
sa_list(sql->sa);
+       sql_subfunc *f = NULL;
+       sql_subtype tpe;
+
+       if (!sql_find_subtype(&tpe, "varchar", 1024, 0))
+               return sql_error(sql, 02, SQLSTATE(HY013) "varchar type 
missing?");
+
+       if (sname && tname) {
+               sql_table *t = NULL;
+
+               if (!(t = find_table_or_view_on_scope(sql, NULL, sname, tname, 
"ANALYZE", false)))
+                       return NULL;
+               if (isDeclaredTable(t))
+                       return sql_error(sql, 02, SQLSTATE(42000) "Cannot 
analyze a declared table");
+               sname = t->s->base.name;
+       }
+       /* call analyze( [schema, [ table ]] ) */
+       if (sname) {
+               sql_exp *sname_exp = exp_atom_str(sql->sa, sname, &tpe);
+
+               list_append(exps, sname_exp);
+               list_append(tl, exp_subtype(sname_exp));
+       }
+       if (tname) {
+               sql_exp *tname_exp = exp_atom_str(sql->sa, tname, &tpe);
+
+               list_append(exps, tname_exp);
+               list_append(tl, exp_subtype(tname_exp));
+
+               if (columns)
+                       list_append(tl, exp_subtype(tname_exp));
+       }
+       if (!columns) {
+               if (!(f = sql_bind_func_(sql, "sys", "analyze", tl, F_PROC, 
true, false)))
+                       return sql_error(sql, ERR_NOTFOUND, SQLSTATE(42000) 
"Analyze procedure missing");
+               if (!execute_priv(sql, f->func))
+                       return sql_error(sql, 02, SQLSTATE(42000) "No privilege 
to call analyze procedure");
+               list_append(analyze_calls, exp_op(sql->sa, exps, f));
+       } else {
+               if (!sname || !tname)
+                       return sql_error(sql, ERR_NOTFOUND, SQLSTATE(42000) 
"Analyze schema or table name missing");
+               if (!(f = sql_bind_func_(sql, "sys", "analyze", tl, F_PROC, 
true, false)))
+                       return sql_error(sql, ERR_NOTFOUND, SQLSTATE(42000) 
"Analyze procedure missing");
+               if (!execute_priv(sql, f->func))
+                       return sql_error(sql, 02, SQLSTATE(42000) "No privilege 
to call analyze procedure");
+               for(dnode *n = columns->h; n; n = n->next) {
+                       const char *cname = n->data.sval;
+                       list *nexps = list_dup(exps, NULL);
+                       sql_exp *cname_exp = exp_atom_str(sql->sa, cname, &tpe);
+
+                       list_append(nexps, cname_exp);
+                       /* call analyze( opt_minmax, opt_sample_size, sname, 
tname, cname) */
+                       list_append(analyze_calls, exp_op(sql->sa, nexps, f));
+               }
+       }
+       return analyze_calls;
+}
+
+static list *
 sequential_block(sql_query *query, sql_subtype *restype, list *restypelist, 
dlist *blk, char *opt_label, int is_func)
 {
        mvc *sql = query->sql;
@@ -654,6 +717,11 @@ sequential_block(sql_query *query, sql_s
                case SQL_CASE:
                        res = rel_psm_case(query, restype, restypelist, 
s->data.lval->h, is_func);
                        break;
+               case SQL_ANALYZE: {
+                       dlist *l = s->data.lval;
+
+                       reslist = psm_analyze(query, l->h->data.lval /* 
qualified table name */, l->h->next->data.lval /* opt list of column */);
+               }       break;
                case SQL_CALL:
                        assert(s->type == type_symbol);
                        res = rel_psm_call(query, s->data.sym);
@@ -1427,69 +1495,6 @@ drop_trigger(mvc *sql, dlist *qname, int
        return rel_drop_trigger(sql, tr->t->s->base.name, tname, if_exists);
 }
 
-static sql_rel *
-psm_analyze(sql_query *query, dlist *qname, dlist *columns)
-{
-       mvc *sql = query->sql;
-       const char *sname = qname_schema(qname), *tname = 
qname_schema_object(qname);
-       list *tl = sa_list(sql->sa), *exps = sa_list(sql->sa), *analyze_calls = 
sa_list(sql->sa);
-       sql_subfunc *f = NULL;
-       sql_subtype tpe;
-
-       if (!sql_find_subtype(&tpe, "varchar", 1024, 0))
-               return sql_error(sql, 02, SQLSTATE(HY013) "varchar type 
missing?");
-
-       if (sname && tname) {
-               sql_table *t = NULL;
-
-               if (!(t = find_table_or_view_on_scope(sql, NULL, sname, tname, 
"ANALYZE", false)))
-                       return NULL;
-               if (isDeclaredTable(t))
-                       return sql_error(sql, 02, SQLSTATE(42000) "Cannot 
analyze a declared table");
-               sname = t->s->base.name;
-       }
-       /* call analyze( [schema, [ table ]] ) */
-       if (sname) {
-               sql_exp *sname_exp = exp_atom_str(sql->sa, sname, &tpe);
-
-               list_append(exps, sname_exp);
-               list_append(tl, exp_subtype(sname_exp));
-       }
-       if (tname) {
-               sql_exp *tname_exp = exp_atom_str(sql->sa, tname, &tpe);
-
-               list_append(exps, tname_exp);
-               list_append(tl, exp_subtype(tname_exp));
-
-               if (columns)
-                       list_append(tl, exp_subtype(tname_exp));
-       }
-       if (!columns) {
-               if (!(f = sql_bind_func_(sql, "sys", "analyze", tl, F_PROC, 
true, false)))
-                       return sql_error(sql, ERR_NOTFOUND, SQLSTATE(42000) 
"Analyze procedure missing");
-               if (!execute_priv(sql, f->func))
-                       return sql_error(sql, 02, SQLSTATE(42000) "No privilege 
to call analyze procedure");
-               list_append(analyze_calls, exp_op(sql->sa, exps, f));
-       } else {
-               if (!sname || !tname)
-                       return sql_error(sql, ERR_NOTFOUND, SQLSTATE(42000) 
"Analyze schema or table name missing");
-               if (!(f = sql_bind_func_(sql, "sys", "analyze", tl, F_PROC, 
true, false)))
-                       return sql_error(sql, ERR_NOTFOUND, SQLSTATE(42000) 
"Analyze procedure missing");
-               if (!execute_priv(sql, f->func))
-                       return sql_error(sql, 02, SQLSTATE(42000) "No privilege 
to call analyze procedure");
-               for(dnode *n = columns->h; n; n = n->next) {
-                       const char *cname = n->data.sval;
-                       list *nexps = list_dup(exps, NULL);
-                       sql_exp *cname_exp = exp_atom_str(sql->sa, cname, &tpe);
-
-                       list_append(nexps, cname_exp);
-                       /* call analyze( opt_minmax, opt_sample_size, sname, 
tname, cname) */
-                       list_append(analyze_calls, exp_op(sql->sa, nexps, f));
-               }
-       }
-       return rel_psm_block(sql->sa, analyze_calls);
-}
-
 static sql_rel*
 create_table_from_loader(sql_query *query, dlist *qname, symbol *fcall)
 {
@@ -1630,7 +1635,8 @@ rel_psm(sql_query *query, symbol *s)
                dlist *l = s->data.lval;
 
                /* Jan2022 update: The 'sample' and 'minmax' parameters are now 
ignored because they are no longer used in the backend */
-               ret = psm_analyze(query, l->h->data.lval /* qualified table 
name */, l->h->next->data.lval /* opt list of column */);
+               list *calls = psm_analyze(query, l->h->data.lval /* qualified 
table name */, l->h->next->data.lval /* opt list of column */);
+               ret = rel_psm_block(sql->sa, calls);
                sql->type = Q_UPDATE;
        }       break;
        default:
diff --git a/sql/server/sql_parser.y b/sql/server/sql_parser.y
--- a/sql/server/sql_parser.y
+++ b/sql/server/sql_parser.y
@@ -204,6 +204,7 @@ int yydebug=1;
        aggr_or_window_ref
        alter_statement
        alter_table_element
+       analyze_statement
        and_exp
        assignment
        atom
@@ -959,6 +960,16 @@ declare:
     DECLARE
 
        /* schema definition language */
+analyze_statement:
+   ANALYZE qname opt_column_list opt_sample opt_minmax
+               { dlist *l = L();
+               append_list(l, $2);
+               append_list(l, $3);
+               append_symbol(l, $4);
+               append_int(l, $5);
+               $$ = _symbol_create_list( SQL_ANALYZE, l); }
+ ;
+
 sql:
     schema
  |  grant
@@ -968,14 +979,8 @@ sql:
  |  alter_statement
  |  declare_statement
  |  set_statement
- |  ANALYZE qname opt_column_list opt_sample opt_minmax
-               { dlist *l = L();
-               append_list(l, $2);
-               append_list(l, $3);
-               append_symbol(l, $4);
-               append_int(l, $5);
-               $$ = _symbol_create_list( SQL_ANALYZE, l); }
  |  call_procedure_statement
+ |  analyze_statement
  |  comment_on_statement
  ;
 
@@ -2389,6 +2394,9 @@ procedure_statement:
     |   declare_statement
     |   set_statement
     |  control_statement
+    |   call_procedure_statement
+    |  call_statement
+    |   analyze_statement
     |   select_statement_single_row
     ;
 
@@ -2400,13 +2408,14 @@ trigger_procedure_statement:
     |   declare_statement
     |   set_statement
     |  control_statement
+    |   call_procedure_statement
+    |  call_statement
+    |   analyze_statement
     |   select_statement_single_row
     ;
 
 control_statement:
-       call_procedure_statement
-    |  call_statement
-    |   while_statement
+        while_statement
     |   if_statement
     |   case_statement
     |  return_statement
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to