2011-02-12 14:54:13 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* pg_collation.c
|
|
|
|
* routines to support manipulation of the pg_collation relation
|
|
|
|
*
|
2023-01-02 21:00:37 +01:00
|
|
|
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
|
2011-02-12 14:54:13 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
|
|
|
* src/backend/catalog/pg_collation.c
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
2019-12-27 00:09:00 +01:00
|
|
|
#include "access/genam.h"
|
2012-08-30 22:15:44 +02:00
|
|
|
#include "access/htup_details.h"
|
2011-02-12 14:54:13 +01:00
|
|
|
#include "access/sysattr.h"
|
2019-01-21 19:18:20 +01:00
|
|
|
#include "access/table.h"
|
Remove WITH OIDS support, change oid catalog column visibility.
Previously tables declared WITH OIDS, including a significant fraction
of the catalog tables, stored the oid column not as a normal column,
but as part of the tuple header.
This special column was not shown by default, which was somewhat odd,
as it's often (consider e.g. pg_class.oid) one of the more important
parts of a row. Neither pg_dump nor COPY included the contents of the
oid column by default.
The fact that the oid column was not an ordinary column necessitated a
significant amount of special case code to support oid columns. That
already was painful for the existing, but upcoming work aiming to make
table storage pluggable, would have required expanding and duplicating
that "specialness" significantly.
WITH OIDS has been deprecated since 2005 (commit ff02d0a05280e0).
Remove it.
Removing includes:
- CREATE TABLE and ALTER TABLE syntax for declaring the table to be
WITH OIDS has been removed (WITH (oids[ = true]) will error out)
- pg_dump does not support dumping tables declared WITH OIDS and will
issue a warning when dumping one (and ignore the oid column).
- restoring an pg_dump archive with pg_restore will warn when
restoring a table with oid contents (and ignore the oid column)
- COPY will refuse to load binary dump that includes oids.
- pg_upgrade will error out when encountering tables declared WITH
OIDS, they have to be altered to remove the oid column first.
- Functionality to access the oid of the last inserted row (like
plpgsql's RESULT_OID, spi's SPI_lastoid, ...) has been removed.
The syntax for declaring a table WITHOUT OIDS (or WITH (oids = false)
for CREATE TABLE) is still supported. While that requires a bit of
support code, it seems unnecessary to break applications / dumps that
do not use oids, and are explicit about not using them.
The biggest user of WITH OID columns was postgres' catalog. This
commit changes all 'magic' oid columns to be columns that are normally
declared and stored. To reduce unnecessary query breakage all the
newly added columns are still named 'oid', even if a table's column
naming scheme would indicate 'reloid' or such. This obviously
requires adapting a lot code, mostly replacing oid access via
HeapTupleGetOid() with access to the underlying Form_pg_*->oid column.
The bootstrap process now assigns oids for all oid columns in
genbki.pl that do not have an explicit value (starting at the largest
oid previously used), only oids assigned later by oids will be above
FirstBootstrapObjectId. As the oid column now is a normal column the
special bootstrap syntax for oids has been removed.
Oids are not automatically assigned during insertion anymore, all
backend code explicitly assigns oids with GetNewOidWithIndex(). For
the rare case that insertions into the catalog via SQL are called for
the new pg_nextoid() function can be used (which only works on catalog
tables).
The fact that oid columns on system tables are now normal columns
means that they will be included in the set of columns expanded
by * (i.e. SELECT * FROM pg_class will now include the table's oid,
previously it did not). It'd not technically be hard to hide oid
column by default, but that'd mean confusing behavior would either
have to be carried forward forever, or it'd cause breakage down the
line.
While it's not unlikely that further adjustments are needed, the
scope/invasiveness of the patch makes it worthwhile to get merge this
now. It's painful to maintain externally, too complicated to commit
after the code code freeze, and a dependency of a number of other
patches.
Catversion bump, for obvious reasons.
Author: Andres Freund, with contributions by John Naylor
Discussion: https://postgr.es/m/20180930034810.ywp2c7awz7opzcfr@alap3.anarazel.de
2018-11-21 00:36:57 +01:00
|
|
|
#include "catalog/catalog.h"
|
2011-02-12 14:54:13 +01:00
|
|
|
#include "catalog/dependency.h"
|
|
|
|
#include "catalog/indexing.h"
|
|
|
|
#include "catalog/objectaccess.h"
|
|
|
|
#include "catalog/pg_collation.h"
|
|
|
|
#include "catalog/pg_namespace.h"
|
|
|
|
#include "mb/pg_wchar.h"
|
|
|
|
#include "utils/builtins.h"
|
|
|
|
#include "utils/fmgroids.h"
|
2017-03-23 20:25:34 +01:00
|
|
|
#include "utils/pg_locale.h"
|
2011-03-26 04:10:07 +01:00
|
|
|
#include "utils/rel.h"
|
2011-02-12 14:54:13 +01:00
|
|
|
#include "utils/syscache.h"
|
|
|
|
|
2011-03-11 19:20:11 +01:00
|
|
|
|
2011-02-12 14:54:13 +01:00
|
|
|
/*
|
|
|
|
* CollationCreate
|
|
|
|
*
|
|
|
|
* Add a new tuple to pg_collation.
|
Rethink behavior of pg_import_system_collations().
Marco Atzeri reported that initdb would fail if "locale -a" reported
the same locale name more than once. All previous versions of Postgres
implicitly de-duplicated the results of "locale -a", but the rewrite
to move the collation import logic into C had lost that property.
It had also lost the property that locale names matching built-in
collation names were silently ignored.
The simplest way to fix this is to make initdb run the function in
if-not-exists mode, which means that there's no real use-case for
non if-not-exists mode; we might as well just drop the boolean argument
and simplify the function's definition to be "add any collations not
already known". This change also gets rid of some odd corner cases
caused by the fact that aliases were added in if-not-exists mode even
if the function argument said otherwise.
While at it, adjust the behavior so that pg_import_system_collations()
doesn't spew "collation foo already exists, skipping" messages during a
re-run; that's completely unhelpful, especially since there are often
hundreds of them. And make it return a count of the number of collations
it did add, which seems like it might be helpful.
Also, re-integrate the previous coding's property that it would make a
deterministic selection of which alias to use if there were conflicting
possibilities. This would only come into play if "locale -a" reports
multiple equivalent locale names, say "de_DE.utf8" and "de_DE.UTF-8",
but that hardly seems out of the question.
In passing, fix incorrect behavior in pg_import_system_collations()'s
ICU code path: it neglected CommandCounterIncrement, which would result
in failures if ICU returns duplicate names, and it would try to create
comments even if a new collation hadn't been created.
Also, reorder operations in initdb so that the 'ucs_basic' collation
is created before calling pg_import_system_collations() not after.
This prevents a failure if "locale -a" were to report a locale named
that. There's no reason to think that that ever happens in the wild,
but the old coding would have survived it, so let's be equally robust.
Discussion: https://postgr.es/m/20c74bc3-d6ca-243d-1bbc-12f17fa4fe9a@gmail.com
2017-06-23 20:19:48 +02:00
|
|
|
*
|
|
|
|
* if_not_exists: if true, don't fail on duplicate name, just print a notice
|
|
|
|
* and return InvalidOid.
|
|
|
|
* quiet: if true, don't fail on duplicate name, just silently return
|
|
|
|
* InvalidOid (overrides if_not_exists).
|
2011-02-12 14:54:13 +01:00
|
|
|
*/
|
|
|
|
Oid
|
|
|
|
CollationCreate(const char *collname, Oid collnamespace,
|
|
|
|
Oid collowner,
|
2017-03-23 20:25:34 +01:00
|
|
|
char collprovider,
|
2019-03-22 12:09:32 +01:00
|
|
|
bool collisdeterministic,
|
2011-02-12 14:54:13 +01:00
|
|
|
int32 collencoding,
|
2017-01-18 18:00:00 +01:00
|
|
|
const char *collcollate, const char *collctype,
|
2022-03-17 11:11:21 +01:00
|
|
|
const char *colliculocale,
|
2023-03-08 16:35:42 +01:00
|
|
|
const char *collicurules,
|
2021-05-07 10:17:42 +02:00
|
|
|
const char *collversion,
|
Rethink behavior of pg_import_system_collations().
Marco Atzeri reported that initdb would fail if "locale -a" reported
the same locale name more than once. All previous versions of Postgres
implicitly de-duplicated the results of "locale -a", but the rewrite
to move the collation import logic into C had lost that property.
It had also lost the property that locale names matching built-in
collation names were silently ignored.
The simplest way to fix this is to make initdb run the function in
if-not-exists mode, which means that there's no real use-case for
non if-not-exists mode; we might as well just drop the boolean argument
and simplify the function's definition to be "add any collations not
already known". This change also gets rid of some odd corner cases
caused by the fact that aliases were added in if-not-exists mode even
if the function argument said otherwise.
While at it, adjust the behavior so that pg_import_system_collations()
doesn't spew "collation foo already exists, skipping" messages during a
re-run; that's completely unhelpful, especially since there are often
hundreds of them. And make it return a count of the number of collations
it did add, which seems like it might be helpful.
Also, re-integrate the previous coding's property that it would make a
deterministic selection of which alias to use if there were conflicting
possibilities. This would only come into play if "locale -a" reports
multiple equivalent locale names, say "de_DE.utf8" and "de_DE.UTF-8",
but that hardly seems out of the question.
In passing, fix incorrect behavior in pg_import_system_collations()'s
ICU code path: it neglected CommandCounterIncrement, which would result
in failures if ICU returns duplicate names, and it would try to create
comments even if a new collation hadn't been created.
Also, reorder operations in initdb so that the 'ucs_basic' collation
is created before calling pg_import_system_collations() not after.
This prevents a failure if "locale -a" were to report a locale named
that. There's no reason to think that that ever happens in the wild,
but the old coding would have survived it, so let's be equally robust.
Discussion: https://postgr.es/m/20c74bc3-d6ca-243d-1bbc-12f17fa4fe9a@gmail.com
2017-06-23 20:19:48 +02:00
|
|
|
bool if_not_exists,
|
|
|
|
bool quiet)
|
2011-02-12 14:54:13 +01:00
|
|
|
{
|
|
|
|
Relation rel;
|
|
|
|
TupleDesc tupDesc;
|
|
|
|
HeapTuple tup;
|
|
|
|
Datum values[Natts_pg_collation];
|
2011-03-11 19:20:11 +01:00
|
|
|
bool nulls[Natts_pg_collation];
|
2022-01-27 08:44:31 +01:00
|
|
|
NameData name_name;
|
2011-02-12 14:54:13 +01:00
|
|
|
Oid oid;
|
|
|
|
ObjectAddress myself,
|
|
|
|
referenced;
|
|
|
|
|
2022-10-28 09:19:06 +02:00
|
|
|
Assert(collname);
|
|
|
|
Assert(collnamespace);
|
|
|
|
Assert(collowner);
|
|
|
|
Assert((collcollate && collctype) || colliculocale);
|
2011-02-12 14:54:13 +01:00
|
|
|
|
2011-03-11 19:20:11 +01:00
|
|
|
/*
|
|
|
|
* Make sure there is no existing collation of same name & encoding.
|
|
|
|
*
|
|
|
|
* This would be caught by the unique index anyway; we're just giving a
|
|
|
|
* friendlier error message. The unique index provides a backstop against
|
|
|
|
* race conditions.
|
|
|
|
*/
|
2022-08-08 17:12:31 +02:00
|
|
|
oid = GetSysCacheOid3(COLLNAMEENCNSP,
|
|
|
|
Anum_pg_collation_oid,
|
|
|
|
PointerGetDatum(collname),
|
|
|
|
Int32GetDatum(collencoding),
|
|
|
|
ObjectIdGetDatum(collnamespace));
|
|
|
|
if (OidIsValid(oid))
|
2017-01-18 18:00:00 +01:00
|
|
|
{
|
Rethink behavior of pg_import_system_collations().
Marco Atzeri reported that initdb would fail if "locale -a" reported
the same locale name more than once. All previous versions of Postgres
implicitly de-duplicated the results of "locale -a", but the rewrite
to move the collation import logic into C had lost that property.
It had also lost the property that locale names matching built-in
collation names were silently ignored.
The simplest way to fix this is to make initdb run the function in
if-not-exists mode, which means that there's no real use-case for
non if-not-exists mode; we might as well just drop the boolean argument
and simplify the function's definition to be "add any collations not
already known". This change also gets rid of some odd corner cases
caused by the fact that aliases were added in if-not-exists mode even
if the function argument said otherwise.
While at it, adjust the behavior so that pg_import_system_collations()
doesn't spew "collation foo already exists, skipping" messages during a
re-run; that's completely unhelpful, especially since there are often
hundreds of them. And make it return a count of the number of collations
it did add, which seems like it might be helpful.
Also, re-integrate the previous coding's property that it would make a
deterministic selection of which alias to use if there were conflicting
possibilities. This would only come into play if "locale -a" reports
multiple equivalent locale names, say "de_DE.utf8" and "de_DE.UTF-8",
but that hardly seems out of the question.
In passing, fix incorrect behavior in pg_import_system_collations()'s
ICU code path: it neglected CommandCounterIncrement, which would result
in failures if ICU returns duplicate names, and it would try to create
comments even if a new collation hadn't been created.
Also, reorder operations in initdb so that the 'ucs_basic' collation
is created before calling pg_import_system_collations() not after.
This prevents a failure if "locale -a" were to report a locale named
that. There's no reason to think that that ever happens in the wild,
but the old coding would have survived it, so let's be equally robust.
Discussion: https://postgr.es/m/20c74bc3-d6ca-243d-1bbc-12f17fa4fe9a@gmail.com
2017-06-23 20:19:48 +02:00
|
|
|
if (quiet)
|
|
|
|
return InvalidOid;
|
|
|
|
else if (if_not_exists)
|
2017-01-18 18:00:00 +01:00
|
|
|
{
|
2022-08-08 17:12:31 +02:00
|
|
|
/*
|
|
|
|
* If we are in an extension script, insist that the pre-existing
|
|
|
|
* object be a member of the extension, to avoid security risks.
|
|
|
|
*/
|
|
|
|
ObjectAddressSet(myself, CollationRelationId, oid);
|
|
|
|
checkMembershipInCurrentExtension(&myself);
|
|
|
|
|
|
|
|
/* OK to skip */
|
2017-01-18 18:00:00 +01:00
|
|
|
ereport(NOTICE,
|
2011-02-12 14:54:13 +01:00
|
|
|
(errcode(ERRCODE_DUPLICATE_OBJECT),
|
2017-03-23 20:25:34 +01:00
|
|
|
collencoding == -1
|
|
|
|
? errmsg("collation \"%s\" already exists, skipping",
|
|
|
|
collname)
|
|
|
|
: errmsg("collation \"%s\" for encoding \"%s\" already exists, skipping",
|
|
|
|
collname, pg_encoding_to_char(collencoding))));
|
2017-01-18 18:00:00 +01:00
|
|
|
return InvalidOid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DUPLICATE_OBJECT),
|
2017-03-23 20:25:34 +01:00
|
|
|
collencoding == -1
|
|
|
|
? errmsg("collation \"%s\" already exists",
|
|
|
|
collname)
|
|
|
|
: errmsg("collation \"%s\" for encoding \"%s\" already exists",
|
|
|
|
collname, pg_encoding_to_char(collencoding))));
|
2017-01-18 18:00:00 +01:00
|
|
|
}
|
2011-02-12 14:54:13 +01:00
|
|
|
|
2017-03-23 20:25:34 +01:00
|
|
|
/* open pg_collation; see below about the lock level */
|
2019-01-21 19:32:19 +01:00
|
|
|
rel = table_open(CollationRelationId, ShareRowExclusiveLock);
|
2017-03-23 20:25:34 +01:00
|
|
|
|
2011-03-11 19:20:11 +01:00
|
|
|
/*
|
2017-03-23 20:25:34 +01:00
|
|
|
* Also forbid a specific-encoding collation shadowing an any-encoding
|
|
|
|
* collation, or an any-encoding collation being shadowed (see
|
|
|
|
* get_collation_name()). This test is not backed up by the unique index,
|
|
|
|
* so we take a ShareRowExclusiveLock earlier, to protect against
|
|
|
|
* concurrent changes fooling this check.
|
2011-03-11 19:20:11 +01:00
|
|
|
*/
|
2022-08-08 17:12:31 +02:00
|
|
|
if (collencoding == -1)
|
|
|
|
oid = GetSysCacheOid3(COLLNAMEENCNSP,
|
|
|
|
Anum_pg_collation_oid,
|
|
|
|
PointerGetDatum(collname),
|
|
|
|
Int32GetDatum(GetDatabaseEncoding()),
|
|
|
|
ObjectIdGetDatum(collnamespace));
|
|
|
|
else
|
|
|
|
oid = GetSysCacheOid3(COLLNAMEENCNSP,
|
|
|
|
Anum_pg_collation_oid,
|
|
|
|
PointerGetDatum(collname),
|
|
|
|
Int32GetDatum(-1),
|
|
|
|
ObjectIdGetDatum(collnamespace));
|
|
|
|
if (OidIsValid(oid))
|
2017-01-18 18:00:00 +01:00
|
|
|
{
|
Rethink behavior of pg_import_system_collations().
Marco Atzeri reported that initdb would fail if "locale -a" reported
the same locale name more than once. All previous versions of Postgres
implicitly de-duplicated the results of "locale -a", but the rewrite
to move the collation import logic into C had lost that property.
It had also lost the property that locale names matching built-in
collation names were silently ignored.
The simplest way to fix this is to make initdb run the function in
if-not-exists mode, which means that there's no real use-case for
non if-not-exists mode; we might as well just drop the boolean argument
and simplify the function's definition to be "add any collations not
already known". This change also gets rid of some odd corner cases
caused by the fact that aliases were added in if-not-exists mode even
if the function argument said otherwise.
While at it, adjust the behavior so that pg_import_system_collations()
doesn't spew "collation foo already exists, skipping" messages during a
re-run; that's completely unhelpful, especially since there are often
hundreds of them. And make it return a count of the number of collations
it did add, which seems like it might be helpful.
Also, re-integrate the previous coding's property that it would make a
deterministic selection of which alias to use if there were conflicting
possibilities. This would only come into play if "locale -a" reports
multiple equivalent locale names, say "de_DE.utf8" and "de_DE.UTF-8",
but that hardly seems out of the question.
In passing, fix incorrect behavior in pg_import_system_collations()'s
ICU code path: it neglected CommandCounterIncrement, which would result
in failures if ICU returns duplicate names, and it would try to create
comments even if a new collation hadn't been created.
Also, reorder operations in initdb so that the 'ucs_basic' collation
is created before calling pg_import_system_collations() not after.
This prevents a failure if "locale -a" were to report a locale named
that. There's no reason to think that that ever happens in the wild,
but the old coding would have survived it, so let's be equally robust.
Discussion: https://postgr.es/m/20c74bc3-d6ca-243d-1bbc-12f17fa4fe9a@gmail.com
2017-06-23 20:19:48 +02:00
|
|
|
if (quiet)
|
|
|
|
{
|
2019-01-21 19:32:19 +01:00
|
|
|
table_close(rel, NoLock);
|
Rethink behavior of pg_import_system_collations().
Marco Atzeri reported that initdb would fail if "locale -a" reported
the same locale name more than once. All previous versions of Postgres
implicitly de-duplicated the results of "locale -a", but the rewrite
to move the collation import logic into C had lost that property.
It had also lost the property that locale names matching built-in
collation names were silently ignored.
The simplest way to fix this is to make initdb run the function in
if-not-exists mode, which means that there's no real use-case for
non if-not-exists mode; we might as well just drop the boolean argument
and simplify the function's definition to be "add any collations not
already known". This change also gets rid of some odd corner cases
caused by the fact that aliases were added in if-not-exists mode even
if the function argument said otherwise.
While at it, adjust the behavior so that pg_import_system_collations()
doesn't spew "collation foo already exists, skipping" messages during a
re-run; that's completely unhelpful, especially since there are often
hundreds of them. And make it return a count of the number of collations
it did add, which seems like it might be helpful.
Also, re-integrate the previous coding's property that it would make a
deterministic selection of which alias to use if there were conflicting
possibilities. This would only come into play if "locale -a" reports
multiple equivalent locale names, say "de_DE.utf8" and "de_DE.UTF-8",
but that hardly seems out of the question.
In passing, fix incorrect behavior in pg_import_system_collations()'s
ICU code path: it neglected CommandCounterIncrement, which would result
in failures if ICU returns duplicate names, and it would try to create
comments even if a new collation hadn't been created.
Also, reorder operations in initdb so that the 'ucs_basic' collation
is created before calling pg_import_system_collations() not after.
This prevents a failure if "locale -a" were to report a locale named
that. There's no reason to think that that ever happens in the wild,
but the old coding would have survived it, so let's be equally robust.
Discussion: https://postgr.es/m/20c74bc3-d6ca-243d-1bbc-12f17fa4fe9a@gmail.com
2017-06-23 20:19:48 +02:00
|
|
|
return InvalidOid;
|
|
|
|
}
|
|
|
|
else if (if_not_exists)
|
2017-01-18 18:00:00 +01:00
|
|
|
{
|
2022-08-08 17:12:31 +02:00
|
|
|
/*
|
|
|
|
* If we are in an extension script, insist that the pre-existing
|
|
|
|
* object be a member of the extension, to avoid security risks.
|
|
|
|
*/
|
|
|
|
ObjectAddressSet(myself, CollationRelationId, oid);
|
|
|
|
checkMembershipInCurrentExtension(&myself);
|
|
|
|
|
|
|
|
/* OK to skip */
|
2019-01-21 19:32:19 +01:00
|
|
|
table_close(rel, NoLock);
|
2017-01-18 18:00:00 +01:00
|
|
|
ereport(NOTICE,
|
|
|
|
(errcode(ERRCODE_DUPLICATE_OBJECT),
|
|
|
|
errmsg("collation \"%s\" already exists, skipping",
|
|
|
|
collname)));
|
|
|
|
return InvalidOid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ereport(ERROR,
|
2011-03-11 19:20:11 +01:00
|
|
|
(errcode(ERRCODE_DUPLICATE_OBJECT),
|
|
|
|
errmsg("collation \"%s\" already exists",
|
|
|
|
collname)));
|
2017-01-18 18:00:00 +01:00
|
|
|
}
|
2011-03-11 19:20:11 +01:00
|
|
|
|
|
|
|
tupDesc = RelationGetDescr(rel);
|
2011-02-12 14:54:13 +01:00
|
|
|
|
|
|
|
/* form a tuple */
|
2011-03-11 19:20:11 +01:00
|
|
|
memset(nulls, 0, sizeof(nulls));
|
|
|
|
|
2011-02-12 14:54:13 +01:00
|
|
|
namestrcpy(&name_name, collname);
|
Remove WITH OIDS support, change oid catalog column visibility.
Previously tables declared WITH OIDS, including a significant fraction
of the catalog tables, stored the oid column not as a normal column,
but as part of the tuple header.
This special column was not shown by default, which was somewhat odd,
as it's often (consider e.g. pg_class.oid) one of the more important
parts of a row. Neither pg_dump nor COPY included the contents of the
oid column by default.
The fact that the oid column was not an ordinary column necessitated a
significant amount of special case code to support oid columns. That
already was painful for the existing, but upcoming work aiming to make
table storage pluggable, would have required expanding and duplicating
that "specialness" significantly.
WITH OIDS has been deprecated since 2005 (commit ff02d0a05280e0).
Remove it.
Removing includes:
- CREATE TABLE and ALTER TABLE syntax for declaring the table to be
WITH OIDS has been removed (WITH (oids[ = true]) will error out)
- pg_dump does not support dumping tables declared WITH OIDS and will
issue a warning when dumping one (and ignore the oid column).
- restoring an pg_dump archive with pg_restore will warn when
restoring a table with oid contents (and ignore the oid column)
- COPY will refuse to load binary dump that includes oids.
- pg_upgrade will error out when encountering tables declared WITH
OIDS, they have to be altered to remove the oid column first.
- Functionality to access the oid of the last inserted row (like
plpgsql's RESULT_OID, spi's SPI_lastoid, ...) has been removed.
The syntax for declaring a table WITHOUT OIDS (or WITH (oids = false)
for CREATE TABLE) is still supported. While that requires a bit of
support code, it seems unnecessary to break applications / dumps that
do not use oids, and are explicit about not using them.
The biggest user of WITH OID columns was postgres' catalog. This
commit changes all 'magic' oid columns to be columns that are normally
declared and stored. To reduce unnecessary query breakage all the
newly added columns are still named 'oid', even if a table's column
naming scheme would indicate 'reloid' or such. This obviously
requires adapting a lot code, mostly replacing oid access via
HeapTupleGetOid() with access to the underlying Form_pg_*->oid column.
The bootstrap process now assigns oids for all oid columns in
genbki.pl that do not have an explicit value (starting at the largest
oid previously used), only oids assigned later by oids will be above
FirstBootstrapObjectId. As the oid column now is a normal column the
special bootstrap syntax for oids has been removed.
Oids are not automatically assigned during insertion anymore, all
backend code explicitly assigns oids with GetNewOidWithIndex(). For
the rare case that insertions into the catalog via SQL are called for
the new pg_nextoid() function can be used (which only works on catalog
tables).
The fact that oid columns on system tables are now normal columns
means that they will be included in the set of columns expanded
by * (i.e. SELECT * FROM pg_class will now include the table's oid,
previously it did not). It'd not technically be hard to hide oid
column by default, but that'd mean confusing behavior would either
have to be carried forward forever, or it'd cause breakage down the
line.
While it's not unlikely that further adjustments are needed, the
scope/invasiveness of the patch makes it worthwhile to get merge this
now. It's painful to maintain externally, too complicated to commit
after the code code freeze, and a dependency of a number of other
patches.
Catversion bump, for obvious reasons.
Author: Andres Freund, with contributions by John Naylor
Discussion: https://postgr.es/m/20180930034810.ywp2c7awz7opzcfr@alap3.anarazel.de
2018-11-21 00:36:57 +01:00
|
|
|
oid = GetNewOidWithIndex(rel, CollationOidIndexId,
|
|
|
|
Anum_pg_collation_oid);
|
|
|
|
values[Anum_pg_collation_oid - 1] = ObjectIdGetDatum(oid);
|
2011-02-12 14:54:13 +01:00
|
|
|
values[Anum_pg_collation_collname - 1] = NameGetDatum(&name_name);
|
|
|
|
values[Anum_pg_collation_collnamespace - 1] = ObjectIdGetDatum(collnamespace);
|
|
|
|
values[Anum_pg_collation_collowner - 1] = ObjectIdGetDatum(collowner);
|
2017-03-23 20:25:34 +01:00
|
|
|
values[Anum_pg_collation_collprovider - 1] = CharGetDatum(collprovider);
|
2019-03-22 12:09:32 +01:00
|
|
|
values[Anum_pg_collation_collisdeterministic - 1] = BoolGetDatum(collisdeterministic);
|
2011-02-12 14:54:13 +01:00
|
|
|
values[Anum_pg_collation_collencoding - 1] = Int32GetDatum(collencoding);
|
2022-03-17 11:11:21 +01:00
|
|
|
if (collcollate)
|
|
|
|
values[Anum_pg_collation_collcollate - 1] = CStringGetTextDatum(collcollate);
|
|
|
|
else
|
|
|
|
nulls[Anum_pg_collation_collcollate - 1] = true;
|
|
|
|
if (collctype)
|
|
|
|
values[Anum_pg_collation_collctype - 1] = CStringGetTextDatum(collctype);
|
|
|
|
else
|
|
|
|
nulls[Anum_pg_collation_collctype - 1] = true;
|
|
|
|
if (colliculocale)
|
|
|
|
values[Anum_pg_collation_colliculocale - 1] = CStringGetTextDatum(colliculocale);
|
|
|
|
else
|
|
|
|
nulls[Anum_pg_collation_colliculocale - 1] = true;
|
2023-03-08 16:35:42 +01:00
|
|
|
if (collicurules)
|
|
|
|
values[Anum_pg_collation_collicurules - 1] = CStringGetTextDatum(collicurules);
|
|
|
|
else
|
|
|
|
nulls[Anum_pg_collation_collicurules - 1] = true;
|
2021-05-07 10:17:42 +02:00
|
|
|
if (collversion)
|
|
|
|
values[Anum_pg_collation_collversion - 1] = CStringGetTextDatum(collversion);
|
|
|
|
else
|
|
|
|
nulls[Anum_pg_collation_collversion - 1] = true;
|
2011-02-12 14:54:13 +01:00
|
|
|
|
|
|
|
tup = heap_form_tuple(tupDesc, values, nulls);
|
|
|
|
|
|
|
|
/* insert a new tuple */
|
Remove WITH OIDS support, change oid catalog column visibility.
Previously tables declared WITH OIDS, including a significant fraction
of the catalog tables, stored the oid column not as a normal column,
but as part of the tuple header.
This special column was not shown by default, which was somewhat odd,
as it's often (consider e.g. pg_class.oid) one of the more important
parts of a row. Neither pg_dump nor COPY included the contents of the
oid column by default.
The fact that the oid column was not an ordinary column necessitated a
significant amount of special case code to support oid columns. That
already was painful for the existing, but upcoming work aiming to make
table storage pluggable, would have required expanding and duplicating
that "specialness" significantly.
WITH OIDS has been deprecated since 2005 (commit ff02d0a05280e0).
Remove it.
Removing includes:
- CREATE TABLE and ALTER TABLE syntax for declaring the table to be
WITH OIDS has been removed (WITH (oids[ = true]) will error out)
- pg_dump does not support dumping tables declared WITH OIDS and will
issue a warning when dumping one (and ignore the oid column).
- restoring an pg_dump archive with pg_restore will warn when
restoring a table with oid contents (and ignore the oid column)
- COPY will refuse to load binary dump that includes oids.
- pg_upgrade will error out when encountering tables declared WITH
OIDS, they have to be altered to remove the oid column first.
- Functionality to access the oid of the last inserted row (like
plpgsql's RESULT_OID, spi's SPI_lastoid, ...) has been removed.
The syntax for declaring a table WITHOUT OIDS (or WITH (oids = false)
for CREATE TABLE) is still supported. While that requires a bit of
support code, it seems unnecessary to break applications / dumps that
do not use oids, and are explicit about not using them.
The biggest user of WITH OID columns was postgres' catalog. This
commit changes all 'magic' oid columns to be columns that are normally
declared and stored. To reduce unnecessary query breakage all the
newly added columns are still named 'oid', even if a table's column
naming scheme would indicate 'reloid' or such. This obviously
requires adapting a lot code, mostly replacing oid access via
HeapTupleGetOid() with access to the underlying Form_pg_*->oid column.
The bootstrap process now assigns oids for all oid columns in
genbki.pl that do not have an explicit value (starting at the largest
oid previously used), only oids assigned later by oids will be above
FirstBootstrapObjectId. As the oid column now is a normal column the
special bootstrap syntax for oids has been removed.
Oids are not automatically assigned during insertion anymore, all
backend code explicitly assigns oids with GetNewOidWithIndex(). For
the rare case that insertions into the catalog via SQL are called for
the new pg_nextoid() function can be used (which only works on catalog
tables).
The fact that oid columns on system tables are now normal columns
means that they will be included in the set of columns expanded
by * (i.e. SELECT * FROM pg_class will now include the table's oid,
previously it did not). It'd not technically be hard to hide oid
column by default, but that'd mean confusing behavior would either
have to be carried forward forever, or it'd cause breakage down the
line.
While it's not unlikely that further adjustments are needed, the
scope/invasiveness of the patch makes it worthwhile to get merge this
now. It's painful to maintain externally, too complicated to commit
after the code code freeze, and a dependency of a number of other
patches.
Catversion bump, for obvious reasons.
Author: Andres Freund, with contributions by John Naylor
Discussion: https://postgr.es/m/20180930034810.ywp2c7awz7opzcfr@alap3.anarazel.de
2018-11-21 00:36:57 +01:00
|
|
|
CatalogTupleInsert(rel, tup);
|
2011-02-12 14:54:13 +01:00
|
|
|
Assert(OidIsValid(oid));
|
|
|
|
|
2011-03-11 19:20:11 +01:00
|
|
|
/* set up dependencies for the new collation */
|
2011-02-12 14:54:13 +01:00
|
|
|
myself.classId = CollationRelationId;
|
2011-03-11 19:20:11 +01:00
|
|
|
myself.objectId = oid;
|
2011-02-12 14:54:13 +01:00
|
|
|
myself.objectSubId = 0;
|
|
|
|
|
|
|
|
/* create dependency on namespace */
|
|
|
|
referenced.classId = NamespaceRelationId;
|
|
|
|
referenced.objectId = collnamespace;
|
|
|
|
referenced.objectSubId = 0;
|
|
|
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
|
|
|
|
|
|
|
/* create dependency on owner */
|
Remove WITH OIDS support, change oid catalog column visibility.
Previously tables declared WITH OIDS, including a significant fraction
of the catalog tables, stored the oid column not as a normal column,
but as part of the tuple header.
This special column was not shown by default, which was somewhat odd,
as it's often (consider e.g. pg_class.oid) one of the more important
parts of a row. Neither pg_dump nor COPY included the contents of the
oid column by default.
The fact that the oid column was not an ordinary column necessitated a
significant amount of special case code to support oid columns. That
already was painful for the existing, but upcoming work aiming to make
table storage pluggable, would have required expanding and duplicating
that "specialness" significantly.
WITH OIDS has been deprecated since 2005 (commit ff02d0a05280e0).
Remove it.
Removing includes:
- CREATE TABLE and ALTER TABLE syntax for declaring the table to be
WITH OIDS has been removed (WITH (oids[ = true]) will error out)
- pg_dump does not support dumping tables declared WITH OIDS and will
issue a warning when dumping one (and ignore the oid column).
- restoring an pg_dump archive with pg_restore will warn when
restoring a table with oid contents (and ignore the oid column)
- COPY will refuse to load binary dump that includes oids.
- pg_upgrade will error out when encountering tables declared WITH
OIDS, they have to be altered to remove the oid column first.
- Functionality to access the oid of the last inserted row (like
plpgsql's RESULT_OID, spi's SPI_lastoid, ...) has been removed.
The syntax for declaring a table WITHOUT OIDS (or WITH (oids = false)
for CREATE TABLE) is still supported. While that requires a bit of
support code, it seems unnecessary to break applications / dumps that
do not use oids, and are explicit about not using them.
The biggest user of WITH OID columns was postgres' catalog. This
commit changes all 'magic' oid columns to be columns that are normally
declared and stored. To reduce unnecessary query breakage all the
newly added columns are still named 'oid', even if a table's column
naming scheme would indicate 'reloid' or such. This obviously
requires adapting a lot code, mostly replacing oid access via
HeapTupleGetOid() with access to the underlying Form_pg_*->oid column.
The bootstrap process now assigns oids for all oid columns in
genbki.pl that do not have an explicit value (starting at the largest
oid previously used), only oids assigned later by oids will be above
FirstBootstrapObjectId. As the oid column now is a normal column the
special bootstrap syntax for oids has been removed.
Oids are not automatically assigned during insertion anymore, all
backend code explicitly assigns oids with GetNewOidWithIndex(). For
the rare case that insertions into the catalog via SQL are called for
the new pg_nextoid() function can be used (which only works on catalog
tables).
The fact that oid columns on system tables are now normal columns
means that they will be included in the set of columns expanded
by * (i.e. SELECT * FROM pg_class will now include the table's oid,
previously it did not). It'd not technically be hard to hide oid
column by default, but that'd mean confusing behavior would either
have to be carried forward forever, or it'd cause breakage down the
line.
While it's not unlikely that further adjustments are needed, the
scope/invasiveness of the patch makes it worthwhile to get merge this
now. It's painful to maintain externally, too complicated to commit
after the code code freeze, and a dependency of a number of other
patches.
Catversion bump, for obvious reasons.
Author: Andres Freund, with contributions by John Naylor
Discussion: https://postgr.es/m/20180930034810.ywp2c7awz7opzcfr@alap3.anarazel.de
2018-11-21 00:36:57 +01:00
|
|
|
recordDependencyOnOwner(CollationRelationId, oid, collowner);
|
2011-02-12 14:54:13 +01:00
|
|
|
|
|
|
|
/* dependency on extension */
|
2011-07-23 22:59:39 +02:00
|
|
|
recordDependencyOnCurrentExtension(&myself, false);
|
2011-02-12 14:54:13 +01:00
|
|
|
|
|
|
|
/* Post creation hook for new collation */
|
2013-03-07 02:52:06 +01:00
|
|
|
InvokeObjectPostCreateHook(CollationRelationId, oid, 0);
|
2011-02-12 14:54:13 +01:00
|
|
|
|
|
|
|
heap_freetuple(tup);
|
2019-01-21 19:32:19 +01:00
|
|
|
table_close(rel, NoLock);
|
2011-02-12 14:54:13 +01:00
|
|
|
|
|
|
|
return oid;
|
|
|
|
}
|