Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitce207d2

Browse files
committed
Add functions pg_set_attribute_stats() and pg_clear_attribute_stats().
Enable manipulation of attribute statistics. Only superficialvalidation is performed, so it's possible to add nonsense, and it's upto the planner (or other users of statistics) to behave reasonably inthat case.Bump catalog version.Author: Corey HuinkerDiscussion:https://postgr.es/m/CADkLM=eErgzn7ECDpwFcptJKOk9SxZEk5Pot4d94eVTZsvj3gw@mail.gmail.com
1 parentdbe6bd4 commitce207d2

File tree

11 files changed

+2263
-2
lines changed

11 files changed

+2263
-2
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30222,6 +30222,78 @@ DETAIL: Make sure pg_wal_replay_wait() isn't called within a transaction with a
3022230222
</para>
3022330223
</entry>
3022430224
</row>
30225+
30226+
<row>
30227+
<entry role="func_table_entry">
30228+
<para role="func_signature">
30229+
<indexterm>
30230+
<primary>pg_set_attribute_stats</primary>
30231+
</indexterm>
30232+
<function>pg_set_attribute_stats</function> (
30233+
<parameter>relation</parameter> <type>regclass</type>,
30234+
<parameter>attname</parameter> <type>name</type>,
30235+
<parameter>inherited</parameter> <type>boolean</type>
30236+
<optional>, <parameter>null_frac</parameter> <type>real</type></optional>
30237+
<optional>, <parameter>avg_width</parameter> <type>integer</type></optional>
30238+
<optional>, <parameter>n_distinct</parameter> <type>real</type></optional>
30239+
<optional>, <parameter>most_common_vals</parameter> <type>text</type>, <parameter>most_common_freqs</parameter> <type>real[]</type> </optional>
30240+
<optional>, <parameter>histogram_bounds</parameter> <type>text</type> </optional>
30241+
<optional>, <parameter>correlation</parameter> <type>real</type> </optional>
30242+
<optional>, <parameter>most_common_elems</parameter> <type>text</type>, <parameter>most_common_elem_freqs</parameter> <type>real[]</type> </optional>
30243+
<optional>, <parameter>elem_count_histogram</parameter> <type>real[]</type> </optional>
30244+
<optional>, <parameter>range_length_histogram</parameter> <type>text</type> </optional>
30245+
<optional>, <parameter>range_empty_frac</parameter> <type>real</type> </optional>
30246+
<optional>, <parameter>range_bounds_histogram</parameter> <type>text</type> </optional> )
30247+
<returnvalue>void</returnvalue>
30248+
</para>
30249+
<para>
30250+
Creates or updates attribute-level statistics for the given relation
30251+
and attribute name to the specified values. The parameters correspond
30252+
to to attributes of the same name found in the <link
30253+
linkend="view-pg-stats"><structname>pg_stats</structname></link>
30254+
view.
30255+
</para>
30256+
<para>
30257+
Optional parameters default to <literal>NULL</literal>, which leave
30258+
the corresponding statistic unchanged.
30259+
</para>
30260+
<para>
30261+
Ordinarily, these statistics are collected automatically or updated
30262+
as a part of <xref linkend="sql-vacuum"/> or <xref
30263+
linkend="sql-analyze"/>, so it's not necessary to call this
30264+
function. However, it may be useful when testing the effects of
30265+
statistics on the planner to understand or anticipate plan changes.
30266+
</para>
30267+
<para>
30268+
The caller must have the <literal>MAINTAIN</literal> privilege on
30269+
the table or be the owner of the database.
30270+
</para>
30271+
</entry>
30272+
</row>
30273+
30274+
<row>
30275+
<entry role="func_table_entry">
30276+
<para role="func_signature">
30277+
<indexterm>
30278+
<primary>pg_clear_attribute_stats</primary>
30279+
</indexterm>
30280+
<function>pg_clear_attribute_stats</function> (
30281+
<parameter>relation</parameter> <type>regclass</type>,
30282+
<parameter>attname</parameter> <type>name</type>,
30283+
<parameter>inherited</parameter> <type>boolean</type> )
30284+
<returnvalue>boolean</returnvalue>
30285+
</para>
30286+
<para>
30287+
Clears table-level statistics for the given relation attribute, as
30288+
though the table was newly created.
30289+
</para>
30290+
<para>
30291+
The caller must have the <literal>MAINTAIN</literal> privilege on
30292+
the table or be the owner of the database.
30293+
</para>
30294+
</entry>
30295+
</row>
30296+
3022530297
</tbody>
3022630298
</tgroup>
3022730299
</table>

‎src/backend/catalog/system_functions.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,28 @@ LANGUAGE INTERNAL
649649
CALLEDONNULL INPUT VOLATILE
650650
AS'pg_set_relation_stats';
651651

652+
CREATEOR REPLACE FUNCTION
653+
pg_set_attribute_stats(relation regclass,
654+
attname name,
655+
inherited bool,
656+
null_fracreal DEFAULTNULL,
657+
avg_widthinteger DEFAULTNULL,
658+
n_distinctreal DEFAULTNULL,
659+
most_common_valstext DEFAULTNULL,
660+
most_common_freqsreal[] DEFAULTNULL,
661+
histogram_boundstext DEFAULTNULL,
662+
correlationreal DEFAULTNULL,
663+
most_common_elemstext DEFAULTNULL,
664+
most_common_elem_freqsreal[] DEFAULTNULL,
665+
elem_count_histogramreal[] DEFAULTNULL,
666+
range_length_histogramtext DEFAULTNULL,
667+
range_empty_fracreal DEFAULTNULL,
668+
range_bounds_histogramtext DEFAULTNULL)
669+
RETURNS void
670+
LANGUAGE INTERNAL
671+
CALLEDONNULL INPUT VOLATILE
672+
AS'pg_set_attribute_stats';
673+
652674
--
653675
-- The default permissions for functions mean that anyone can execute them.
654676
-- A number of functions shouldn't be executable by just anyone, but rather

‎src/backend/statistics/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ top_builddir = ../../..
1313
include$(top_builddir)/src/Makefile.global
1414

1515
OBJS =\
16+
attribute_stats.o\
1617
dependencies.o\
1718
extended_stats.o\
1819
mcv.o\

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp