Modifying update_attstats of analyze.c for C Strings - Mailing list pgsql-hackers

From Ashoke
Subject Modifying update_attstats of analyze.c for C Strings
Date
Msg-id CALpszJOkbYcGXehaLqDMqT6P-BfurPZOHT-ywGqzGMxE+R3gSQ@mail.gmail.com
Whole thread Raw
Responses Re: Modifying update_attstats of analyze.c for C Strings  (Ashoke <s.ashoke@gmail.com>)
List pgsql-hackers
Hi,

I am trying to implement a functionality that is similar to ANALYZE, but needs to have different values (the values will be valid and is stored in inp->str[][]) for MCV/Histogram Bounds in case the column under consideration is varchar (C Strings). I have written a function dummy_update_attstats with the following changes. Other things remain the same as in update_attstats of ~/src/backend/commands/analyze.c

---
{
ArrayType  *arry;

if (
strcmp(col_type,"varchar") == 0
)

arry = construct_array(stats->stavalues[k],

stats->numvalues[k],

CSTRINGOID,

-2,

false,

'c');

else

arry = construct_array(stats->stavalues[k],

stats->numvalues[k],

stats->statypid[k],

stats->statyplen[k],

stats->statypbyval[k],

stats->statypalign[k]);

values[i++] = PointerGetDatum(arry); /* stavaluesN */
            }
          ---

and I update the hist_values in the appropriate function as:
          ---
if (strcmp(col_type,"varchar") == 0)
hist_values[i] = datumCopy(CStringGetDatum(inp->str[i][j]),
false,
-2);
---


My issue is : When I use my way for strings, the MCV/histogram_bounds in pg_stats doesn't have double quotes (" ") surrounding string. That is,

If normal update_attstats is used, histogram_bounds for TPCH nation(n_name) are : "ALGERIA       ","ARGENTINA    ",...
If I use dummy_update_attstats as above, histogram_bounds for TPCH nation(n_name) are : ALGERIA,ARGENTINA,...

This becomes an issue if the string has ',' (commas), like for example in n_comment column of nation table.

Could someone point out the problem and suggest a solution?

Thank you.

--
Regards,
Ashoke

pgsql-hackers by date:

Previous
From: Ashutosh Bapat
Date:
Subject: Re: Extending constraint exclusion for implied constraints/conditions
Next
From: Amit Kapila
Date:
Subject: Re: better atomics - v0.5