Jan Urbański wrote:
Following the conclusion here:
http://archives.postgresql.org/pgsql-hackers/2008-05/msg00273.php
here's a patch that extends VacAttrStats to allow typanalyze functions to store statistic values of different types than the underlying column.

The XXX comment can be taken into consideration or just dropped as unimportant.

Doh, this time against HEAD, not my branch ...

--
Jan Urbanski
GPG key ID: E583D7D2

ouden estin
*** src/backend/commands/analyze.c
--- src/backend/commands/analyze.c      2008-05-16 00:47:00.000000000 +0200
***************
*** 1321,1330 ****
  
                                arry = construct_array(stats->stavalues[k],
                                                                           
stats->numvalues[k],
!                                                                          
stats->attr->atttypid,
!                                                                          
stats->attrtype->typlen,
!                                                                          
stats->attrtype->typbyval,
!                                                                          
stats->attrtype->typalign);
                                values[i++] = PointerGetDatum(arry);    /* 
stavaluesN */
                        }
                        else
--- 1321,1330 ----
  
                                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 */
                        }
                        else
***************
*** 1854,1859 ****
--- 1854,1867 ----
                        stats->numnumbers[0] = num_mcv;
                        stats->stavalues[0] = mcv_values;
                        stats->numvalues[0] = num_mcv;
+                       /*
+                        * MCV entries have the same element type as the 
analyzed
+                        * attribute.
+                        */
+                       stats->statypid[0] = stats->attr->atttypid;
+                       stats->statyplen[0] = stats->attrtype->typlen;
+                       stats->statypbyval[0] = stats->attrtype->typbyval;
+                       stats->statypalign[0] = stats->attrtype->typalign;
                }
        }
        else if (null_cnt > 0)
***************
*** 2197,2202 ****
--- 2205,2218 ----
                        stats->numnumbers[slot_idx] = num_mcv;
                        stats->stavalues[slot_idx] = mcv_values;
                        stats->numvalues[slot_idx] = num_mcv;
+                       /*
+                        * MCV entries have the same element type as the 
analyzed
+                        * attribute.
+                        */
+                       stats->statypid[slot_idx] = stats->attr->atttypid;
+                       stats->statyplen[slot_idx] = stats->attrtype->typlen;
+                       stats->statypbyval[slot_idx] = 
stats->attrtype->typbyval;
+                       stats->statypalign[slot_idx] = 
stats->attrtype->typalign;
                        slot_idx++;
                }
  
***************
*** 2281,2286 ****
--- 2297,2310 ----
                        stats->staop[slot_idx] = mystats->ltopr;
                        stats->stavalues[slot_idx] = hist_values;
                        stats->numvalues[slot_idx] = num_hist;
+                       /*
+                        * Histogram entries have the same element type as the 
analyzed
+                        * attribute.
+                        */
+                       stats->statypid[slot_idx] = stats->attr->atttypid;
+                       stats->statyplen[slot_idx] = stats->attrtype->typlen;
+                       stats->statypbyval[slot_idx] = 
stats->attrtype->typbyval;
+                       stats->statypalign[slot_idx] = 
stats->attrtype->typalign;
                        slot_idx++;
                }
  
*** src/include/commands/vacuum.h
--- src/include/commands/vacuum.h       2008-05-16 00:47:09.000000000 +0200
***************
*** 94,99 ****
--- 94,119 ----
        Datum      *stavalues[STATISTIC_NUM_SLOTS];
  
        /*
+        * These fields describe the stavalues[n] element types. They will
+        * typically be the same as the column's that's underlying the slot, but
+        * sometimes a custom typanalyze function might want to store an array 
of
+        * something other that the analyzed column's elements. This must be 
filled
+        * in by the compute_stats routine.
+        *
+        * XXX or maybe fall back on attrtype-> stuff when these are NULL? That 
way
+        * we won't break other people's custom typanalyze functions. Not sure 
if
+        * any exist, though.
+        *
+        * Another concern is that typlen, typbyval and typalign are reduntant
+        * given the OID. But the caller is in better position to cache this so
+        * maybe we shouldn't worry about it?
+        */
+       Oid                     statypid[STATISTIC_NUM_SLOTS];
+       int2            statyplen[STATISTIC_NUM_SLOTS];
+       bool            statypbyval[STATISTIC_NUM_SLOTS];
+       char            statypalign[STATISTIC_NUM_SLOTS];
+ 
+       /*
         * These fields are private to the main ANALYZE code and should not be
         * looked at by type-specific functions.
         */
-- 
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches

Reply via email to