LCOV - code coverage report
Current view: top level - monetdb5/mal - mal_namespace.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 333 345 96.5 %
Date: 2025-03-26 20:06:40 Functions: 8 9 88.9 %

          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, 2025 MonetDB Foundation;
       9             :  * Copyright August 2008 - 2023 MonetDB B.V.;
      10             :  * Copyright 1997 - July 2008 CWI.
      11             :  */
      12             : 
      13             : /*
      14             :  * (author) M.L. Kersten
      15             :  */
      16             : #include "monetdb_config.h"
      17             : #include "mal_type.h"
      18             : #include "mal_namespace.h"
      19             : #include "mal_exception.h"
      20             : #include "mal_private.h"
      21             : 
      22             : #define MAXIDENTIFIERS 4096
      23             : #define HASHMASK  4095
      24             : 
      25             : MT_Lock mal_namespaceLock = MT_LOCK_INITIALIZER(mal_namespaceLock);
      26             : 
      27             : /* taken from gdk_atoms */
      28             : __attribute__((__pure__))
      29             : static inline size_t
      30    99058746 : nme_hash(const char *key, size_t len)
      31             : {
      32    99058746 :         size_t y = 0;
      33             : 
      34   856177802 :         for (size_t i = 0; i < len && key[i]; i++) {
      35   757119056 :                 y += key[i];
      36   757119056 :                 y += (y << 10);
      37   757119056 :                 y ^= (y >> 6);
      38             :         }
      39    99058746 :         y += (y << 3);
      40    99058746 :         y ^= (y >> 11);
      41    99058746 :         y += (y << 15);
      42    99058746 :         return y & HASHMASK;
      43             : }
      44             : 
      45             : typedef struct NAME {
      46             :         struct NAME *next;
      47             :         char nme[IDLENGTH + 1];
      48             : } *NamePtr;
      49             : 
      50             : static NamePtr hash[MAXIDENTIFIERS];
      51             : 
      52             : static struct namespace {
      53             :         struct namespace *next;
      54             :         int count;
      55             :         struct NAME data[4096];
      56             : } namespace1, *namespace = &namespace1;
      57             : 
      58             : struct fixname {
      59             :         struct fixname *next;
      60             :         const char *name;
      61             : };
      62             : static struct fixnamespace {
      63             :         int count;
      64             :         struct fixname data[1024];
      65             : } fixnamespace;
      66             : static struct fixname *fixhash[4096];
      67             : 
      68             : static void
      69       92820 : fixName(const char *name)
      70             : {
      71       92820 :         size_t key = nme_hash(name, 1024 /* something large */);
      72       92820 :         MT_lock_set(&mal_namespaceLock);
      73       92820 :         struct fixname **n;
      74       95319 :         for (n = &fixhash[key]; *n; n = &(*n)->next) {
      75        5099 :                 if ((*n)->name == name || strcmp((*n)->name, name) == 0) {
      76             :                         /* name is already there; this can happen when
      77             :                          * reinitializing */
      78        2600 :                         MT_lock_unset(&mal_namespaceLock);
      79        2600 :                         return;
      80             :                 }
      81             :         }
      82       90220 :         assert(fixnamespace.count < 1024);
      83       90220 :         struct fixname *new = &fixnamespace.data[fixnamespace.count++];
      84       90220 :         *new = (struct fixname) {
      85             :                 .name = name,
      86             :         };
      87       90220 :         *n = new;
      88       90220 :         MT_lock_unset(&mal_namespaceLock);
      89             : }
      90             : 
      91             : /* ! please keep this list sorted for easier maintenance ! */
      92             : const char affectedRowsRef[] = "affectedRows";
      93             : const char aggrRef[] = "aggr";
      94             : const char alarmRef[] = "alarm";
      95             : const char algebraRef[] = "algebra";
      96             : const char alter_add_range_partitionRef[] = "alter_add_range_partition";
      97             : const char alter_add_tableRef[] = "alter_add_table";
      98             : const char alter_add_value_partitionRef[] = "alter_add_value_partition";
      99             : const char alter_del_tableRef[] = "alter_del_table";
     100             : const char alter_seqRef[] = "alter_seq";
     101             : const char alter_set_tableRef[] = "alter_set_table";
     102             : const char alter_tableRef[] = "alter_table";
     103             : const char alter_userRef[] = "alter_user";
     104             : const char appendBulkRef[] = "appendBulk";
     105             : const char appendRef[] = "append";
     106             : const char assertRef[] = "assert";
     107             : const char avgRef[] = "avg";
     108             : const char bandjoinRef[] = "bandjoin";
     109             : const char batalgebraRef[] = "batalgebra";
     110             : const char batcalcRef[] = "batcalc";
     111             : const char batcapiRef[] = "batcapi";
     112             : const char batmalRef[] = "batmal";
     113             : const char batmkeyRef[] = "batmkey";
     114             : const char batmmathRef[] = "batmmath";
     115             : const char batmtimeRef[] = "batmtime";
     116             : const char batpyapi3Ref[] = "batpyapi3";
     117             : const char batrapiRef[] = "batrapi";
     118             : const char batRef[] = "bat";
     119             : const char batsqlRef[] = "batsql";
     120             : const char batstrRef[] = "batstr";
     121             : const char bbpRef[] = "bbp";
     122             : const char betweenRef[] = "between";
     123             : const char binddbatRef[] = "bind_dbat";
     124             : const char bindidxRef[] = "bind_idxbat";
     125             : const char bindRef[] = "bind";
     126             : const char blockRef[] = "block";
     127             : const char bstreamRef[] = "bstream";
     128             : const char calcRef[] = "calc";
     129             : const char capiRef[] = "capi";
     130             : const char claimRef[] = "claim";
     131             : const char clear_tableRef[] = "clear_table";
     132             : const char columnBindRef[] = "columnBind";
     133             : const char comment_onRef[] = "comment_on";
     134             : const char compressRef[] = "compress";
     135             : const char connectRef[] = "connect";
     136             : const char containsRef[] = "contains";
     137             : const char copy_fromRef[] = "copy_from";
     138             : const char corrRef[] = "corr";
     139             : const char count_no_nilRef[] = "count_no_nil";
     140             : const char countRef[] = "count";
     141             : const char create_functionRef[] = "create_function";
     142             : const char create_roleRef[] = "create_role";
     143             : const char create_schemaRef[] = "create_schema";
     144             : const char create_seqRef[] = "create_seq";
     145             : const char create_tableRef[] = "create_table";
     146             : const char create_triggerRef[] = "create_trigger";
     147             : const char create_typeRef[] = "create_type";
     148             : const char create_userRef[] = "create_user";
     149             : const char create_viewRef[] = "create_view";
     150             : const char crossRef[] = "crossproduct";
     151             : const char cume_distRef[] = "cume_dist";
     152             : const char dataflowRef[] = "dataflow";
     153             : const char dblRef[] = "dbl";
     154             : const char decompressRef[] = "decompress";
     155             : const char defineRef[] = "define";
     156             : const char deleteRef[] = "delete";
     157             : const char deltaRef[] = "delta";
     158             : const char dense_rankRef[] = "dense_rank";
     159             : const char dependRef[] = "depend";
     160             : const char deregisterRef[] = "deregister";
     161             : const char dictRef[] = "dict";
     162             : const char diffcandRef[] = "diffcand";
     163             : const char differenceRef[] = "difference";
     164             : const char disconnectRef[] = "disconnect";
     165             : const char divRef[] = "/";
     166             : const char drop_constraintRef[] = "drop_constraint";
     167             : const char drop_functionRef[] = "drop_function";
     168             : const char drop_indexRef[] = "drop_index";
     169             : const char drop_roleRef[] = "drop_role";
     170             : const char drop_schemaRef[] = "drop_schema";
     171             : const char drop_seqRef[] = "drop_seq";
     172             : const char drop_tableRef[] = "drop_table";
     173             : const char drop_triggerRef[] = "drop_trigger";
     174             : const char drop_typeRef[] = "drop_type";
     175             : const char drop_userRef[] = "drop_user";
     176             : const char drop_viewRef[] = "drop_view";
     177             : const char emptybindidxRef[] = "emptybindidx";
     178             : const char emptybindRef[] = "emptybind";
     179             : const char endswithjoinRef[] = "endswithjoin";
     180             : const char eqRef[] = "==";
     181             : const char evalRef[] = "eval";
     182             : const char execRef[] = "exec";
     183             : const char export_bin_columnRef[] = "export_bin_column";
     184             : const char exportOperationRef[] = "exportOperation";
     185             : const char export_tableRef[] = "export_table";
     186             : const char fetchRef[] = "fetch";
     187             : const char findRef[] = "find";
     188             : const char firstnRef[] = "firstn";
     189             : const char first_valueRef[] = "first_value";
     190             : const char forRef[] = "for";
     191             : const char generatorRef[] = "generator";
     192             : const char getRef[] = "get";
     193             : const char getTraceRef[] = "getTrace";
     194             : const char getVariableRef[] = "getVariable";
     195             : const char grant_functionRef[] = "grant_function";
     196             : const char grantRef[] = "grant";
     197             : const char grant_rolesRef[] = "grant_roles";
     198             : const char groupbyRef[] = "groupby";
     199             : const char groupdoneRef[] = "groupdone";
     200             : const char groupedfirstnRef[] = "groupedfirstn";
     201             : const char groupRef[] = "group";
     202             : const char growRef[] = "grow";
     203             : const char hgeRef[] = "hge";
     204             : const char identityRef[] = "identity";
     205             : const char ifthenelseRef[] = "ifthenelse";
     206             : const char importColumnRef[] = "importColumn";
     207             : const char intersectcandRef[] = "intersectcand";
     208             : const char intersectRef[] = "intersect";
     209             : const char intRef[] = "int";
     210             : const char ioRef[] = "io";
     211             : const char iteratorRef[] = "iterator";
     212             : const char joinRef[] = "join";
     213             : const char jsonRef[] = "json";
     214             : const char lagRef[] = "lag";
     215             : const char languageRef[] = "language";
     216             : const char last_valueRef[] = "last_value";
     217             : const char leadRef[] = "lead";
     218             : const char leftjoinRef[] = "leftjoin";
     219             : const char likejoinRef[] = "likejoin";
     220             : const char likeRef[] = "like";
     221             : const char likeselectRef[] = "likeselect";
     222             : const char lngRef[] = "lng";
     223             : const char lockRef[] = "lock";
     224             : const char lookupRef[] = "lookup";
     225             : const char mainRef[] = "main";
     226             : const char malRef[] = "mal";
     227             : const char manifoldRef[] = "manifold";
     228             : const char mapiRef[] = "mapi";
     229             : const char markjoinRef[] = "markjoin";
     230             : const char markselectRef[] = "markselect";
     231             : const char maskRef[] = "mask";
     232             : const char matRef[] = "mat";
     233             : const char maxlevenshteinRef[] = "maxlevenshtein";
     234             : const char maxRef[] = "max";
     235             : const char mdbRef[] = "mdb";
     236             : const char mergecandRef[] = "mergecand";
     237             : const char mergepackRef[] = "mergepack";
     238             : const char mergetableRef[] = "mergetable";
     239             : const char minjarowinklerRef[] = "minjarowinkler";
     240             : const char minRef[] = "min";
     241             : const char minusRef[] = "-";
     242             : const char mirrorRef[] = "mirror";
     243             : const char mitosisRef[] = "mitosis";
     244             : const char mmathRef[] = "mmath";
     245             : const char modRef[] = "%";
     246             : const char mtimeRef[] = "mtime";
     247             : const char mulRef[] = "*";
     248             : const char multiplexRef[] = "multiplex";
     249             : const char mvcRef[] = "mvc";
     250             : const char newRef[] = "new";
     251             : const char nextRef[] = "next";
     252             : const char not_likeRef[] = "not_like";
     253             : const char notRef[] = "not";
     254             : const char not_uniqueRef[] = "not_unique";
     255             : const char nth_valueRef[] = "nth_value";
     256             : const char ntileRef[] = "ntile";
     257             : const char optimizerRef[] = "optimizer";
     258             : const char outercrossRef[] = "outercrossproduct";
     259             : const char outerjoinRef[] = "outerjoin";
     260             : const char outerselectRef[] = "outerselect";
     261             : const char packIncrementRef[] = "packIncrement";
     262             : const char packRef[] = "pack";
     263             : const char parametersRef[] = "parameters";
     264             : const char passRef[] = "pass";
     265             : const char percent_rankRef[] = "percent_rank";
     266             : const char plusRef[] = "+";
     267             : const char predicateRef[] = "predicate";
     268             : const char printRef[] = "print";
     269             : const char prodRef[] = "prod";
     270             : const char profilerRef[] = "profiler";
     271             : const char projectdeltaRef[] = "projectdelta";
     272             : const char projectionpathRef[] = "projectionpath";
     273             : const char projectionRef[] = "projection";
     274             : const char projectRef[] = "project";
     275             : const char putRef[] = "put";
     276             : const char pyapi3Ref[] = "pyapi3";
     277             : const char querylogRef[] = "querylog";
     278             : const char raiseRef[] = "raise";
     279             : const char rangejoinRef[] = "rangejoin";
     280             : const char rankRef[] = "rank";
     281             : const char rapiRef[] = "rapi";
     282             : const char reconnectRef[] = "reconnect";
     283             : const char registerRef[] = "register";
     284             : const char register_supervisorRef[] = "register_supervisor";
     285             : const char remapRef[] = "remap";
     286             : const char remoteRef[] = "remote";
     287             : const char rename_columnRef[] = "rename_column";
     288             : const char rename_schemaRef[] = "rename_schema";
     289             : const char rename_tableRef[] = "rename_table";
     290             : const char rename_userRef[] = "rename_user";
     291             : const char renumberRef[] = "renumber";
     292             : const char replaceRef[] = "replace";
     293             : const char resultSetRef[] = "resultSet";
     294             : const char revoke_functionRef[] = "revoke_function";
     295             : const char revokeRef[] = "revoke";
     296             : const char revoke_rolesRef[] = "revoke_roles";
     297             : const char row_numberRef[] = "row_number";
     298             : const char rpcRef[] = "rpc";
     299             : const char rsColumnRef[] = "rsColumn";
     300             : const char rtreeRef[] = "rtree";
     301             : const char sampleRef[] = "sample";
     302             : const char selectNotNilRef[] = "selectNotNil";
     303             : const char selectRef[] = "select";
     304             : const char semaRef[] = "sema";
     305             : const char semijoinRef[] = "semijoin";
     306             : const char seriesRef[] = "series";
     307             : const char setAccessRef[] = "setAccess";
     308             : const char set_protocolRef[] = "set_protocol";
     309             : const char setVariableRef[] = "setVariable";
     310             : const char singleRef[] = "single";
     311             : const char sliceRef[] = "slice";
     312             : const char sortRef[] = "sort";
     313             : const char sqlcatalogRef[] = "sqlcatalog";
     314             : const char sqlRef[] = "sql";
     315             : const char startswithjoinRef[] = "startswithjoin";
     316             : const char stoptraceRef[] = "stoptrace";
     317             : const char streamsRef[] = "streams";
     318             : const char strimpsRef[] = "strimps";
     319             : const char strRef[] = "str";
     320             : const char subavgRef[] = "subavg";
     321             : const char subcountRef[] = "subcount";
     322             : const char subdeltaRef[] = "subdelta";
     323             : const char subeval_aggrRef[] = "subeval_aggr";
     324             : const char subgroupdoneRef[] = "subgroupdone";
     325             : const char subgroupRef[] = "subgroup";
     326             : const char submaxRef[] = "submax";
     327             : const char subminRef[] = "submin";
     328             : const char subprodRef[] = "subprod";
     329             : const char subsliceRef[] = "subslice";
     330             : const char subsumRef[] = "subsum";
     331             : const char subuniformRef[] = "subuniform";
     332             : const char sumRef[] = "sum";
     333             : const char takeRef[] = "take";
     334             : const char thetajoinRef[] = "thetajoin";
     335             : const char thetaselectRef[] = "thetaselect";
     336             : const char tidRef[] = "tid";
     337             : const char totalRef[] = "total";
     338             : const char transaction_abortRef[] = "transaction_abort";
     339             : const char transaction_beginRef[] = "transaction_begin";
     340             : const char transaction_commitRef[] = "transaction_commit";
     341             : const char transactionRef[] = "transaction";
     342             : const char transaction_releaseRef[] = "transaction_release";
     343             : const char transaction_rollbackRef[] = "transaction_rollback";
     344             : const char umaskRef[] = "umask";
     345             : const char unionfuncRef[] = "unionfunc";
     346             : const char uniqueRef[] = "unique";
     347             : const char unlockRef[] = "unlock";
     348             : const char updateRef[] = "update";
     349             : const char userRef[] = "user";
     350             : const char window_boundRef[] = "window_bound";
     351             : const char zero_or_oneRef[] = "zero_or_one";
     352             : /* ! please keep this list sorted for easier maintenance ! */
     353             : 
     354             : void
     355         357 : initNamespace(void)
     356             : {
     357             : /* ! please keep this list sorted for easier maintenance ! */
     358         357 :         fixName(affectedRowsRef);
     359         357 :         fixName(aggrRef);
     360         357 :         fixName(alarmRef);
     361         357 :         fixName(algebraRef);
     362         357 :         fixName(alter_add_range_partitionRef);
     363         357 :         fixName(alter_add_tableRef);
     364         357 :         fixName(alter_add_value_partitionRef);
     365         357 :         fixName(alter_del_tableRef);
     366         357 :         fixName(alter_seqRef);
     367         357 :         fixName(alter_set_tableRef);
     368         357 :         fixName(alter_tableRef);
     369         357 :         fixName(alter_userRef);
     370         357 :         fixName(appendBulkRef);
     371         357 :         fixName(appendRef);
     372         357 :         fixName(assertRef);
     373         357 :         fixName(avgRef);
     374         357 :         fixName(bandjoinRef);
     375         357 :         fixName(batalgebraRef);
     376         357 :         fixName(batcalcRef);
     377         357 :         fixName(batcapiRef);
     378         357 :         fixName(batmalRef);
     379         357 :         fixName(batmkeyRef);
     380         357 :         fixName(batmmathRef);
     381         357 :         fixName(batmtimeRef);
     382         357 :         fixName(batpyapi3Ref);
     383         357 :         fixName(batrapiRef);
     384         357 :         fixName(batRef);
     385         357 :         fixName(batsqlRef);
     386         357 :         fixName(batstrRef);
     387         357 :         fixName(bbpRef);
     388         357 :         fixName(betweenRef);
     389         357 :         fixName(binddbatRef);
     390         357 :         fixName(bindidxRef);
     391         357 :         fixName(bindRef);
     392         357 :         fixName(blockRef);
     393         357 :         fixName(bstreamRef);
     394         357 :         fixName(calcRef);
     395         357 :         fixName(capiRef);
     396         357 :         fixName(claimRef);
     397         357 :         fixName(clear_tableRef);
     398         357 :         fixName(columnBindRef);
     399         357 :         fixName(comment_onRef);
     400         357 :         fixName(compressRef);
     401         357 :         fixName(connectRef);
     402         357 :         fixName(containsRef);
     403         357 :         fixName(copy_fromRef);
     404         357 :         fixName(corrRef);
     405         357 :         fixName(count_no_nilRef);
     406         357 :         fixName(countRef);
     407         357 :         fixName(create_functionRef);
     408         357 :         fixName(create_roleRef);
     409         357 :         fixName(create_schemaRef);
     410         357 :         fixName(create_seqRef);
     411         357 :         fixName(create_tableRef);
     412         357 :         fixName(create_triggerRef);
     413         357 :         fixName(create_typeRef);
     414         357 :         fixName(create_userRef);
     415         357 :         fixName(create_viewRef);
     416         357 :         fixName(crossRef);
     417         357 :         fixName(cume_distRef);
     418         357 :         fixName(dataflowRef);
     419         357 :         fixName(dblRef);
     420         357 :         fixName(decompressRef);
     421         357 :         fixName(defineRef);
     422         357 :         fixName(deleteRef);
     423         357 :         fixName(deltaRef);
     424         357 :         fixName(dense_rankRef);
     425         357 :         fixName(dependRef);
     426         357 :         fixName(deregisterRef);
     427         357 :         fixName(dictRef);
     428         357 :         fixName(diffcandRef);
     429         357 :         fixName(differenceRef);
     430         357 :         fixName(disconnectRef);
     431         357 :         fixName(divRef);
     432         357 :         fixName(drop_constraintRef);
     433         357 :         fixName(drop_functionRef);
     434         357 :         fixName(drop_indexRef);
     435         357 :         fixName(drop_roleRef);
     436         357 :         fixName(drop_schemaRef);
     437         357 :         fixName(drop_seqRef);
     438         357 :         fixName(drop_tableRef);
     439         357 :         fixName(drop_triggerRef);
     440         357 :         fixName(drop_typeRef);
     441         357 :         fixName(drop_userRef);
     442         357 :         fixName(drop_viewRef);
     443         357 :         fixName(emptybindidxRef);
     444         357 :         fixName(emptybindRef);
     445         357 :         fixName(endswithjoinRef);
     446         357 :         fixName(eqRef);
     447         357 :         fixName(evalRef);
     448         357 :         fixName(execRef);
     449         357 :         fixName(export_bin_columnRef);
     450         357 :         fixName(exportOperationRef);
     451         357 :         fixName(export_tableRef);
     452         357 :         fixName(fetchRef);
     453         357 :         fixName(findRef);
     454         357 :         fixName(firstnRef);
     455         357 :         fixName(first_valueRef);
     456         357 :         fixName(forRef);
     457         357 :         fixName(generatorRef);
     458         357 :         fixName(getRef);
     459         357 :         fixName(getTraceRef);
     460         357 :         fixName(getVariableRef);
     461         357 :         fixName(grant_functionRef);
     462         357 :         fixName(grantRef);
     463         357 :         fixName(grant_rolesRef);
     464         357 :         fixName(groupbyRef);
     465         357 :         fixName(groupdoneRef);
     466         357 :         fixName(groupedfirstnRef);
     467         357 :         fixName(groupRef);
     468         357 :         fixName(growRef);
     469         357 :         fixName(hgeRef);
     470         357 :         fixName(identityRef);
     471         357 :         fixName(ifthenelseRef);
     472         357 :         fixName(importColumnRef);
     473         357 :         fixName(intersectcandRef);
     474         357 :         fixName(intersectRef);
     475         357 :         fixName(intRef);
     476         357 :         fixName(ioRef);
     477         357 :         fixName(iteratorRef);
     478         357 :         fixName(joinRef);
     479         357 :         fixName(jsonRef);
     480         357 :         fixName(lagRef);
     481         357 :         fixName(languageRef);
     482         357 :         fixName(last_valueRef);
     483         357 :         fixName(leadRef);
     484         357 :         fixName(leftjoinRef);
     485         357 :         fixName(likejoinRef);
     486         357 :         fixName(likeRef);
     487         357 :         fixName(likeselectRef);
     488         357 :         fixName(lngRef);
     489         357 :         fixName(lockRef);
     490         357 :         fixName(lookupRef);
     491         357 :         fixName(mainRef);
     492         357 :         fixName(malRef);
     493         357 :         fixName(manifoldRef);
     494         357 :         fixName(mapiRef);
     495         357 :         fixName(markjoinRef);
     496         357 :         fixName(markselectRef);
     497         357 :         fixName(maskRef);
     498         357 :         fixName(matRef);
     499         357 :         fixName(maxlevenshteinRef);
     500         357 :         fixName(maxRef);
     501         357 :         fixName(mdbRef);
     502         357 :         fixName(mergecandRef);
     503         357 :         fixName(mergepackRef);
     504         357 :         fixName(mergetableRef);
     505         357 :         fixName(minjarowinklerRef);
     506         357 :         fixName(minRef);
     507         357 :         fixName(minusRef);
     508         357 :         fixName(mirrorRef);
     509         357 :         fixName(mitosisRef);
     510         357 :         fixName(mmathRef);
     511         357 :         fixName(modRef);
     512         357 :         fixName(mtimeRef);
     513         357 :         fixName(mulRef);
     514         357 :         fixName(multiplexRef);
     515         357 :         fixName(mvcRef);
     516         357 :         fixName(newRef);
     517         357 :         fixName(nextRef);
     518         357 :         fixName(not_likeRef);
     519         357 :         fixName(notRef);
     520         357 :         fixName(not_uniqueRef);
     521         357 :         fixName(nth_valueRef);
     522         357 :         fixName(ntileRef);
     523         357 :         fixName(optimizerRef);
     524         357 :         fixName(outercrossRef);
     525         357 :         fixName(outerjoinRef);
     526         357 :         fixName(outerselectRef);
     527         357 :         fixName(packIncrementRef);
     528         357 :         fixName(packRef);
     529         357 :         fixName(parametersRef);
     530         357 :         fixName(passRef);
     531         357 :         fixName(percent_rankRef);
     532         357 :         fixName(plusRef);
     533         357 :         fixName(predicateRef);
     534         357 :         fixName(printRef);
     535         357 :         fixName(prodRef);
     536         357 :         fixName(profilerRef);
     537         357 :         fixName(projectdeltaRef);
     538         357 :         fixName(projectionpathRef);
     539         357 :         fixName(projectionRef);
     540         357 :         fixName(projectRef);
     541         357 :         fixName(putRef);
     542         357 :         fixName(pyapi3Ref);
     543         357 :         fixName(querylogRef);
     544         357 :         fixName(raiseRef);
     545         357 :         fixName(rangejoinRef);
     546         357 :         fixName(rankRef);
     547         357 :         fixName(rapiRef);
     548         357 :         fixName(reconnectRef);
     549         357 :         fixName(registerRef);
     550         357 :         fixName(register_supervisorRef);
     551         357 :         fixName(remapRef);
     552         357 :         fixName(remoteRef);
     553         357 :         fixName(rename_columnRef);
     554         357 :         fixName(rename_schemaRef);
     555         357 :         fixName(rename_tableRef);
     556         357 :         fixName(rename_userRef);
     557         357 :         fixName(renumberRef);
     558         357 :         fixName(replaceRef);
     559         357 :         fixName(resultSetRef);
     560         357 :         fixName(revoke_functionRef);
     561         357 :         fixName(revokeRef);
     562         357 :         fixName(revoke_rolesRef);
     563         357 :         fixName(row_numberRef);
     564         357 :         fixName(rpcRef);
     565         357 :         fixName(rsColumnRef);
     566         357 :         fixName(rtreeRef);
     567         357 :         fixName(sampleRef);
     568         357 :         fixName(selectNotNilRef);
     569         357 :         fixName(selectRef);
     570         357 :         fixName(semaRef);
     571         357 :         fixName(semijoinRef);
     572         357 :         fixName(seriesRef);
     573         357 :         fixName(setAccessRef);
     574         357 :         fixName(set_protocolRef);
     575         357 :         fixName(setVariableRef);
     576         357 :         fixName(singleRef);
     577         357 :         fixName(sliceRef);
     578         357 :         fixName(sortRef);
     579         357 :         fixName(sqlcatalogRef);
     580         357 :         fixName(sqlRef);
     581         357 :         fixName(startswithjoinRef);
     582         357 :         fixName(stoptraceRef);
     583         357 :         fixName(streamsRef);
     584         357 :         fixName(strimpsRef);
     585         357 :         fixName(strRef);
     586         357 :         fixName(subavgRef);
     587         357 :         fixName(subcountRef);
     588         357 :         fixName(subdeltaRef);
     589         357 :         fixName(subeval_aggrRef);
     590         357 :         fixName(subgroupdoneRef);
     591         357 :         fixName(subgroupRef);
     592         357 :         fixName(submaxRef);
     593         357 :         fixName(subminRef);
     594         357 :         fixName(subprodRef);
     595         357 :         fixName(subsliceRef);
     596         357 :         fixName(subsumRef);
     597         357 :         fixName(subuniformRef);
     598         357 :         fixName(sumRef);
     599         357 :         fixName(takeRef);
     600         357 :         fixName(thetajoinRef);
     601         357 :         fixName(thetaselectRef);
     602         357 :         fixName(tidRef);
     603         357 :         fixName(totalRef);
     604         357 :         fixName(transaction_abortRef);
     605         357 :         fixName(transaction_beginRef);
     606         357 :         fixName(transaction_commitRef);
     607         357 :         fixName(transactionRef);
     608         357 :         fixName(transaction_releaseRef);
     609         357 :         fixName(transaction_rollbackRef);
     610         357 :         fixName(umaskRef);
     611         357 :         fixName(unionfuncRef);
     612         357 :         fixName(uniqueRef);
     613         357 :         fixName(unlockRef);
     614         357 :         fixName(updateRef);
     615         357 :         fixName(userRef);
     616         357 :         fixName(window_boundRef);
     617         357 :         fixName(zero_or_oneRef);
     618             : /* ! please keep this list sorted for easier maintenance ! */
     619         357 : }
     620             : 
     621             : void
     622         355 : mal_namespace_reset(void)
     623             : {
     624         355 :         struct namespace *ns;
     625             : 
     626             :         /* assume we are at the end of the server session */
     627         355 :         MT_lock_set(&mal_namespaceLock);
     628         355 :         memset(hash, 0, sizeof(hash));
     629         710 :         while (namespace) {
     630         355 :                 ns = namespace->next;
     631         355 :                 if (namespace != &namespace1)
     632           0 :                         GDKfree(namespace);
     633         355 :                 namespace = ns;
     634             :         }
     635         355 :         namespace1 = (struct namespace) {
     636             :                 .count = 0,
     637             :         };
     638         355 :         namespace = &namespace1;
     639         355 :         MT_lock_unset(&mal_namespaceLock);
     640         355 : }
     641             : 
     642             : static const char *
     643    98965815 : findName(const char *nme, size_t len, bool allocate)
     644             : {
     645    98965815 :         NamePtr *n, m;
     646    98965815 :         size_t key;
     647             : 
     648    98965815 :         assert(len == 0 || nme != NULL);
     649    98965815 :         if (len == 0 || nme == NULL)
     650             :                 return NULL;
     651    98965815 :         if (len > IDLENGTH) {
     652             :                 len = IDLENGTH;
     653             :         }
     654    98965815 :         key = nme_hash(nme, len);
     655    98965815 :         MT_lock_set(&mal_namespaceLock);
     656    99079735 :         for (struct fixname *p = fixhash[key]; p; p = p->next) {
     657    75181395 :                 if (p->name == nme || (strncmp(p->name, nme, len) == 0 && p->name[len] == 0)) {
     658    75086947 :                         MT_lock_unset(&mal_namespaceLock);
     659    75086377 :                         return p->name;
     660             :                 }
     661             :         }
     662    27567145 :         for (n = &hash[key]; *n; n = &(*n)->next) {
     663    27307106 :                 if (strncmp(nme, (*n)->nme, len) == 0 && (*n)->nme[len] == 0) {
     664    23638301 :                         MT_lock_unset(&mal_namespaceLock);
     665    23638078 :                         return (*n)->nme;
     666             :                 }
     667             :         }
     668             :         /* item not found */
     669      260039 :         if (!allocate) {
     670           0 :                 MT_lock_unset(&mal_namespaceLock);
     671           0 :                 return NULL;
     672             :         }
     673      260039 :         if (namespace == NULL || namespace->count == 4096) {
     674           0 :                 struct namespace *ns = GDKmalloc(sizeof(struct namespace));
     675           0 :                 if (ns == NULL) {
     676           0 :                         MT_lock_unset(&mal_namespaceLock);
     677           0 :                         return NULL;
     678             :                 }
     679           0 :                 ns->next = namespace;
     680           0 :                 ns->count = 0;
     681           0 :                 namespace = ns;
     682             :         }
     683      260039 :         m = &namespace->data[namespace->count++];
     684      260039 :         assert(m->nme != nme);
     685      260039 :         strncpy(m->nme, nme, len);
     686      260039 :         m->nme[len] = 0;
     687      260039 :         m->next = *n;
     688      260039 :         *n = m;
     689      260039 :         MT_lock_unset(&mal_namespaceLock);
     690      260039 :         return m->nme;
     691             : }
     692             : 
     693             : const char *
     694    37661499 : getName(const char *nme)
     695             : {
     696    37661499 :         if (nme != NULL)
     697    36530170 :                 nme = findName(nme, strlen(nme), false);
     698    37666349 :         return nme;
     699             : }
     700             : 
     701             : const char *
     702           0 : getNameLen(const char *nme, size_t len)
     703             : {
     704           0 :         return findName(nme, len, false);
     705             : }
     706             : 
     707             : const char *
     708    62428861 : putName(const char *nme)
     709             : {
     710    62428861 :         if (nme != NULL)
     711    62428861 :                 nme = findName(nme, strlen(nme), true);
     712    62431370 :         return nme;
     713             : }
     714             : 
     715             : const char *
     716       18231 : putNameLen(const char *nme, size_t len)
     717             : {
     718       18231 :         return findName(nme, len, true);
     719             : }

Generated by: LCOV version 1.14