Changeset: 857beb9621e1 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/857beb9621e1
Removed Files:
        monetdb5/optimizer/opt_bincopyfrom.c
        monetdb5/optimizer/opt_bincopyfrom.h
Modified Files:
        clients/Tests/MAL-signatures-hge.test
        clients/Tests/MAL-signatures.test
        clients/Tests/exports.stable.out
        monetdb5/optimizer/CMakeLists.txt
        monetdb5/optimizer/opt_fastpath.c
        monetdb5/optimizer/opt_pipes.c
        monetdb5/optimizer/opt_prelude.c
        monetdb5/optimizer/opt_prelude.h
        monetdb5/optimizer/opt_wrapper.c
        monetdb5/optimizer/optimizer.c
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql.h
        sql/backends/monet5/sql_bincopyfrom.c
        sql/storage/bat/bat_logger.c
        sql/test/BugTracker-2009/Tests/reorder.SF-2770608.test
        sql/test/Tests/setoptimizer.test
Branch: copyintobinary
Log Message:

Get rid of the opt_bincopyfrom optimizer


diffs (truncated from 609 to 300 lines):

diff --git a/clients/Tests/MAL-signatures-hge.test 
b/clients/Tests/MAL-signatures-hge.test
--- a/clients/Tests/MAL-signatures-hge.test
+++ b/clients/Tests/MAL-signatures-hge.test
@@ -47259,16 +47259,6 @@ pattern optimizer.aliases(X_0:str, X_1:s
 OPTwrapper;
 Alias removal optimizer
 optimizer
-bincopyfrom
-pattern optimizer.bincopyfrom():str 
-OPTwrapper;
-(empty)
-optimizer
-bincopyfrom
-pattern optimizer.bincopyfrom(X_0:str, X_1:str):str 
-OPTwrapper;
-Parallellize column loading
-optimizer
 candidates
 pattern optimizer.candidates():str 
 OPTwrapper;
@@ -48604,11 +48594,6 @@ pattern sql.importColumn(X_0:str, X_1:bi
 mvc_bin_import_column_wrap;
 Import a column from the given file
 sql
-importTable
-unsafe pattern sql.importTable(X_0:str, X_1:str, X_2:int, X_3:bit, 
X_4:str...):bat[:any]... 
-mvc_bin_import_table_wrap;
-Import a table from the files (fname)
-sql
 include
 unsafe pattern sql.include(X_0:str):void 
 SQLinclude;
diff --git a/clients/Tests/MAL-signatures.test 
b/clients/Tests/MAL-signatures.test
--- a/clients/Tests/MAL-signatures.test
+++ b/clients/Tests/MAL-signatures.test
@@ -35684,16 +35684,6 @@ pattern optimizer.aliases(X_0:str, X_1:s
 OPTwrapper;
 Alias removal optimizer
 optimizer
-bincopyfrom
-pattern optimizer.bincopyfrom():str 
-OPTwrapper;
-(empty)
-optimizer
-bincopyfrom
-pattern optimizer.bincopyfrom(X_0:str, X_1:str):str 
-OPTwrapper;
-Parallellize column loading
-optimizer
 candidates
 pattern optimizer.candidates():str 
 OPTwrapper;
@@ -37004,11 +36994,6 @@ pattern sql.importColumn(X_0:str, X_1:bi
 mvc_bin_import_column_wrap;
 Import a column from the given file
 sql
-importTable
-unsafe pattern sql.importTable(X_0:str, X_1:str, X_2:int, X_3:bit, 
X_4:str...):bat[:any]... 
-mvc_bin_import_table_wrap;
-Import a table from the files (fname)
-sql
 include
 unsafe pattern sql.include(X_0:str):void 
 SQLinclude;
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -1060,7 +1060,6 @@ const char *hgeRef;
 const char *identityRef;
 const char *ifthenelseRef;
 const char *importColumnRef;
-const char *importTableRef;
 void initHeartbeat(void);
 void initNamespace(void);
 void initParser(void);
diff --git a/monetdb5/optimizer/CMakeLists.txt 
b/monetdb5/optimizer/CMakeLists.txt
--- a/monetdb5/optimizer/CMakeLists.txt
+++ b/monetdb5/optimizer/CMakeLists.txt
@@ -12,7 +12,6 @@ target_sources(optimizer
   PRIVATE
   optimizer.c optimizer.h optimizer_private.h
   opt_aliases.c opt_aliases.h
-  opt_bincopyfrom.c opt_bincopyfrom.h
   opt_coercion.c opt_coercion.h
   opt_commonTerms.c opt_commonTerms.h
   opt_candidates.c opt_candidates.h
diff --git a/monetdb5/optimizer/opt_bincopyfrom.c 
b/monetdb5/optimizer/opt_bincopyfrom.c
deleted file mode 100644
--- a/monetdb5/optimizer/opt_bincopyfrom.c
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0.  If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * Copyright 1997 - July 2008 CWI, August 2008 - 2022 MonetDB B.V.
- */
-
-/* author Joeri van Ruth
- * This optimizer replaces calls to sql.importTable with a series of calls to
- * sql.importColumn.
- */
-#include "monetdb_config.h"
-#include "mal_builder.h"
-#include "opt_bincopyfrom.h"
-
-static str transform(MalBlkPtr mb, InstrPtr importTable);
-static int extract_column(MalBlkPtr mb, InstrPtr old, int idx, str proto_path, 
int proto_bat_var, int count_var, bool byteswap);
-
-str
-OPTbincopyfromImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci)
-{
-       str msg = MAL_SUCCEED;
-       InstrPtr *old_mb_stmt = NULL;
-       int actions = 0;
-       size_t old_ssize = 0;
-       size_t old_stop = 0;
-
-       (void)stk;
-
-       int found_at = -1;
-       for (int i = 0; i < mb->stop; i++) {
-               InstrPtr p = getInstrPtr(mb, i);
-               if (p->modname == sqlRef && p->fcnname == importTableRef) {
-                       found_at = i;
-                       break;
-               }
-       }
-       if (found_at == -1)
-               // we didn't find a reason to modify the plan
-               goto wrapup;
-
-       old_mb_stmt = mb->stmt;
-       old_ssize = mb->ssize;
-       old_stop = mb->stop;
-       if (newMalBlkStmt(mb, mb->stop + getInstrPtr(mb, found_at)->argc) < 0)
-               throw(MAL, "optimizer.bincopyfrom", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-
-       for (size_t i = 0; i < old_stop; i++) {
-               InstrPtr p = old_mb_stmt[i];
-               if (p->modname == sqlRef && p->fcnname == importTableRef) {
-                       msg = transform(mb, p);
-                       actions++;
-               } else {
-                       pushInstruction(mb, p);
-               }
-               if (msg != MAL_SUCCEED)
-                       goto end;
-       }
-
-end:
-       if (old_mb_stmt) {
-               for (size_t i = old_stop; i < old_ssize; i++)
-                       if (old_mb_stmt[i])
-                               pushInstruction(mb, old_mb_stmt[i]);
-               GDKfree(old_mb_stmt);
-       }
-
-       /* Defense line against incorrect plans */
-       if (actions > 0 && msg == MAL_SUCCEED) {
-               if (!msg)
-                       msg = chkTypes(cntxt->usermodule, mb, FALSE);
-               if (!msg)
-                       msg = chkFlow(mb);
-               if (!msg)
-                       msg = chkDeclarations(mb);
-       }
-       /* keep all actions taken as a post block comment */
-wrapup:
-       /* keep actions taken as a fake argument*/
-       (void) pushInt(mb,pci,actions);
-       return msg;
-}
-
-static str
-transform(MalBlkPtr mb, InstrPtr old)
-{
-       // prototype: (bat1, .., batN) := sql.importTable(schema, table, 
onclient, path1 , .. ,pathN);
-       int onclient_arg = *(int*)getVarValue(mb, getArg(old, old->retc + 2));
-       bool onserver = !onclient_arg;
-       bool onclient = !onserver;
-       bool byteswap = *(bit*)getVarValue(mb, getArg(old, old->retc + 3));
-
-       // In the following loop we pick a "prototype column".
-       // This is always a column with a non-nil path and will be the first 
column for
-       // which we emit code. We prefer a prototype column that is quick to 
import
-       // because ON SERVER, all other columns can be loaded in parallel once 
we've
-       // loaded the first one.
-       //
-       // Both ON SERVER and ON CLIENT, the prototype column is also used when 
emitting the
-       // columns with a nil path, by projecting nil values over it.
-       int prototype_idx = -1;
-       int prototype_type = TYPE_any;
-       str prototype_path = NULL;
-       for (int i = 0; i < old->retc; i++) {
-               int var = getArg(old, i);
-               int var_type = getVarType(mb, var);
-               int tail_type = ATOMstorage(getBatType(var_type));
-               if (tail_type >= prototype_type)
-                       continue;
-               int path_idx = old->retc + 4 + i;
-               int path_var = getArg(old, path_idx);
-               if (VALisnil(&getVarConstant(mb, path_var)))
-                       continue;
-               // this is the best so far
-               prototype_idx = i;
-               prototype_type = tail_type;
-               prototype_path = (str)getVarValue(mb, path_var);
-       }
-       if (prototype_idx < 0)
-               return createException(MAL, "optimizer.bincopyfrom", 
SQLSTATE(42000) "all paths are nil");
-
-       // Always emit the prototype column first
-       int prototype_count_var = extract_column(mb, old, prototype_idx, NULL, 
-1, -1, byteswap);
-       assert(mb->stop > 0);
-       int prototype_bat_var = getArg(getInstrPtr(mb, mb->stop - 1), 0);
-       assert(prototype_count_var == getArg(getInstrPtr(mb, mb->stop - 1), 1));
-
-       // Then emit the rest of the columns
-
-       int row_count_var = prototype_count_var;
-       for (int i = 0; i < old->retc; i++) {
-               if (i == prototype_idx)
-                       continue;
-               int new_row_count_var = extract_column(mb, old, i, 
prototype_path, prototype_bat_var, row_count_var, byteswap);
-               if (onclient)
-                       row_count_var = new_row_count_var; // chain the 
importColumn statements
-       }
-
-       freeInstruction(old);
-
-       return MAL_SUCCEED;
-}
-
-static int
-extract_column(MalBlkPtr mb, InstrPtr old, int idx, str proto_path, int 
proto_bat_var, int count_var, bool byteswap)
-{
-       int var = getArg(old, idx);
-       int var_type = getVarType(mb, var);
-
-       // The sql.importColumn operator takes a 'method' string to determine 
how to
-       // load the data. This leaves the door open to have multiple loaders 
for the
-       // same backend type, for example nul- and newline terminated strings.
-       // For the time being we just use the name of the storage type as the 
method
-       // name.
-       const char *method = ATOMname(getBatType(var_type));
-
-       int onclient = *(int*)getVarValue(mb, getArg(old, old->retc + 2));
-
-       int path_idx = old->retc + 4 + idx;
-       int path_var = getArg(old, path_idx);
-       str path = (str)getVarValue(mb, path_var);
-
-       if (!strNil(path)) {
-               if (proto_path != NULL && strcmp(proto_path, path) == 0) {
-                       // Same data as in the prototype column so reuse that 
var
-                       InstrPtr p = newInstructionArgs(mb, NULL, NULL, 2);
-                       p = pushArgument(mb, p, proto_bat_var);
-                       setReturnArgument(p, old->argv[idx]);
-                       pushInstruction(mb, p);
-                       return count_var;
-               } else {
-                       // Emit a new importColumn call
-                       InstrPtr p = newFcnCall(mb, sqlRef, importColumnRef);
-                       setReturnArgument(p, old->argv[idx]);
-                       int new_count_var = newTmpVariable(mb, TYPE_oid);
-                       p = pushReturn(mb, p, new_count_var);
-                       p = pushStr(mb, p, method);
-                       p = pushBit(mb, p, byteswap);
-                       p = pushStr(mb, p, path);
-                       p = pushInt(mb, p, onclient);
-                       if (count_var < 0)
-                               p = pushOid(mb, p, 0);
-                       else
-                               p = pushArgument(mb, p, count_var);
-                       return new_count_var;
-               }
-       } else {
-               // create an empty column by projecting the prototype
-               InstrPtr p = newFcnCall(mb, algebraRef, projectRef);
-               setReturnArgument(p, old->argv[idx]);
-               p = pushArgument(mb, p, proto_bat_var);
-               int proto_bat_type = getVarType(mb, var);
-               int proto_elem_type = getBatType(proto_bat_type);
-               p = pushNil(mb, p, proto_elem_type);
-               return count_var;
-       }
-}
diff --git a/monetdb5/optimizer/opt_bincopyfrom.h 
b/monetdb5/optimizer/opt_bincopyfrom.h
deleted file mode 100644
--- a/monetdb5/optimizer/opt_bincopyfrom.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0.  If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * Copyright 1997 - July 2008 CWI, August 2008 - 2022 MonetDB B.V.
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to