MCPcopy Create free account
hub / github.com/apache/cloudberry / load_categories_hash

Function load_categories_hash

contrib/tablefunc/tablefunc.c:707–791  ·  view source on GitHub ↗

* load up the categories hash table */

Source from the content-addressed store, hash-verified

705 * load up the categories hash table
706 */
707static HTAB *
708load_categories_hash(char *cats_sql, MemoryContext per_query_ctx)
709{
710 HTAB *crosstab_hash;
711 HASHCTL ctl;
712 int ret;
713 uint64 proc;
714 MemoryContext SPIcontext;
715
716 /* initialize the category hash table */
717 ctl.keysize = MAX_CATNAME_LEN;
718 ctl.entrysize = sizeof(crosstab_HashEnt);
719 ctl.hcxt = per_query_ctx;
720
721 /*
722 * use INIT_CATS, defined above as a guess of how many hash table entries
723 * to create, initially
724 */
725 crosstab_hash = hash_create("crosstab hash",
726 INIT_CATS,
727 &ctl,
728 HASH_ELEM | HASH_STRINGS | HASH_CONTEXT);
729
730 /* Connect to SPI manager */
731 if ((ret = SPI_connect()) < 0)
732 /* internal error */
733 elog(ERROR, "load_categories_hash: SPI_connect returned %d", ret);
734
735 /* Retrieve the category name rows */
736 ret = SPI_execute(cats_sql, true, 0);
737 proc = SPI_processed;
738
739 /* Check for qualifying tuples */
740 if ((ret == SPI_OK_SELECT) && (proc > 0))
741 {
742 SPITupleTable *spi_tuptable = SPI_tuptable;
743 TupleDesc spi_tupdesc = spi_tuptable->tupdesc;
744 uint64 i;
745
746 /*
747 * The provided categories SQL query must always return one column:
748 * category - the label or identifier for each column
749 */
750 if (spi_tupdesc->natts != 1)
751 ereport(ERROR,
752 (errcode(ERRCODE_SYNTAX_ERROR),
753 errmsg("provided \"categories\" SQL must " \
754 "return 1 column of at least one row")));
755
756 for (i = 0; i < proc; i++)
757 {
758 crosstab_cat_desc *catdesc;
759 char *catname;
760 HeapTuple spi_tuple;
761
762 /* get the next sql result tuple */
763 spi_tuple = spi_tuptable->vals[i];
764

Callers 1

crosstab_hashFunction · 0.85

Calls 9

hash_createFunction · 0.85
SPI_connectFunction · 0.85
SPI_executeFunction · 0.85
SPI_getvalueFunction · 0.85
MemoryContextSwitchToFunction · 0.85
SPI_finishFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
pallocFunction · 0.50

Tested by

no test coverage detected