LCOV - code coverage report
Current view: top level - sql/backends/monet5 - sql_orderidx.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 80 0.0 %
Date: 2024-12-20 21:24:02 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /*
       2             :  * SPDX-License-Identifier: MPL-2.0
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * Copyright 2024 MonetDB Foundation;
       9             :  * Copyright August 2008 - 2023 MonetDB B.V.;
      10             :  * Copyright 1997 - July 2008 CWI.
      11             :  */
      12             : 
      13             : /* (c) M.L. Kersten
      14             :  * The order index interface routines are defined here.
      15             : */
      16             : #include "monetdb_config.h"
      17             : #include "mal_backend.h"
      18             : #include "sql_scenario.h"
      19             : #include "sql_result.h"
      20             : #include "sql_gencode.h"
      21             : #include "sql_optimizer.h"
      22             : #include "sql_env.h"
      23             : #include "sql_mvc.h"
      24             : #include "sql_orderidx.h"
      25             : #include "orderidx.h"
      26             : #include "sql_scenario.h"
      27             : 
      28             : str
      29           0 : sql_createorderindex(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      30             : {
      31           0 :         mvc *m = NULL;
      32           0 :         str msg = getSQLContext(cntxt, mb, &m, NULL);
      33           0 :         str sch,tbl,col;
      34           0 :         sql_schema *s;
      35           0 :         sql_table *t;
      36           0 :         sql_column *c;
      37           0 :         BAT *b = NULL, *nb = NULL;
      38             : 
      39           0 :         if (msg != MAL_SUCCEED || (msg = checkSQLContext(cntxt)) != NULL)
      40           0 :                 return msg;
      41             : 
      42           0 :         sch = *getArgReference_str(stk, pci, 1);
      43           0 :         tbl = *getArgReference_str(stk, pci, 2);
      44           0 :         col = *getArgReference_str(stk, pci, 3);
      45           0 :         if (strNil(sch))
      46           0 :                 throw(SQL, "sql.createorderindex", SQLSTATE(42000) "Schema name cannot be NULL");
      47           0 :         if (strNil(tbl))
      48           0 :                 throw(SQL, "sql.createorderindex", SQLSTATE(42000) "Table name cannot be NULL");
      49           0 :         if (strNil(col))
      50           0 :                 throw(SQL, "sql.createorderindex", SQLSTATE(42000) "Column name cannot be NULL");
      51             : 
      52           0 :         if (!(s = mvc_bind_schema(m, sch)))
      53           0 :                 throw(SQL, "sql.createorderindex", SQLSTATE(3FOOO) "Unknown schema %s", sch);
      54           0 :         if (!mvc_schema_privs(m, s))
      55           0 :                 throw(SQL, "sql.createorderindex", SQLSTATE(42000) "Access denied for %s to schema '%s'", get_string_global_var(m, "current_user"), s->base.name);
      56           0 :         if (!(t = mvc_bind_table(m, s, tbl)))
      57           0 :                 throw(SQL, "sql.createorderindex", SQLSTATE(42S02) "Unknown table %s.%s", sch, tbl);
      58           0 :         if (!isTable(t))
      59           0 :                 throw(SQL, "sql.createorderindex", SQLSTATE(42000) "%s '%s' is not persistent", TABLE_TYPE_DESCRIPTION(t->type, t->properties), t->base.name);
      60           0 :         if (!(c = mvc_bind_column(m, t, col)))
      61           0 :                 throw(SQL, "sql.createorderindex", SQLSTATE(38000) "Unknown column %s.%s.%s", sch, tbl, col);
      62           0 :         sqlstore *store = m->session->tr->store;
      63           0 :         if (!(b = store->storage_api.bind_col(m->session->tr, c, RDONLY)))
      64           0 :                 throw(SQL,"sql.createorderindex", SQLSTATE(HY005) "Column can not be accessed");
      65           0 :         if (VIEWtparent(b)) {
      66           0 :                 nb = BBP_desc(VIEWtparent(b));
      67           0 :                 BBPunfix(b->batCacheid);
      68           0 :                 if (!(b = BATdescriptor(nb->batCacheid)))
      69           0 :                         throw(SQL,"sql.createorderindex", SQLSTATE(HY005) "Column can not be accessed");
      70             :         }
      71             :         /* create the ordered index on the column */
      72           0 :         msg = OIDXcreateImplementation(cntxt, newBatType(b->ttype), b, -1);
      73           0 :         BBPunfix(b->batCacheid);
      74           0 :         return msg;
      75             : }
      76             : 
      77             : str
      78           0 : sql_droporderindex(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      79             : {
      80           0 :         mvc *m = NULL;
      81           0 :         str msg = getSQLContext(cntxt, mb, &m, NULL);
      82           0 :         str sch,tbl,col;
      83           0 :         sql_schema *s;
      84           0 :         sql_table *t;
      85           0 :         sql_column *c;
      86           0 :         BAT *b = NULL, *nb = NULL;
      87             : 
      88           0 :         if (msg != MAL_SUCCEED || (msg = checkSQLContext(cntxt)) != NULL)
      89           0 :                 return msg;
      90             : 
      91           0 :         sch = *getArgReference_str(stk, pci, 1);
      92           0 :         tbl = *getArgReference_str(stk, pci, 2);
      93           0 :         col = *getArgReference_str(stk, pci, 3);
      94           0 :         if (strNil(sch))
      95           0 :                 throw(SQL, "sql.droporderindex", SQLSTATE(42000) "Schema name cannot be NULL");
      96           0 :         if (strNil(tbl))
      97           0 :                 throw(SQL, "sql.droporderindex", SQLSTATE(42000) "Table name cannot be NULL");
      98           0 :         if (strNil(col))
      99           0 :                 throw(SQL, "sql.droporderindex", SQLSTATE(42000) "Column name cannot be NULL");
     100             : 
     101           0 :         if (!(s = mvc_bind_schema(m, sch)))
     102           0 :                 throw(SQL, "sql.droporderindex", SQLSTATE(3FOOO) "Unknown schema %s", sch);
     103           0 :         if (!mvc_schema_privs(m, s))
     104           0 :                 throw(SQL, "sql.droporderindex", SQLSTATE(42000) "Access denied for %s to schema '%s'", get_string_global_var(m, "current_user"), s->base.name);
     105           0 :         if (!(t = mvc_bind_table(m, s, tbl)))
     106           0 :                 throw(SQL, "sql.droporderindex", SQLSTATE(42S02) "Unknown table %s.%s", sch, tbl);
     107           0 :         if (!isTable(t))
     108           0 :                 throw(SQL, "sql.droporderindex", SQLSTATE(42000) "%s '%s' is not persistent", TABLE_TYPE_DESCRIPTION(t->type, t->properties), t->base.name);
     109           0 :         if (!(c = mvc_bind_column(m, t, col)))
     110           0 :                 throw(SQL, "sql.droporderindex", SQLSTATE(38000) "Unknown column %s.%s.%s", sch, tbl, col);
     111           0 :         sqlstore *store = m->session->tr->store;
     112           0 :         if (!(b = store->storage_api.bind_col(m->session->tr, c, RDONLY)))
     113           0 :                 throw(SQL,"sql.droporderindex", SQLSTATE(HY005) "Column can not be accessed");
     114           0 :         if (VIEWtparent(b)) {
     115           0 :                 nb = BBP_desc(VIEWtparent(b));
     116           0 :                 BBPunfix(b->batCacheid);
     117           0 :                 if (!(b = BATdescriptor(nb->batCacheid)))
     118           0 :                         throw(SQL,"sql.droporderindex", SQLSTATE(HY005) "Column can not be accessed");
     119             :         }
     120           0 :         OIDXdestroy(b);
     121           0 :         BBPunfix(b->batCacheid);
     122           0 :         return msg;
     123             : }

Generated by: LCOV version 1.14