Changeset: b5f2ddb23b78 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/b5f2ddb23b78
Modified Files:
        monetdb5/modules/mal/pcre.c
        sql/backends/monet5/generator/generator.c
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_execute.c
        sql/backends/monet5/sql_gencode.c
        sql/backends/monet5/sql_scenario.c
        sql/backends/monet5/sql_upgrades.c
        sql/server/rel_dump.c
        sql/server/rel_rel.h
        sql/server/rel_schema.c
        sql/server/rel_select.c
        sql/server/sql_mvc.c
        sql/server/sql_mvc.h
        sql/server/sql_parser.y
        sql/storage/store.c
        
sql/test/BugTracker-2018/Tests/count_from_commented_function_signatures.Bug-6542.test
        
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-3join-query.test
        testing/Mtest.py.in
        tools/mserver/mserver5.c
Branch: resource_management
Log Message:

merge with default


diffs (truncated from 18068 to 300 lines):

diff --git a/.editorconfig b/.editorconfig
--- a/.editorconfig
+++ b/.editorconfig
@@ -5,7 +5,7 @@ root = true
 end_of_line = lf
 insert_final_newline = true
 
-[*.{c,h}{,.in}]
+[*.{c,h,y}{,.in}]
 indent_style = tab
 tab_width = 4
 indent_size = tab
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -2559,7 +2559,7 @@ doFile(Mapi mid, stream *fp, bool useins
                                                        " 
''''||replace(rp.minimum, '''', '''''')||'''' as minimum,"
                                                        " 
''''||replace(rp.maximum, '''', '''''')||'''' as maximum,"
                                                        " rp.with_nulls,"
-                                                       " 
'('||group_concat(''''||replace(vp.value, '''', '''''')||'''', ',' order by 
vp.value)||')' as values,"
+                                                       " 
'('||group_concat(''''||replace(vp.value, '''', '''''')||'''', ','%s)||')' as 
\"values\","
                                                        " count(vp.value) <> 
count(*) as has_nulls"
                                                        " from sys.schemas as 
s1,"
                                                        " sys._tables as t1 
left outer join sys.table_partitions as tp on t1.id = tp.table_id left outer 
join sys._columns as c1 on tp.column_id = c1.id,"
@@ -2574,10 +2574,25 @@ doFile(Mapi mid, stream *fp, bool useins
                                                        " d.id = t2.id"
                                                        " group by s1.name, 
t1.name, s2.name, t2.name, c1.name, tp.expression, tp.type, rp.minimum, 
rp.maximum, rp.with_nulls"
                                                        " order by s1.name, 
t1.name, s2.name, t2.name";
+                                               const char *ordering = "";
                                                char *squery = NULL;
                                                size_t squerylen = 0;
                                                char *tquery = NULL;
                                                size_t tquerylen = 0;
+                                               hdl = mapi_query(mid, "select 
value from sys.env() where name = 'monet_version'");
+                                               CHECK_RESULT(mid, hdl, buf, fp);
+                                               if (fetch_row(hdl) > 0) {
+                                                       const char *version = 
mapi_fetch_field(hdl, 0);
+                                                       int major, minor, patch;
+                                                       if (version &&
+                                                               sscanf(version, 
"%d.%d.%d",
+                                                                          
&major, &minor, &patch) == 3 &&
+                                                               major == 11 &&
+                                                               minor >= 53)
+                                                               ordering = " 
order by vp.value";
+                                               }
+                                               mapi_close_handle(hdl);
+                                               hdl = NULL;
                                                if (sname) {
                                                        sname = sescape(sname);
                                                        squerylen = 
strlen(sname) + 21;
@@ -2604,9 +2619,9 @@ doFile(Mapi mid, stream *fp, bool useins
                                                        free(tname);
                                                        tname = NULL;
                                                }
-                                               size_t qlen = sizeof(mquery) + 
squerylen + tquerylen;
+                                               size_t qlen = sizeof(mquery) + 
strlen(ordering) + squerylen + tquerylen;
                                                char *query = malloc(qlen);
-                                               snprintf(query, qlen, mquery, 
squery ? squery : "", tquery ? tquery : "");
+                                               snprintf(query, qlen, mquery, 
ordering, squery ? squery : "", tquery ? tquery : "");
                                                free(squery);
                                                free(tquery);
                                                hdl = mapi_query(mid, query);
diff --git a/clients/mapiclient/mhelp.c b/clients/mapiclient/mhelp.c
--- a/clients/mapiclient/mhelp.c
+++ b/clients/mapiclient/mhelp.c
@@ -410,9 +410,16 @@ SQLhelp sqlhelp1[] = {
         NULL,
         "See also 
https://www.monetdb.org/documentation/user-guide/sql-manual/data-manipulation/prepare-statement/"},
        {"EXPLAIN",
-        "Give MAL execution plan for the SQL statement",
-        "EXPLAIN statement",
+        "Display logical or physical execution plan for the SQL statement.",
+        "EXPLAIN [BEFORE|AFTER] [step] [SHOW DETAILS] statement\n"
+        "step [REL_UNNEST|REL_REWRITE|PHYSICAL]",
         NULL,
+        "Plain EXPLAIN defaults to logical execution plan.\n"
+        "Use REL_UNNEST|REL_REWRITE|PHYSICAL to specify compilation step to 
show.\n"
+        "Use BEFORE|AFTER to specify moment of compilation step\n"
+        "to output. The default is AFTER.\n"
+        "SHOW DETAILS displays column properties, rewriter number of changes\n"
+        "and time spent.\n"
         "See also 
https://www.monetdb.org/documentation/admin-guide/debugging-features/explain-sql-stmt/"},
        {"EXTRACT",
         "Built-in function",
@@ -446,11 +453,6 @@ SQLhelp sqlhelp1[] = {
         "[ WITH cte_list ] MERGE INTO qname [ [AS] ident ] USING table_ref [ 
[AS] ident ] ON search_condition merge_list",
         "cte_list,table_ref,search_condition,merge_list",
         "See also: 
https://www.monetdb.org/documentation/user-guide/blog-archive/merge-statements/"},
-       {"PLAN",
-        "Give relational execution plan for the SQL statement",
-        "PLAN statement",
-        NULL,
-        "See also 
https://www.monetdb.org/documentation/admin-guide/debugging-features/plan-sql-stmt/"},
        {"PREPARE",
         "Prepare a SQL DML statement with optional question-mark parameter 
markers",
         "PREPARE statement",
@@ -551,7 +553,7 @@ SQLhelp sqlhelp1[] = {
         "joined_table,join_type",
         "See also 
https://www.monetdb.org/documentation/user-guide/sql-manual/data-manipulation/table-expressions/"},
        {"TRACE",
-        "Give execution trace for the SQL statement",
+        "Trace engine execution for the SQL statement. Output can be accessed 
via tracelog view.",
         "TRACE statement",
         NULL,
         "See also 
https://www.monetdb.org/documentation/admin-guide/debugging-features/trace-sql-stmt/"},
diff --git a/clients/odbc/tests/ODBCgetInfo.c b/clients/odbc/tests/ODBCgetInfo.c
--- a/clients/odbc/tests/ODBCgetInfo.c
+++ b/clients/odbc/tests/ODBCgetInfo.c
@@ -663,7 +663,7 @@ const struct {
                        "MATCHED,MAXVALUE,MEDIUMINT,MERGE,MINVALUE,"
                        "NAME,NATIVE,NEW,NOW,NULLS,"
                        "OBJECT,OFFSET,OLD,OPTIONS,ORDERED,OTHERS,OVER,"
-                       "PARTITION,PASSWORD,PATH,PLAN,PRECEDING,PREP,QUARTER,"
+                       "PARTITION,PASSWORD,PATH,PRECEDING,PREP,QUARTER,"
                        
"RANGE,RECORDS,REFERENCING,RELEASE,REMOTE,RENAME,REPEATABLE,"
                        
"REPLACE,REPLICA,RESTART,RETURN,RETURNS,ROLE,ROLLUP,ROW,"
                        "SAMPLE,SAVEPOINT,SEED,SEQUENCE,SERIAL,SERIALIZABLE,"
diff --git a/clients/odbc/tests/ODBCmetadata.c 
b/clients/odbc/tests/ODBCmetadata.c
--- a/clients/odbc/tests/ODBCmetadata.c
+++ b/clients/odbc/tests/ODBCmetadata.c
@@ -324,7 +324,7 @@ compareResultOptClose(SQLHANDLE stmt, SQ
 
 /*
  * Utility function to query the gdk_nr_threads value from the server.
- * The output of some queries (EXPLAIN, TRACE) differ when the server
+ * The output of some queries (EXPLAIN PHYSICAL, TRACE) differ when the server
  * is started with 1 thread, as is done in our testweb.
  */
 static int
@@ -1519,9 +1519,9 @@ main(int argc, char **argv)
                "ORDERID        LINES   PARTID  QUANTITY\n"
                "INTEGER        INTEGER INTEGER DECIMAL(9,3)\n");
 
-       // test PLAN SELECT query
-       ret = SQLExecDirect(stmt, (SQLCHAR *) "PLAN SELECT * from 
odbctst.\"LINES\";", SQL_NTS);
-       compareResult(stmt, ret, "PLAN SELECT * from odbctst.\"LINES\"",
+       // test EXPLAIN SHOW DETAILS SELECT query
+       ret = SQLExecDirect(stmt, (SQLCHAR *) "EXPLAIN SHOW DETAILS SELECT * 
from odbctst.\"LINES\";", SQL_NTS);
+       compareResult(stmt, ret, "EXPLAIN SHOW DETAILS SELECT * from 
odbctst.\"LINES\"",
                "Resultset with 1 columns\n"
                "Resultset with 3 rows\n"
                "rel\n"
@@ -1531,15 +1531,15 @@ main(int argc, char **argv)
                ") [ \"LINES\".\"ORDERID\" NOT NULL UNIQUE HASHCOL , 
\"LINES\".\"LINES\" NOT NULL UNIQUE, \"LINES\".\"PARTID\" NOT NULL UNIQUE, 
\"LINES\".\"QUANTITY\" NOT NULL UNIQUE ]\n");
 
        // test EXPLAIN SELECT query
-       ret = SQLExecDirect(stmt, (SQLCHAR *) "EXPLAIN SELECT * from 
odbctst.\"LINES\";", SQL_NTS);
-       compareResult(stmt, ret, "EXPLAIN SELECT * from odbctst.\"LINES\"",
+       ret = SQLExecDirect(stmt, (SQLCHAR *) "EXPLAIN PHYSICAL SELECT * from 
odbctst.\"LINES\";", SQL_NTS);
+       compareResult(stmt, ret, "EXPLAIN PHYSICAL SELECT * from 
odbctst.\"LINES\"",
            nrServerThreads > 1 ?
                "Resultset with 1 columns\n"
                "Resultset with 17 rows\n"
                "mal\n"
                "WLONGVARCHAR(174)\n"
                "function user.main():void;\n"
-               "    X_1:void := querylog.define(\"explain select * from 
odbctst.\\\"LINES\\\";\":str, \"default_pipe\":str, 26:int);\n"
+               "    X_1:void := querylog.define(\"explain physical select * 
from odbctst.\\\"LINES\\\";\":str, \"default_pipe\":str, 26:int);\n"
                "\n"
                "    X_33:bat[:int] := bat.new(nil:int);\n"
                "    X_34:bat[:int] := bat.new(nil:int);\n"
@@ -1560,7 +1560,7 @@ main(int argc, char **argv)
                "mal\n"
                "WLONGVARCHAR(174)\n"
                "function user.main():void;\n"
-               "    X_1:void := querylog.define(\"explain select * from 
odbctst.\\\"LINES\\\";\":str, \"default_pipe\":str, 26:int);\n"
+               "    X_1:void := querylog.define(\"explain physical select * 
from odbctst.\\\"LINES\\\";\":str, \"default_pipe\":str, 26:int);\n"
                "    X_33:bat[:int] := bat.new(nil:int);\n"
                "    X_34:bat[:int] := bat.new(nil:int);\n"
                "    X_35:bat[:int] := bat.new(nil:int);\n"
diff --git a/monetdb5/modules/mal/pcre.c b/monetdb5/modules/mal/pcre.c
--- a/monetdb5/modules/mal/pcre.c
+++ b/monetdb5/modules/mal/pcre.c
@@ -26,7 +26,7 @@
 #include "mal_exception.h"
 
 #include <wchar.h>
-#include <wctype.h>
+//#include <wctype.h>
 
 #ifdef HAVE_LIBPCRE
 #define PCRE2_CODE_UNIT_WIDTH 8
@@ -451,7 +451,7 @@ pcre_replace_bat(allocator *ma, BAT **re
        BUN p, q;
        PCRE2_SIZE len_replacement = (PCRE2_SIZE) strlen(replacement);
        PCRE2_SPTR origin_str;
-       PCRE2_SIZE max_dest_size = 0;
+       PCRE2_SIZE max_dest_size = 0, init_size = 0;
 
        while (*flags) {
                switch (*flags) {
@@ -501,7 +501,7 @@ pcre_replace_bat(allocator *ma, BAT **re
 
        /* the buffer for all destination strings is allocated only once,
         * and extended when needed */
-       max_dest_size = len_replacement + 1;
+       init_size = max_dest_size = 64*1024;
        tmpres = ma_alloc(ma, max_dest_size);
        if (tmpbat == NULL || tmpres == NULL) {
                pcre2_match_data_free(match_data);
@@ -527,6 +527,10 @@ pcre_replace_bat(allocator *ma, BAT **re
                        throw(MAL, global ? "batpcre.replace" : 
"batpcre.replace_first",
                                  SQLSTATE(HY013) MAL_MALLOC_FAIL);
                }
+               if (max_dest_size <= init_size)
+                       max_dest_size = init_size;
+               else /* buffer is enlarged */
+                       init_size = max_dest_size;
        }
        bat_iterator_end(&origin_strsi);
        pcre2_match_data_free(match_data);
diff --git a/sql/ChangeLog b/sql/ChangeLog
--- a/sql/ChangeLog
+++ b/sql/ChangeLog
@@ -1,6 +1,15 @@
 # ChangeLog file for sql
 # This file is updated with Maddlog
 
+* Fri Oct  3 2025 Lucas Pereira <[email protected]>
+  - EXPLAIN now supports a BEFORE/AFTER REL_UNNEST/REL_REWRITE/PHYSICAL
+  clause to indicate which phase of query compilation to show.  A plain
+  EXPLAIN is equivalent to EXPLAIN BEFORE PHYSICAL, which is what PLAN
+  used to do. The old EXPLAIN is now EXPLAIN PHYSICAL. SHOW DETAILS
+  includes more information about properties, rewriters number of
+  changes and time spent.
+- The PLAN keyword has been removed.
+
 * Tue Sep 16 2025 Sjoerd Mullender <[email protected]>
 - The TRACE prefix for SQL queries now no longer produces two result sets.
   Before, the first result set was the result of the query, and the
diff --git 
a/sql/backends/monet5/generator/Tests/execute-privilege-for-public.test 
b/sql/backends/monet5/generator/Tests/execute-privilege-for-public.test
--- a/sql/backends/monet5/generator/Tests/execute-privilege-for-public.test
+++ b/sql/backends/monet5/generator/Tests/execute-privilege-for-public.test
@@ -184,6 +184,7 @@ SELECT * from generate_series(cast('2024
 2024-02-28
 2024-05-28
 2024-08-28
+2024-11-28
 
 @connection(id=c2, username=test, password=test)
 query T nosort
diff --git a/sql/backends/monet5/generator/generator.c 
b/sql/backends/monet5/generator/generator.c
--- a/sql/backends/monet5/generator/generator.c
+++ b/sql/backends/monet5/generator/generator.c
@@ -250,7 +250,7 @@ VLTgenerator_table_(BAT **result, Client
                                throw(MAL, "generator.table", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                        v = (date *) Tloc(bn, 0);
                        BUN c;
-                       for (c = 0; c < n && f < l; c++) {
+                       for (c = 0; f < l; c++) {
                                *v++ = f;
                                f = date_add_month(f, s);
                                if (is_date_nil(f)) {
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -1152,13 +1152,17 @@ exp2bin_coalesce(backend *be, sql_exp *f
        sql_subfunc *and = sql_bind_func(be->mvc, "sys", "and", bt, bt, F_FUNC, 
true, true);
        sql_subfunc *not = sql_bind_func(be->mvc, "sys", "not", bt, NULL, 
F_FUNC, true, true);
 
+       list *exps = fe->l;
+       if (list_length(exps) == 1) {
+               sql_exp *e = exps->h->data;
+               return exp_bin(be, e, left, right, NULL, NULL, NULL, isel, 
depth+1, 0, 1);
+       }
        if (single_value) {
                /* var_x = nil; */
                nme = number2name(name, sizeof(name), ++be->mvc->label);
                (void)stmt_var(be, NULL, nme, exp_subtype(fe), 1, 2);
        }
 
-       list *exps = fe->l;
        for (node *en = exps->h; en; en = en->next) {
                sql_exp *e = en->data;
 
@@ -1705,6 +1709,9 @@ exp_bin(backend *be, sql_exp *e, stmt *l
                                        if (!f->func->s && 
!strcmp(f->func->base.name, "window_bound")
                                                && exps->h->next && 
list_length(f->func->ops) == 6 && en == exps->h->next && left->nrcols)
                                                es = stmt_const(be, 
bin_find_smallest_column(be, left), es);
+                                       if (!f->func->s && 
(!strcmp(f->func->base.name, "first_value") || !strcmp(f->func->base.name, 
"last_value"))
+                                               && (!en->next || 
!en->next->next) && list_length(f->func->ops) == 1 && left->nrcols)
+                                               es = stmt_const(be, 
bin_find_smallest_column(be, left), es);
                                }
                                if (es->nrcols > nrcols)
                                        nrcols = es->nrcols;
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -144,7 +144,8 @@ sql_symbol2relation(backend *be, symbol 
 
        lng t_begin = GDKusec();
        storage_based_opt = value_based_opt && rel && !is_ddl(rel->op);
-       if (rel && !(rel->op == op_ddl && rel->card == CARD_ATOM && rel->flag 
== ddl_psm && (be->mvc->emod & mod_exec) != 0)) { /* no need to optimize exec */
+       if (rel && !(rel->op == op_ddl && rel->card == CARD_ATOM &&
+                                rel->flag == ddl_psm && (be->mvc->emod == 
mod_exec) != 0)) { /* no need to optimize exec */
                if (rel)
                        rel = sql_processrelation(be->mvc, rel, profile, 1, 
value_based_opt, storage_based_opt);
                if (rel && (rel_no_mitosis(be->mvc, rel) || 
rel_need_distinct_query(rel)))
@@ -5588,6 +5589,10 @@ SQLread_dump_rel(Client cntxt, MalBlkPtr
        if (refs == NULL)
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to