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: 2024-12-20 21:24:02 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 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    96174976 : nme_hash(const char *key, size_t len)
      31             : {
      32    96174976 :         size_t y = 0;
      33             : 
      34   843441842 :         for (size_t i = 0; i < len && key[i]; i++) {
      35   747266866 :                 y += key[i];
      36   747266866 :                 y += (y << 10);
      37   747266866 :                 y ^= (y >> 6);
      38             :         }
      39    96174976 :         y += (y << 3);
      40    96174976 :         y ^= (y >> 11);
      41    96174976 :         y += (y << 15);
      42    96174976 :         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       91520 : fixName(const char *name)
      70             : {
      71       91520 :         size_t key = nme_hash(name, 1024 /* something large */);
      72       91520 :         MT_lock_set(&mal_namespaceLock);
      73       91520 :         struct fixname **n;
      74       93984 :         for (n = &fixhash[key]; *n; n = &(*n)->next) {
      75        5064 :                 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       88920 :         assert(fixnamespace.count < 1024);
      83       88920 :         struct fixname *new = &fixnamespace.data[fixnamespace.count++];
      84       88920 :         *new = (struct fixname) {
      85             :                 .name = name,
      86             :         };
      87       88920 :         *n = new;
      88       88920 :         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         352 : initNamespace(void)
     356             : {
     357             : /* ! please keep this list sorted for easier maintenance ! */
     358         352 :         fixName(affectedRowsRef);
     359         352 :         fixName(aggrRef);
     360         352 :         fixName(alarmRef);
     361         352 :         fixName(algebraRef);
     362         352 :         fixName(alter_add_range_partitionRef);
     363         352 :         fixName(alter_add_tableRef);
     364         352 :         fixName(alter_add_value_partitionRef);
     365         352 :         fixName(alter_del_tableRef);
     366         352 :         fixName(alter_seqRef);
     367         352 :         fixName(alter_set_tableRef);
     368         352 :         fixName(alter_tableRef);
     369         352 :         fixName(alter_userRef);
     370         352 :         fixName(appendBulkRef);
     371         352 :         fixName(appendRef);
     372         352 :         fixName(assertRef);
     373         352 :         fixName(avgRef);
     374         352 :         fixName(bandjoinRef);
     375         352 :         fixName(batalgebraRef);
     376         352 :         fixName(batcalcRef);
     377         352 :         fixName(batcapiRef);
     378         352 :         fixName(batmalRef);
     379         352 :         fixName(batmkeyRef);
     380         352 :         fixName(batmmathRef);
     381         352 :         fixName(batmtimeRef);
     382         352 :         fixName(batpyapi3Ref);
     383         352 :         fixName(batrapiRef);
     384         352 :         fixName(batRef);
     385         352 :         fixName(batsqlRef);
     386         352 :         fixName(batstrRef);
     387         352 :         fixName(bbpRef);
     388         352 :         fixName(betweenRef);
     389         352 :         fixName(binddbatRef);
     390         352 :         fixName(bindidxRef);
     391         352 :         fixName(bindRef);
     392         352 :         fixName(blockRef);
     393         352 :         fixName(bstreamRef);
     394         352 :         fixName(calcRef);
     395         352 :         fixName(capiRef);
     396         352 :         fixName(claimRef);
     397         352 :         fixName(clear_tableRef);
     398         352 :         fixName(columnBindRef);
     399         352 :         fixName(comment_onRef);
     400         352 :         fixName(compressRef);
     401         352 :         fixName(connectRef);
     402         352 :         fixName(containsRef);
     403         352 :         fixName(copy_fromRef);
     404         352 :         fixName(corrRef);
     405         352 :         fixName(count_no_nilRef);
     406         352 :         fixName(countRef);
     407         352 :         fixName(create_functionRef);
     408         352 :         fixName(create_roleRef);
     409         352 :         fixName(create_schemaRef);
     410         352 :         fixName(create_seqRef);
     411         352 :         fixName(create_tableRef);
     412         352 :         fixName(create_triggerRef);
     413         352 :         fixName(create_typeRef);
     414         352 :         fixName(create_userRef);
     415         352 :         fixName(create_viewRef);
     416         352 :         fixName(crossRef);
     417         352 :         fixName(cume_distRef);
     418         352 :         fixName(dataflowRef);
     419         352 :         fixName(dblRef);
     420         352 :         fixName(decompressRef);
     421         352 :         fixName(defineRef);
     422         352 :         fixName(deleteRef);
     423         352 :         fixName(deltaRef);
     424         352 :         fixName(dense_rankRef);
     425         352 :         fixName(dependRef);
     426         352 :         fixName(deregisterRef);
     427         352 :         fixName(dictRef);
     428         352 :         fixName(diffcandRef);
     429         352 :         fixName(differenceRef);
     430         352 :         fixName(disconnectRef);
     431         352 :         fixName(divRef);
     432         352 :         fixName(drop_constraintRef);
     433         352 :         fixName(drop_functionRef);
     434         352 :         fixName(drop_indexRef);
     435         352 :         fixName(drop_roleRef);
     436         352 :         fixName(drop_schemaRef);
     437         352 :         fixName(drop_seqRef);
     438         352 :         fixName(drop_tableRef);
     439         352 :         fixName(drop_triggerRef);
     440         352 :         fixName(drop_typeRef);
     441         352 :         fixName(drop_userRef);
     442         352 :         fixName(drop_viewRef);
     443         352 :         fixName(emptybindidxRef);
     444         352 :         fixName(emptybindRef);
     445         352 :         fixName(endswithjoinRef);
     446         352 :         fixName(eqRef);
     447         352 :         fixName(evalRef);
     448         352 :         fixName(execRef);
     449         352 :         fixName(export_bin_columnRef);
     450         352 :         fixName(exportOperationRef);
     451         352 :         fixName(export_tableRef);
     452         352 :         fixName(fetchRef);
     453         352 :         fixName(findRef);
     454         352 :         fixName(firstnRef);
     455         352 :         fixName(first_valueRef);
     456         352 :         fixName(forRef);
     457         352 :         fixName(generatorRef);
     458         352 :         fixName(getRef);
     459         352 :         fixName(getTraceRef);
     460         352 :         fixName(getVariableRef);
     461         352 :         fixName(grant_functionRef);
     462         352 :         fixName(grantRef);
     463         352 :         fixName(grant_rolesRef);
     464         352 :         fixName(groupbyRef);
     465         352 :         fixName(groupdoneRef);
     466         352 :         fixName(groupedfirstnRef);
     467         352 :         fixName(groupRef);
     468         352 :         fixName(growRef);
     469         352 :         fixName(hgeRef);
     470         352 :         fixName(identityRef);
     471         352 :         fixName(ifthenelseRef);
     472         352 :         fixName(importColumnRef);
     473         352 :         fixName(intersectcandRef);
     474         352 :         fixName(intersectRef);
     475         352 :         fixName(intRef);
     476         352 :         fixName(ioRef);
     477         352 :         fixName(iteratorRef);
     478         352 :         fixName(joinRef);
     479         352 :         fixName(jsonRef);
     480         352 :         fixName(lagRef);
     481         352 :         fixName(languageRef);
     482         352 :         fixName(last_valueRef);
     483         352 :         fixName(leadRef);
     484         352 :         fixName(leftjoinRef);
     485         352 :         fixName(likejoinRef);
     486         352 :         fixName(likeRef);
     487         352 :         fixName(likeselectRef);
     488         352 :         fixName(lngRef);
     489         352 :         fixName(lockRef);
     490         352 :         fixName(lookupRef);
     491         352 :         fixName(mainRef);
     492         352 :         fixName(malRef);
     493         352 :         fixName(manifoldRef);
     494         352 :         fixName(mapiRef);
     495         352 :         fixName(markjoinRef);
     496         352 :         fixName(markselectRef);
     497         352 :         fixName(maskRef);
     498         352 :         fixName(matRef);
     499         352 :         fixName(maxlevenshteinRef);
     500         352 :         fixName(maxRef);
     501         352 :         fixName(mdbRef);
     502         352 :         fixName(mergecandRef);
     503         352 :         fixName(mergepackRef);
     504         352 :         fixName(mergetableRef);
     505         352 :         fixName(minjarowinklerRef);
     506         352 :         fixName(minRef);
     507         352 :         fixName(minusRef);
     508         352 :         fixName(mirrorRef);
     509         352 :         fixName(mitosisRef);
     510         352 :         fixName(mmathRef);
     511         352 :         fixName(modRef);
     512         352 :         fixName(mtimeRef);
     513         352 :         fixName(mulRef);
     514         352 :         fixName(multiplexRef);
     515         352 :         fixName(mvcRef);
     516         352 :         fixName(newRef);
     517         352 :         fixName(nextRef);
     518         352 :         fixName(not_likeRef);
     519         352 :         fixName(notRef);
     520         352 :         fixName(not_uniqueRef);
     521         352 :         fixName(nth_valueRef);
     522         352 :         fixName(ntileRef);
     523         352 :         fixName(optimizerRef);
     524         352 :         fixName(outercrossRef);
     525         352 :         fixName(outerjoinRef);
     526         352 :         fixName(outerselectRef);
     527         352 :         fixName(packIncrementRef);
     528         352 :         fixName(packRef);
     529         352 :         fixName(parametersRef);
     530         352 :         fixName(passRef);
     531         352 :         fixName(percent_rankRef);
     532         352 :         fixName(plusRef);
     533         352 :         fixName(predicateRef);
     534         352 :         fixName(printRef);
     535         352 :         fixName(prodRef);
     536         352 :         fixName(profilerRef);
     537         352 :         fixName(projectdeltaRef);
     538         352 :         fixName(projectionpathRef);
     539         352 :         fixName(projectionRef);
     540         352 :         fixName(projectRef);
     541         352 :         fixName(putRef);
     542         352 :         fixName(pyapi3Ref);
     543         352 :         fixName(querylogRef);
     544         352 :         fixName(raiseRef);
     545         352 :         fixName(rangejoinRef);
     546         352 :         fixName(rankRef);
     547         352 :         fixName(rapiRef);
     548         352 :         fixName(reconnectRef);
     549         352 :         fixName(registerRef);
     550         352 :         fixName(register_supervisorRef);
     551         352 :         fixName(remapRef);
     552         352 :         fixName(remoteRef);
     553         352 :         fixName(rename_columnRef);
     554         352 :         fixName(rename_schemaRef);
     555         352 :         fixName(rename_tableRef);
     556         352 :         fixName(rename_userRef);
     557         352 :         fixName(renumberRef);
     558         352 :         fixName(replaceRef);
     559         352 :         fixName(resultSetRef);
     560         352 :         fixName(revoke_functionRef);
     561         352 :         fixName(revokeRef);
     562         352 :         fixName(revoke_rolesRef);
     563         352 :         fixName(row_numberRef);
     564         352 :         fixName(rpcRef);
     565         352 :         fixName(rsColumnRef);
     566         352 :         fixName(rtreeRef);
     567         352 :         fixName(sampleRef);
     568         352 :         fixName(selectNotNilRef);
     569         352 :         fixName(selectRef);
     570         352 :         fixName(semaRef);
     571         352 :         fixName(semijoinRef);
     572         352 :         fixName(seriesRef);
     573         352 :         fixName(setAccessRef);
     574         352 :         fixName(set_protocolRef);
     575         352 :         fixName(setVariableRef);
     576         352 :         fixName(singleRef);
     577         352 :         fixName(sliceRef);
     578         352 :         fixName(sortRef);
     579         352 :         fixName(sqlcatalogRef);
     580         352 :         fixName(sqlRef);
     581         352 :         fixName(startswithjoinRef);
     582         352 :         fixName(stoptraceRef);
     583         352 :         fixName(streamsRef);
     584         352 :         fixName(strimpsRef);
     585         352 :         fixName(strRef);
     586         352 :         fixName(subavgRef);
     587         352 :         fixName(subcountRef);
     588         352 :         fixName(subdeltaRef);
     589         352 :         fixName(subeval_aggrRef);
     590         352 :         fixName(subgroupdoneRef);
     591         352 :         fixName(subgroupRef);
     592         352 :         fixName(submaxRef);
     593         352 :         fixName(subminRef);
     594         352 :         fixName(subprodRef);
     595         352 :         fixName(subsliceRef);
     596         352 :         fixName(subsumRef);
     597         352 :         fixName(subuniformRef);
     598         352 :         fixName(sumRef);
     599         352 :         fixName(takeRef);
     600         352 :         fixName(thetajoinRef);
     601         352 :         fixName(thetaselectRef);
     602         352 :         fixName(tidRef);
     603         352 :         fixName(totalRef);
     604         352 :         fixName(transaction_abortRef);
     605         352 :         fixName(transaction_beginRef);
     606         352 :         fixName(transaction_commitRef);
     607         352 :         fixName(transactionRef);
     608         352 :         fixName(transaction_releaseRef);
     609         352 :         fixName(transaction_rollbackRef);
     610         352 :         fixName(umaskRef);
     611         352 :         fixName(unionfuncRef);
     612         352 :         fixName(uniqueRef);
     613         352 :         fixName(unlockRef);
     614         352 :         fixName(updateRef);
     615         352 :         fixName(userRef);
     616         352 :         fixName(window_boundRef);
     617         352 :         fixName(zero_or_oneRef);
     618             : /* ! please keep this list sorted for easier maintenance ! */
     619         352 : }
     620             : 
     621             : void
     622         350 : mal_namespace_reset(void)
     623             : {
     624         350 :         struct namespace *ns;
     625             : 
     626             :         /* assume we are at the end of the server session */
     627         350 :         MT_lock_set(&mal_namespaceLock);
     628         350 :         memset(hash, 0, sizeof(hash));
     629         700 :         while (namespace) {
     630         350 :                 ns = namespace->next;
     631         350 :                 if (namespace != &namespace1)
     632           0 :                         GDKfree(namespace);
     633         350 :                 namespace = ns;
     634             :         }
     635         350 :         namespace1 = (struct namespace) {
     636             :                 .count = 0,
     637             :         };
     638         350 :         namespace = &namespace1;
     639         350 :         MT_lock_unset(&mal_namespaceLock);
     640         350 : }
     641             : 
     642             : static const char *
     643    96081712 : findName(const char *nme, size_t len, bool allocate)
     644             : {
     645    96081712 :         NamePtr *n, m;
     646    96081712 :         size_t key;
     647             : 
     648    96081712 :         assert(len == 0 || nme != NULL);
     649    96081712 :         if (len == 0 || nme == NULL)
     650             :                 return NULL;
     651    96081712 :         if (len > IDLENGTH) {
     652             :                 len = IDLENGTH;
     653             :         }
     654    96081712 :         key = nme_hash(nme, len);
     655    96081712 :         MT_lock_set(&mal_namespaceLock);
     656    96248071 :         for (struct fixname *p = fixhash[key]; p; p = p->next) {
     657    73947276 :                 if (p->name == nme || (strncmp(p->name, nme, len) == 0 && p->name[len] == 0)) {
     658    73853084 :                         MT_lock_unset(&mal_namespaceLock);
     659    73849663 :                         return p->name;
     660             :                 }
     661             :         }
     662    25706638 :         for (n = &hash[key]; *n; n = &(*n)->next) {
     663    25450939 :                 if (strncmp(nme, (*n)->nme, len) == 0 && (*n)->nme[len] == 0) {
     664    22045096 :                         MT_lock_unset(&mal_namespaceLock);
     665    22044561 :                         return (*n)->nme;
     666             :                 }
     667             :         }
     668             :         /* item not found */
     669      255699 :         if (!allocate) {
     670           0 :                 MT_lock_unset(&mal_namespaceLock);
     671           0 :                 return NULL;
     672             :         }
     673      255699 :         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      255699 :         m = &namespace->data[namespace->count++];
     684      255699 :         assert(m->nme != nme);
     685      255699 :         strncpy(m->nme, nme, len);
     686      255699 :         m->nme[len] = 0;
     687      255699 :         m->next = *n;
     688      255699 :         *n = m;
     689      255699 :         MT_lock_unset(&mal_namespaceLock);
     690      255699 :         return m->nme;
     691             : }
     692             : 
     693             : const char *
     694    37839169 : getName(const char *nme)
     695             : {
     696    37839169 :         if (nme != NULL)
     697    36530482 :                 nme = findName(nme, strlen(nme), false);
     698    37844862 :         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    59563795 : putName(const char *nme)
     709             : {
     710    59563795 :         if (nme != NULL)
     711    59563795 :                 nme = findName(nme, strlen(nme), true);
     712    59595243 :         return nme;
     713             : }
     714             : 
     715             : const char *
     716       18140 : putNameLen(const char *nme, size_t len)
     717             : {
     718       18140 :         return findName(nme, len, true);
     719             : }

Generated by: LCOV version 1.14