mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Track collation versions for indexes.
Record the current version of dependent collations in pg_depend when creating or rebuilding an index. When accessing the index later, warn that the index may be corrupted if the current version doesn't match. Thanks to Douglas Doole, Peter Eisentraut, Christoph Berg, Laurenz Albe, Michael Paquier, Robert Haas, Tom Lane and others for very helpful discussion. Author: Thomas Munro <thomas.munro@gmail.com> Author: Julien Rouhaud <rjuju123@gmail.com> Reviewed-by: Peter Eisentraut <peter.eisentraut@2ndquadrant.com> (earlier versions) Discussion: https://postgr.es/m/CAEepm%3D0uEQCpfq_%2BLYFBdArCe4Ot98t1aR4eYiYTe%3DyavQygiQ%40mail.gmail.com
This commit is contained in:
@ -45,6 +45,7 @@
|
||||
|
||||
#include "catalog/pg_am_d.h"
|
||||
#include "catalog/pg_class_d.h"
|
||||
#include "catalog/pg_collation_d.h"
|
||||
#include "common.h"
|
||||
#include "libpq-fe.h"
|
||||
#include "pqexpbuffer.h"
|
||||
@ -820,6 +821,20 @@ static const SchemaQuery Query_for_list_of_statistics = {
|
||||
" (SELECT tgrelid FROM pg_catalog.pg_trigger "\
|
||||
" WHERE pg_catalog.quote_ident(tgname)='%s')"
|
||||
|
||||
/* the silly-looking length condition is just to eat up the current word */
|
||||
#define Query_for_list_of_colls_for_one_index \
|
||||
" SELECT DISTINCT pg_catalog.quote_ident(coll.collname) " \
|
||||
" FROM pg_catalog.pg_depend d, pg_catalog.pg_collation coll, " \
|
||||
" pg_catalog.pg_class c" \
|
||||
" WHERE (%d = pg_catalog.length('%s'))" \
|
||||
" AND d.refclassid = " CppAsString2(CollationRelationId) \
|
||||
" AND d.refobjid = coll.oid " \
|
||||
" AND d.classid = " CppAsString2(RelationRelationId) \
|
||||
" AND d.objid = c.oid " \
|
||||
" AND c.relkind = " CppAsString2(RELKIND_INDEX) \
|
||||
" AND pg_catalog.pg_table_is_visible(c.oid) " \
|
||||
" AND c.relname = '%s'"
|
||||
|
||||
#define Query_for_list_of_ts_configurations \
|
||||
"SELECT pg_catalog.quote_ident(cfgname) FROM pg_catalog.pg_ts_config "\
|
||||
" WHERE substring(pg_catalog.quote_ident(cfgname),1,%d)='%s'"
|
||||
@ -1715,14 +1730,15 @@ psql_completion(const char *text, int start, int end)
|
||||
/* ALTER INDEX <name> */
|
||||
else if (Matches("ALTER", "INDEX", MatchAny))
|
||||
COMPLETE_WITH("ALTER COLUMN", "OWNER TO", "RENAME TO", "SET",
|
||||
"RESET", "ATTACH PARTITION", "DEPENDS", "NO DEPENDS");
|
||||
"RESET", "ATTACH PARTITION", "DEPENDS", "NO DEPENDS",
|
||||
"ALTER COLLATION");
|
||||
else if (Matches("ALTER", "INDEX", MatchAny, "ATTACH"))
|
||||
COMPLETE_WITH("PARTITION");
|
||||
else if (Matches("ALTER", "INDEX", MatchAny, "ATTACH", "PARTITION"))
|
||||
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, NULL);
|
||||
/* ALTER INDEX <name> ALTER */
|
||||
else if (Matches("ALTER", "INDEX", MatchAny, "ALTER"))
|
||||
COMPLETE_WITH("COLUMN");
|
||||
COMPLETE_WITH("COLLATION", "COLUMN");
|
||||
/* ALTER INDEX <name> ALTER COLUMN */
|
||||
else if (Matches("ALTER", "INDEX", MatchAny, "ALTER", "COLUMN"))
|
||||
{
|
||||
@ -1765,6 +1781,15 @@ psql_completion(const char *text, int start, int end)
|
||||
COMPLETE_WITH("ON EXTENSION");
|
||||
else if (Matches("ALTER", "INDEX", MatchAny, "DEPENDS"))
|
||||
COMPLETE_WITH("ON EXTENSION");
|
||||
/* ALTER INDEX <name> ALTER COLLATION */
|
||||
else if (Matches("ALTER", "INDEX", MatchAny, "ALTER", "COLLATION"))
|
||||
{
|
||||
completion_info_charp = prev3_wd;
|
||||
COMPLETE_WITH_QUERY(Query_for_list_of_colls_for_one_index);
|
||||
}
|
||||
/* ALTER INDEX <name> ALTER COLLATION <name> */
|
||||
else if (Matches("ALTER", "INDEX", MatchAny, "ALTER", "COLLATION", MatchAny))
|
||||
COMPLETE_WITH("REFRESH VERSION");
|
||||
|
||||
/* ALTER LANGUAGE <name> */
|
||||
else if (Matches("ALTER", "LANGUAGE", MatchAny))
|
||||
|
Reference in New Issue
Block a user