pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Doc: Remove obsolete CREATE AGGREGATE note.
4+ messages / 2 participants
[nested] [flat]

* pgsql: Doc: Remove obsolete CREATE AGGREGATE note.
@ 2020-07-29 00:00  Peter Geoghegan <pg@bowt.ie>
  0 siblings, 0 replies; 4+ messages in thread

From: Peter Geoghegan @ 2020-07-29 00:00 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Doc: Remove obsolete CREATE AGGREGATE note.

The planner is in fact willing to use hash aggregation when work_mem is
not set high enough for everything to fit in memory.  This has been the
case since commit 1f39bce0, which added disk-based hash aggregation.

There are a few remaining cases in which hash aggregation is avoided as
a matter of policy when the planner surmises that spilling will be
necessary.  For example, callers of choose_hashed_setop() still
conservatively avoid hash aggregation when spilling is anticipated.
That doesn't seem like a good enough reason to mention hash aggregation
in this context.

Backpatch: 13-, where disk-based hash aggregation was introduced.

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/e362f469c50f6e671285640cc2087345ab55a9b2

Modified Files
--------------
doc/src/sgml/ref/create_aggregate.sgml | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Doc: Remove obsolete CREATE AGGREGATE note.
@ 2020-07-29 00:00  Peter Geoghegan <pg@bowt.ie>
  0 siblings, 0 replies; 4+ messages in thread

From: Peter Geoghegan @ 2020-07-29 00:00 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Doc: Remove obsolete CREATE AGGREGATE note.

The planner is in fact willing to use hash aggregation when work_mem is
not set high enough for everything to fit in memory.  This has been the
case since commit 1f39bce0, which added disk-based hash aggregation.

There are a few remaining cases in which hash aggregation is avoided as
a matter of policy when the planner surmises that spilling will be
necessary.  For example, callers of choose_hashed_setop() still
conservatively avoid hash aggregation when spilling is anticipated.
That doesn't seem like a good enough reason to mention hash aggregation
in this context.

Backpatch: 13-, where disk-based hash aggregation was introduced.

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f36e82072c8866ba2eca08d88d1a5c3e0c3d1eb4

Modified Files
--------------
doc/src/sgml/ref/create_aggregate.sgml | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* [PATCH v1] Fix global icu collations for ICU < 54
@ 2022-03-18 08:20  Julien Rouhaud <julien.rouhaud@free.fr>
  0 siblings, 0 replies; 4+ messages in thread

From: Julien Rouhaud @ 2022-03-18 08:20 UTC (permalink / raw)

Multiple call sites didn't check for collation attributes validity, which has
to be done explicitly on ICU < 54.
---
 src/backend/commands/dbcommands.c |   9 +--
 src/backend/utils/adt/pg_locale.c |  24 +++++++
 src/bin/initdb/initdb.c           | 109 +++++++++++++++++++++++++++++-
 src/include/utils/pg_locale.h     |   1 +
 4 files changed, 134 insertions(+), 9 deletions(-)

inline patch 1: src/backend/commands/dbcommands.c, src/backend/utils/adt/pg_locale.c, src/bin/initdb/initdb.c and 1 more (+134/-9 lines) download inline-1.patchdiff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 2e1af642e4..104e45b66d 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -460,14 +460,7 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt) if (dblocprovider == COLLPROVIDER_ICU) { #ifdef USE_ICU - UErrorCode status; - - status = U_ZERO_ERROR; - ucol_open(dbiculocale, &status); - if (U_FAILURE(status)) - ereport(ERROR, - (errmsg("could not open collator for locale \"%s\": %s", - dbiculocale, u_errorName(status)))); + check_icu_locale(dbiculocale); #else ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index 4019255f8e..bc0a038168 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -1854,6 +1854,9 @@ icu_to_uchar(UChar **buff_uchar, const char *buff, size_t nbytes) * function's result is the number of bytes generated (not counting nul). * * The result string is nul-terminated. + * + * If you modify this function, modify accordingly the similar frontend + * function in initdb.c */ int32_t icu_from_uchar(char **result, const UChar *buff_uchar, int32_t len_uchar) @@ -1884,6 +1887,27 @@ icu_from_uchar(char **result, const UChar *buff_uchar, int32_t len_uchar) return len_result; } +/* + * Check if the given locale ID is valid, and ereport(ERROR) if it isn't. + */ +void +check_icu_locale(const char *icu_locale) +{ + UCollator *collator; + UErrorCode status; + + status = U_ZERO_ERROR; + collator = ucol_open(icu_locale, &status); + if (U_FAILURE(status)) + ereport(ERROR, + (errmsg("could not open collator for locale \"%s\": %s", + icu_locale, u_errorName(status)))); + + if (U_ICU_VERSION_MAJOR_NUM < 54) + icu_set_collation_attributes(collator, icu_locale); + ucol_close(collator); +} + /* * Parse collation attributes and apply them to the open collator. This takes * a string like "und@colStrength=primary;colCaseLevel=yes" and parses and diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index cbcd55288f..ee6243560b 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -282,6 +282,10 @@ static int locale_date_order(const char *locale); static void check_locale_name(int category, const char *locale, char **canonname); static bool check_locale_encoding(const char *locale, int encoding); +#ifdef USE_ICU +static void icu_set_collation_attributes(UCollator *collator, + const char *loc); +#endif static void setlocales(void); static void usage(const char *progname); void setup_pgdata(void); @@ -2145,6 +2149,105 @@ check_locale_encoding(const char *locale, int user_enc) return true; } +#ifdef USE_ICU +/* + * Frontend version of the same function in pg_locale.c. + * + * If you modify this function, modify accordingly the similar backend function + * in pg_locale.c + */ +static void +icu_set_collation_attributes(UCollator *collator, const char *loc) +{ + char *str = pg_strdup(loc); + + str = strchr(str, '@'); + if (!str) + return; + str++; + + for (char *token = strtok(str, ";"); token; token = strtok(NULL, ";")) + { + char *e = strchr(token, '='); + + if (e) + { + char *name; + char *value; + UColAttribute uattr; + UColAttributeValue uvalue; + UErrorCode status; + + status = U_ZERO_ERROR; + + *e = '\0'; + name = token; + value = e + 1; + + /* + * See attribute name and value lists in ICU i18n/coll.cpp + */ + if (pg_strcasecmp(name, "colstrength") == 0) + uattr = UCOL_STRENGTH; + else if (pg_strcasecmp(name, "colbackwards") == 0) + uattr = UCOL_FRENCH_COLLATION; + else if (pg_strcasecmp(name, "colcaselevel") == 0) + uattr = UCOL_CASE_LEVEL; + else if (pg_strcasecmp(name, "colcasefirst") == 0) + uattr = UCOL_CASE_FIRST; + else if (pg_strcasecmp(name, "colalternate") == 0) + uattr = UCOL_ALTERNATE_HANDLING; + else if (pg_strcasecmp(name, "colnormalization") == 0) + uattr = UCOL_NORMALIZATION_MODE; + else if (pg_strcasecmp(name, "colnumeric") == 0) + uattr = UCOL_NUMERIC_COLLATION; + else + /* ignore if unknown */ + continue; + + if (pg_strcasecmp(value, "primary") == 0) + uvalue = UCOL_PRIMARY; + else if (pg_strcasecmp(value, "secondary") == 0) + uvalue = UCOL_SECONDARY; + else if (pg_strcasecmp(value, "tertiary") == 0) + uvalue = UCOL_TERTIARY; + else if (pg_strcasecmp(value, "quaternary") == 0) + uvalue = UCOL_QUATERNARY; + else if (pg_strcasecmp(value, "identical") == 0) + uvalue = UCOL_IDENTICAL; + else if (pg_strcasecmp(value, "no") == 0) + uvalue = UCOL_OFF; + else if (pg_strcasecmp(value, "yes") == 0) + uvalue = UCOL_ON; + else if (pg_strcasecmp(value, "shifted") == 0) + uvalue = UCOL_SHIFTED; + else if (pg_strcasecmp(value, "non-ignorable") == 0) + uvalue = UCOL_NON_IGNORABLE; + else if (pg_strcasecmp(value, "lower") == 0) + uvalue = UCOL_LOWER_FIRST; + else if (pg_strcasecmp(value, "upper") == 0) + uvalue = UCOL_UPPER_FIRST; + else + status = U_ILLEGAL_ARGUMENT_ERROR; + + if (status == U_ZERO_ERROR) + ucol_setAttribute(collator, uattr, uvalue, &status); + + /* + * Pretend the error came from ucol_open(), for consistent error + * message across ICU versions. + */ + if (U_FAILURE(status)) + { + pg_log_error("could not open collator for locale \"%s\": %s", + loc, u_errorName(status)); + exit(1); + } + } + } +} +#endif + /* * set up the locale variables * @@ -2209,16 +2312,20 @@ setlocales(void) */ #ifdef USE_ICU { + UCollator *collator; UErrorCode status; status = U_ZERO_ERROR; - ucol_open(icu_locale, &status); + collator = ucol_open(icu_locale, &status); if (U_FAILURE(status)) { pg_log_error("could not open collator for locale \"%s\": %s", icu_locale, u_errorName(status)); exit(1); } + if (U_ICU_VERSION_MAJOR_NUM < 54) + icu_set_collation_attributes(collator, icu_locale); + ucol_close(collator); } #else pg_log_error("ICU is not supported in this build"); diff --git a/src/include/utils/pg_locale.h b/src/include/utils/pg_locale.h index 9b158f24a0..297d14d918 100644 --- a/src/include/utils/pg_locale.h +++ b/src/include/utils/pg_locale.h @@ -115,6 +115,7 @@ extern char *get_collation_actual_version(char collprovider, const char *collcol #ifdef USE_ICU extern int32_t icu_to_uchar(UChar **buff_uchar, const char *buff, size_t nbytes); extern int32_t icu_from_uchar(char **result, const UChar *buff_uchar, int32_t len_uchar); +extern void check_icu_locale(const char *icu_locale); #endif /* These functions convert from/to libc's wchar_t, *not* pg_wchar_t */ -- 2.33.1
--m4ycfp7bbeuwbyuj-- ^ permalink raw reply [nested|flat] 4+ messages in thread

* [PATCH v2] Fix global icu collations for ICU < 54
@ 2022-03-18 08:20  Julien Rouhaud <julien.rouhaud@free.fr>
  0 siblings, 0 replies; 4+ messages in thread

From: Julien Rouhaud @ 2022-03-18 08:20 UTC (permalink / raw)

createdb() didn't check for collation attributes validity, which has
to be done explicitly on ICU < 54.  It also forgot to close the ICU collator
opened during the check which leaks some memory.

To fix both, add a new check_icu_locale() that does all the appropriate
verification and close the ICU collator.

initdb also had some partial check for ICU < 54.  To have consistent error
reporting across major ICU versions, and get rid of the need to include ucol.h,
remove the partial check there.  The backend will report an error if needed
during the post-boostrap iniitialization phase.
---
 src/backend/commands/dbcommands.c |  9 +--------
 src/backend/utils/adt/pg_locale.c | 21 +++++++++++++++++++++
 src/bin/initdb/initdb.c           | 22 +++-------------------
 src/bin/initdb/t/001_initdb.pl    |  2 +-
 src/include/utils/pg_locale.h     |  1 +
 src/test/icu/t/010_database.pl    |  4 ++--
 6 files changed, 29 insertions(+), 30 deletions(-)

inline patch 1: src/backend/commands/dbcommands.c, src/backend/utils/adt/pg_locale.c, src/bin/initdb/initdb.c and 3 more (+29/-30 lines) download inline-1.patchdiff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 962e11dd8f..15b6eb8e0e 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -460,14 +460,7 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt) if (dblocprovider == COLLPROVIDER_ICU) { #ifdef USE_ICU - UErrorCode status; - - status = U_ZERO_ERROR; - ucol_open(dbiculocale, &status); - if (U_FAILURE(status)) - ereport(ERROR, - (errmsg("could not open collator for locale \"%s\": %s", - dbiculocale, u_errorName(status)))); + check_icu_locale(dbiculocale); #else ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index 4019255f8e..af69f2729e 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -1884,6 +1884,27 @@ icu_from_uchar(char **result, const UChar *buff_uchar, int32_t len_uchar) return len_result; } +/* + * Check if the given locale ID is valid, and ereport(ERROR) if it isn't. + */ +void +check_icu_locale(const char *icu_locale) +{ + UCollator *collator; + UErrorCode status; + + status = U_ZERO_ERROR; + collator = ucol_open(icu_locale, &status); + if (U_FAILURE(status)) + ereport(ERROR, + (errmsg("could not open collator for locale \"%s\": %s", + icu_locale, u_errorName(status)))); + + if (U_ICU_VERSION_MAJOR_NUM < 54) + icu_set_collation_attributes(collator, icu_locale); + ucol_close(collator); +} + /* * Parse collation attributes and apply them to the open collator. This takes * a string like "und@colStrength=primary;colCaseLevel=yes" and parses and diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index cbcd55288f..5e36943ef3 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -55,10 +55,6 @@ #include <signal.h> #include <time.h> -#ifdef USE_ICU -#include <unicode/ucol.h> -#endif - #ifdef HAVE_SHM_OPEN #include "sys/mman.h" #endif @@ -2205,22 +2201,10 @@ setlocales(void) } /* - * Check ICU locale ID + * In supported builds, the ICU locale ID will be checked by the + * backend when performing the post-boostrap initialization. */ -#ifdef USE_ICU - { - UErrorCode status; - - status = U_ZERO_ERROR; - ucol_open(icu_locale, &status); - if (U_FAILURE(status)) - { - pg_log_error("could not open collator for locale \"%s\": %s", - icu_locale, u_errorName(status)); - exit(1); - } - } -#else +#ifndef USE_ICU pg_log_error("ICU is not supported in this build"); fprintf(stderr, _("You need to rebuild PostgreSQL using %s.\n"), "--with-icu"); exit(1); diff --git a/src/bin/initdb/t/001_initdb.pl b/src/bin/initdb/t/001_initdb.pl index c636bf3ab2..a3397777cf 100644 --- a/src/bin/initdb/t/001_initdb.pl +++ b/src/bin/initdb/t/001_initdb.pl @@ -105,7 +105,7 @@ if ($ENV{with_icu} eq 'yes') 'option --icu-locale'); command_fails_like(['initdb', '--no-sync', '--locale-provider=icu', '--icu-locale=@colNumeric=lower', "$tempdir/dataX"], - qr/initdb: error: could not open collator for locale/, + qr/FATAL: could not open collator for locale/, 'fails for invalid ICU locale'); } else diff --git a/src/include/utils/pg_locale.h b/src/include/utils/pg_locale.h index 9b158f24a0..297d14d918 100644 --- a/src/include/utils/pg_locale.h +++ b/src/include/utils/pg_locale.h @@ -115,6 +115,7 @@ extern char *get_collation_actual_version(char collprovider, const char *collcol #ifdef USE_ICU extern int32_t icu_to_uchar(UChar **buff_uchar, const char *buff, size_t nbytes); extern int32_t icu_from_uchar(char **result, const UChar *buff_uchar, int32_t len_uchar); +extern void check_icu_locale(const char *icu_locale); #endif /* These functions convert from/to libc's wchar_t, *not* pg_wchar_t */ diff --git a/src/test/icu/t/010_database.pl b/src/test/icu/t/010_database.pl index d50941b53d..07a1084b09 100644 --- a/src/test/icu/t/010_database.pl +++ b/src/test/icu/t/010_database.pl @@ -16,11 +16,11 @@ $node1->init; $node1->start; $node1->safe_psql('postgres', - q{CREATE DATABASE dbicu LOCALE_PROVIDER icu LOCALE 'C' ICU_LOCALE 'en-u-kf-upper' ENCODING 'UTF8' TEMPLATE template0}); + q{CREATE DATABASE dbicu LOCALE_PROVIDER icu LOCALE 'C' ICU_LOCALE 'en@colCaseFirst=upper' ENCODING 'UTF8' TEMPLATE template0}); $node1->safe_psql('dbicu', q{ -CREATE COLLATION upperfirst (provider = icu, locale = 'en-u-kf-upper'); +CREATE COLLATION upperfirst (provider = icu, locale = 'en@colCaseFirst=upper'); CREATE TABLE icu (def text, en text COLLATE "en-x-icu", upfirst text COLLATE upperfirst); INSERT INTO icu VALUES ('a', 'a', 'a'), ('b', 'b', 'b'), ('A', 'A', 'A'), ('B', 'B', 'B'); }); -- 2.33.1
--pzaifvl6dybqyz3b-- ^ permalink raw reply [nested|flat] 4+ messages in thread


end of thread, other threads:[~2022-03-18 08:20 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-07-29 00:00 pgsql: Doc: Remove obsolete CREATE AGGREGATE note. Peter Geoghegan <pg@bowt.ie>
2020-07-29 00:00 pgsql: Doc: Remove obsolete CREATE AGGREGATE note. Peter Geoghegan <pg@bowt.ie>
2022-03-18 08:20 [PATCH v1] Fix global icu collations for ICU < 54 Julien Rouhaud <julien.rouhaud@free.fr>
2022-03-18 08:20 [PATCH v2] Fix global icu collations for ICU < 54 Julien Rouhaud <julien.rouhaud@free.fr>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox