public inbox for [email protected]  
help / color / mirror / Atom feed
[PATCH v5] ALTER tbl rewrite loses CLUSTER ON index
34+ messages / 11 participants
[nested] [flat]

* [PATCH v5] ALTER tbl rewrite loses CLUSTER ON index
@ 2020-02-06 09:14  Amit Langote <[email protected]>
  0 siblings, 0 replies; 34+ messages in thread

From: Amit Langote @ 2020-02-06 09:14 UTC (permalink / raw)

---
 src/backend/commands/tablecmds.c          | 39 +++++++++++++++++++++++
 src/test/regress/expected/alter_table.out | 34 ++++++++++++++++++++
 src/test/regress/sql/alter_table.sql      | 16 +++++++++-
 3 files changed, 88 insertions(+), 1 deletion(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 02a7c04fdb..6b2469bd09 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -490,6 +490,7 @@ static void ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId,
 static void RebuildConstraintComment(AlteredTableInfo *tab, int pass,
 									 Oid objid, Relation rel, List *domname,
 									 const char *conname);
+static void PreserveClusterOn(AlteredTableInfo *tab, int pass, Oid indoid);
 static void TryReuseIndex(Oid oldId, IndexStmt *stmt);
 static void TryReuseForeignKey(Oid oldId, Constraint *con);
 static ObjectAddress ATExecAlterColumnGenericOptions(Relation rel, const char *colName,
@@ -11838,6 +11839,9 @@ ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId, char *cmd,
 			newcmd->def = (Node *) stmt;
 			tab->subcmds[AT_PASS_OLD_INDEX] =
 				lappend(tab->subcmds[AT_PASS_OLD_INDEX], newcmd);
+
+			/* Preserve index's indisclustered property, if set. */
+			PreserveClusterOn(tab, AT_PASS_OLD_INDEX, oldId);
 		}
 		else if (IsA(stm, AlterTableStmt))
 		{
@@ -11874,6 +11878,9 @@ ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId, char *cmd,
 											 rel,
 											 NIL,
 											 indstmt->idxname);
+
+					/* Preserve index's indisclustered property, if set. */
+					PreserveClusterOn(tab, AT_PASS_OLD_INDEX, indoid);
 				}
 				else if (cmd->subtype == AT_AddConstraint)
 				{
@@ -11996,6 +12003,38 @@ RebuildConstraintComment(AlteredTableInfo *tab, int pass, Oid objid,
 	tab->subcmds[pass] = lappend(tab->subcmds[pass], newcmd);
 }
 
+/*
+ * For a table's index that is to be recreated due to PostAlterType
+ * processing, preserve its indisclustered property by issuing ALTER TABLE
+ * CLUSTER ON command on the table that will run after the command to recreate
+ * the index.
+ */
+static void
+PreserveClusterOn(AlteredTableInfo *tab, int pass, Oid indoid)
+{
+	HeapTuple	indexTuple;
+	Form_pg_index indexForm;
+
+	Assert(OidIsValid(indoid));
+	Assert(pass == AT_PASS_OLD_INDEX);
+
+	indexTuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(indoid));
+	if (!HeapTupleIsValid(indexTuple))
+		elog(ERROR, "cache lookup failed for index %u", indoid);
+	indexForm = (Form_pg_index) GETSTRUCT(indexTuple);
+
+	if (indexForm->indisclustered)
+	{
+		AlterTableCmd *newcmd = makeNode(AlterTableCmd);
+
+		newcmd->subtype = AT_ClusterOn;
+		newcmd->name = get_rel_name(indoid);
+		tab->subcmds[pass] = lappend(tab->subcmds[pass], newcmd);
+	}
+
+	ReleaseSysCache(indexTuple);
+}
+
 /*
  * Subroutine for ATPostAlterTypeParse().  Calls out to CheckIndexCompatible()
  * for the real analysis, then mutates the IndexStmt based on that verdict.
diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out
index fb6d86a269..a01c6d6ec5 100644
--- a/src/test/regress/expected/alter_table.out
+++ b/src/test/regress/expected/alter_table.out
@@ -4296,3 +4296,37 @@ create trigger xtrig
 update bar1 set a = a + 1;
 INFO:  a=1, b=1
 /* End test case for bug #16242 */
+-- alter type rewrite/rebuild should preserve cluster marking on index
+create table alttype_cluster (a int);
+create index alttype_cluster_a on alttype_cluster (a);
+alter table alttype_cluster cluster on alttype_cluster_a;
+select indisclustered from pg_index where indrelid = 'alttype_cluster'::regclass;
+ indisclustered 
+----------------
+ t
+(1 row)
+
+alter table alttype_cluster alter a type bigint;
+select indisclustered from pg_index where indrelid = 'alttype_cluster'::regclass;
+ indisclustered 
+----------------
+ t
+(1 row)
+
+drop index alttype_cluster_a;
+alter table alttype_cluster add primary key (a);
+alter table alttype_cluster cluster on alttype_cluster_pkey;
+select indisclustered from pg_index where indrelid = 'alttype_cluster'::regclass;
+ indisclustered 
+----------------
+ t
+(1 row)
+
+alter table alttype_cluster alter a type int;
+select indisclustered from pg_index where indrelid = 'alttype_cluster'::regclass;
+ indisclustered 
+----------------
+ t
+(1 row)
+
+drop table alttype_cluster;
diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql
index 3801f19c58..6e9048bbec 100644
--- a/src/test/regress/sql/alter_table.sql
+++ b/src/test/regress/sql/alter_table.sql
@@ -2802,7 +2802,6 @@ drop table at_test_sql_partop;
 drop operator class at_test_sql_partop using btree;
 drop function at_test_sql_partop;
 
-
 /* Test case for bug #16242 */
 
 -- We create a parent and child where the child has missing
@@ -2840,3 +2839,18 @@ create trigger xtrig
 update bar1 set a = a + 1;
 
 /* End test case for bug #16242 */
+
+-- alter type rewrite/rebuild should preserve cluster marking on index
+create table alttype_cluster (a int);
+create index alttype_cluster_a on alttype_cluster (a);
+alter table alttype_cluster cluster on alttype_cluster_a;
+select indisclustered from pg_index where indrelid = 'alttype_cluster'::regclass;
+alter table alttype_cluster alter a type bigint;
+select indisclustered from pg_index where indrelid = 'alttype_cluster'::regclass;
+drop index alttype_cluster_a;
+alter table alttype_cluster add primary key (a);
+alter table alttype_cluster cluster on alttype_cluster_pkey;
+select indisclustered from pg_index where indrelid = 'alttype_cluster'::regclass;
+alter table alttype_cluster alter a type int;
+select indisclustered from pg_index where indrelid = 'alttype_cluster'::regclass;
+drop table alttype_cluster;
-- 
2.17.0


--bg08WKrSYDhXBjb5--





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

* [PATCH v7 1/2] ALTER tbl rewrite loses CLUSTER ON index
@ 2020-03-16 07:01  Amit Langote <[email protected]>
  0 siblings, 0 replies; 34+ messages in thread

From: Amit Langote @ 2020-03-16 07:01 UTC (permalink / raw)

On Fri, Mar 13, 2020 at 2:19 AM Tom Lane <[email protected]> wrote:
> Justin Pryzby <[email protected]> writes:
> > @cfbot: resending with only Amit's 0001, since Michael pushed a variation on
> > 0002.

Thank you for taking a look at it.

> Boy, I really dislike this patch.  ATPostAlterTypeParse is documented as
> using the supplied definition string, and nothing else, to reconstruct
> the index.  This breaks that without even the courtesy of documenting
> the breakage.  Moreover, the reason why it's designed like that is to
> avoid requiring the old index objects to still be accessible.  So I'm
> surprised that this hack works at all.  I don't think it would have
> worked at the time the code was first written, and I think it's imposing
> a constraint we'll have problems with (again?) in future.

Okay, so maybe in the middle of ATPostAlterTypeParse() is not a place
to do it, but don't these arguments apply to
RebuildConstraintComment(), which I based the patch on?

> The right way to fix this is to note the presence of the indisclustered
> flag when we're examining the index earlier, and include a suitable
> command in the definition string.  So probably pg_get_indexdef_string()
> is what needs to change.  It doesn't look like that's used anywhere
> else, so we can just redefine its behavior as needed.

I came across a commit that recently went in:

commit 1cc9c2412cc9a2fbe6a381170097d315fd40ccca
Author: Peter Eisentraut <[email protected]>
Date:   Fri Mar 13 11:28:11 2020 +0100

    Preserve replica identity index across ALTER TABLE rewrite

which fixes something very similar to what we are trying to with this
patch.  The way it's done looks to me very close to what you are
telling.  I have updated the patch to be similar to the above fix.

--
Thank you,
Amit
---
 src/backend/commands/tablecmds.c          | 49 +++++++++++++++++++++++
 src/backend/utils/cache/lsyscache.c       | 23 +++++++++++
 src/include/utils/lsyscache.h             |  1 +
 src/test/regress/expected/alter_table.out | 34 ++++++++++++++++
 src/test/regress/sql/alter_table.sql      | 15 +++++++
 5 files changed, 122 insertions(+)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 8c33b67c1b..73d9392878 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -177,6 +177,7 @@ typedef struct AlteredTableInfo
 	List	   *changedIndexOids;	/* OIDs of indexes to rebuild */
 	List	   *changedIndexDefs;	/* string definitions of same */
 	char	   *replicaIdentityIndex;	/* index to reset as REPLICA IDENTITY */
+	char	   *clusterOnIndex;		/* index to CLUSTER ON */
 } AlteredTableInfo;
 
 /* Struct describing one new constraint to check in Phase 3 scan */
@@ -11579,9 +11580,28 @@ RememberReplicaIdentityForRebuilding(Oid indoid, AlteredTableInfo *tab)
 	tab->replicaIdentityIndex = get_rel_name(indoid);
 }
 
+/*
+ * Subroutine for ATExecAlterColumnType: remember any clustered index.
+ */
+static void
+RememberClusterOnForRebuilding(Oid indoid, AlteredTableInfo *tab)
+{
+	if (!get_index_isclustered(indoid))
+		return;
+
+	if (tab->clusterOnIndex)
+		elog(ERROR, "relation %u has multiple clustered indexes", tab->relid);
+
+	tab->clusterOnIndex = get_rel_name(indoid);
+}
+
 /*
  * Subroutine for ATExecAlterColumnType: remember that a constraint needs
  * to be rebuilt (which we might already know).
+ *
+ * For constraint's index (if any), also remember if it's the table's replica
+ * identity or its clustered index, so that ATPostAlterTypeCleanup() can
+ * queue up commands necessary to restore that property.
  */
 static void
 RememberConstraintForRebuilding(Oid conoid, AlteredTableInfo *tab)
@@ -11604,9 +11624,18 @@ RememberConstraintForRebuilding(Oid conoid, AlteredTableInfo *tab)
 		tab->changedConstraintDefs = lappend(tab->changedConstraintDefs,
 											 defstring);
 
+		/*
+		 * For constraint's index (if any), remember if it's the table's
+		 * replica identity or its clustered index, so that
+		 * ATPostAlterTypeCleanup() can queue up commands necessary to restore
+		 * that property.
+		 */
 		indoid = get_constraint_index(conoid);
 		if (OidIsValid(indoid))
+		{
 			RememberReplicaIdentityForRebuilding(indoid, tab);
+			RememberClusterOnForRebuilding(indoid, tab);
+		}
 	}
 }
 
@@ -11650,7 +11679,13 @@ RememberIndexForRebuilding(Oid indoid, AlteredTableInfo *tab)
 			tab->changedIndexDefs = lappend(tab->changedIndexDefs,
 											defstring);
 
+			/*
+			 * Remember if it's the table's replica identity or its clustered
+			 * index, so that ATPostAlterTypeCleanup() can queue up commands
+			 * necessary to restore that property.
+			 */
 			RememberReplicaIdentityForRebuilding(indoid, tab);
+			RememberClusterOnForRebuilding(indoid, tab);
 		}
 	}
 }
@@ -11777,6 +11812,20 @@ ATPostAlterTypeCleanup(List **wqueue, AlteredTableInfo *tab, LOCKMODE lockmode)
 			lappend(tab->subcmds[AT_PASS_OLD_CONSTR], cmd);
 	}
 
+	/*
+	 * Queue up command to restore clustered index marking
+	 */
+	if (tab->clusterOnIndex)
+	{
+		AlterTableCmd *cmd = makeNode(AlterTableCmd);
+
+		cmd->subtype = AT_ClusterOn;
+		cmd->name = tab->clusterOnIndex;
+
+		/* do it after indexes and constraints */
+		tab->subcmds[AT_PASS_OLD_CONSTR] =
+			lappend(tab->subcmds[AT_PASS_OLD_CONSTR], cmd);
+	}
 	/*
 	 * It should be okay to use DROP_RESTRICT here, since nothing else should
 	 * be depending on these objects.
diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c
index 27bbb58f56..9c5b806c22 100644
--- a/src/backend/utils/cache/lsyscache.c
+++ b/src/backend/utils/cache/lsyscache.c
@@ -3299,3 +3299,26 @@ get_index_isvalid(Oid index_oid)
 
 	return isvalid;
 }
+
+/*
+ * get_index_isclustered
+ *
+ *		Given the index OID, return pg_index.indisclustered.
+ */
+bool
+get_index_isclustered(Oid index_oid)
+{
+	bool		isclustered;
+	HeapTuple	tuple;
+	Form_pg_index rd_index;
+
+	tuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(index_oid));
+	if (!HeapTupleIsValid(tuple))
+		elog(ERROR, "cache lookup failed for index %u", index_oid);
+
+	rd_index = (Form_pg_index) GETSTRUCT(tuple);
+	isclustered = rd_index->indisclustered;
+	ReleaseSysCache(tuple);
+
+	return isclustered;
+}
diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h
index 4e646c55e9..9459c6a94f 100644
--- a/src/include/utils/lsyscache.h
+++ b/src/include/utils/lsyscache.h
@@ -184,6 +184,7 @@ extern Oid	get_range_collation(Oid rangeOid);
 extern Oid	get_index_column_opclass(Oid index_oid, int attno);
 extern bool	get_index_isreplident(Oid index_oid);
 extern bool get_index_isvalid(Oid index_oid);
+extern bool get_index_isclustered(Oid index_oid);
 
 #define type_is_array(typid)  (get_element_type(typid) != InvalidOid)
 /* type_is_array_domain accepts both plain arrays and domains over arrays */
diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out
index fb6d86a269..a01c6d6ec5 100644
--- a/src/test/regress/expected/alter_table.out
+++ b/src/test/regress/expected/alter_table.out
@@ -4296,3 +4296,37 @@ create trigger xtrig
 update bar1 set a = a + 1;
 INFO:  a=1, b=1
 /* End test case for bug #16242 */
+-- alter type rewrite/rebuild should preserve cluster marking on index
+create table alttype_cluster (a int);
+create index alttype_cluster_a on alttype_cluster (a);
+alter table alttype_cluster cluster on alttype_cluster_a;
+select indisclustered from pg_index where indrelid = 'alttype_cluster'::regclass;
+ indisclustered 
+----------------
+ t
+(1 row)
+
+alter table alttype_cluster alter a type bigint;
+select indisclustered from pg_index where indrelid = 'alttype_cluster'::regclass;
+ indisclustered 
+----------------
+ t
+(1 row)
+
+drop index alttype_cluster_a;
+alter table alttype_cluster add primary key (a);
+alter table alttype_cluster cluster on alttype_cluster_pkey;
+select indisclustered from pg_index where indrelid = 'alttype_cluster'::regclass;
+ indisclustered 
+----------------
+ t
+(1 row)
+
+alter table alttype_cluster alter a type int;
+select indisclustered from pg_index where indrelid = 'alttype_cluster'::regclass;
+ indisclustered 
+----------------
+ t
+(1 row)
+
+drop table alttype_cluster;
diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql
index 3801f19c58..4eeec24e58 100644
--- a/src/test/regress/sql/alter_table.sql
+++ b/src/test/regress/sql/alter_table.sql
@@ -2840,3 +2840,18 @@ create trigger xtrig
 update bar1 set a = a + 1;
 
 /* End test case for bug #16242 */
+
+-- alter type rewrite/rebuild should preserve cluster marking on index
+create table alttype_cluster (a int);
+create index alttype_cluster_a on alttype_cluster (a);
+alter table alttype_cluster cluster on alttype_cluster_a;
+select indisclustered from pg_index where indrelid = 'alttype_cluster'::regclass;
+alter table alttype_cluster alter a type bigint;
+select indisclustered from pg_index where indrelid = 'alttype_cluster'::regclass;
+drop index alttype_cluster_a;
+alter table alttype_cluster add primary key (a);
+alter table alttype_cluster cluster on alttype_cluster_pkey;
+select indisclustered from pg_index where indrelid = 'alttype_cluster'::regclass;
+alter table alttype_cluster alter a type int;
+select indisclustered from pg_index where indrelid = 'alttype_cluster'::regclass;
+drop table alttype_cluster;
-- 
2.17.0


--aZoGpuMECXJckB41
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
 filename="v7-0002-Use-get_index_isclustered-in-cluster.c.patch"



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

* Re: Fix incorrect comment reference
@ 2023-01-23 20:19  James Coleman <[email protected]>
  0 siblings, 1 reply; 34+ messages in thread

From: James Coleman @ 2023-01-23 20:19 UTC (permalink / raw)
  To: Robert Haas <[email protected]>; +Cc: pgsql-hackers

On Mon, Jan 23, 2023 at 1:26 PM Robert Haas <[email protected]> wrote:
>
> On Mon, Jan 23, 2023 at 8:31 AM James Coleman <[email protected]> wrote:
> > See the attached for a simple comment fix -- the referenced
> > generate_useful_gather_paths call isn't in grouping_planner it's in
> > apply_scanjoin_target_to_paths.
>
> The intended reading of the comment is not clear. Is it telling you to
> look at grouping_planner because that's where we
> generate_useful_gather_paths, or is it telling you to look there to
> see how we get the final target list together? If it's the former,
> then your fix is correct. If the latter, it's fine as it is.
>
> The real answer is probably that some years ago both things happened
> in that function. We've moved on from there, but I'm still not sure
> what the most useful phrasing of the comment is.

Yeah, almost certainly, and the comments just didn't keep up.

Would you prefer something that notes both that the broader concern is
happening via the grouping_planner() stage but still points to the
proper callsite (so that people don't go looking for that confused)?

James Coleman






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

* Re: Fix incorrect comment reference
@ 2023-01-23 20:41  Robert Haas <[email protected]>
  parent: James Coleman <[email protected]>
  0 siblings, 1 reply; 34+ messages in thread

From: Robert Haas @ 2023-01-23 20:41 UTC (permalink / raw)
  To: James Coleman <[email protected]>; +Cc: pgsql-hackers

On Mon, Jan 23, 2023 at 3:19 PM James Coleman <[email protected]> wrote:
> On Mon, Jan 23, 2023 at 1:26 PM Robert Haas <[email protected]> wrote:
> > On Mon, Jan 23, 2023 at 8:31 AM James Coleman <[email protected]> wrote:
> > > See the attached for a simple comment fix -- the referenced
> > > generate_useful_gather_paths call isn't in grouping_planner it's in
> > > apply_scanjoin_target_to_paths.
> >
> > The intended reading of the comment is not clear. Is it telling you to
> > look at grouping_planner because that's where we
> > generate_useful_gather_paths, or is it telling you to look there to
> > see how we get the final target list together? If it's the former,
> > then your fix is correct. If the latter, it's fine as it is.
> >
> > The real answer is probably that some years ago both things happened
> > in that function. We've moved on from there, but I'm still not sure
> > what the most useful phrasing of the comment is.
>
> Yeah, almost certainly, and the comments just didn't keep up.
>
> Would you prefer something that notes both that the broader concern is
> happening via the grouping_planner() stage but still points to the
> proper callsite (so that people don't go looking for that confused)?

I don't really have a strong view on what the best thing to do is. I
was just pointing out that the comment might not be quite so obviously
wrong as you were supposing.

-- 
Robert Haas
EDB: http://www.enterprisedb.com






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

* Re: Fix incorrect comment reference
@ 2023-01-23 21:07  James Coleman <[email protected]>
  parent: Robert Haas <[email protected]>
  0 siblings, 1 reply; 34+ messages in thread

From: James Coleman @ 2023-01-23 21:07 UTC (permalink / raw)
  To: Robert Haas <[email protected]>; +Cc: pgsql-hackers

On Mon, Jan 23, 2023 at 3:41 PM Robert Haas <[email protected]> wrote:
>
> On Mon, Jan 23, 2023 at 3:19 PM James Coleman <[email protected]> wrote:
> > On Mon, Jan 23, 2023 at 1:26 PM Robert Haas <[email protected]> wrote:
> > > On Mon, Jan 23, 2023 at 8:31 AM James Coleman <[email protected]> wrote:
> > > > See the attached for a simple comment fix -- the referenced
> > > > generate_useful_gather_paths call isn't in grouping_planner it's in
> > > > apply_scanjoin_target_to_paths.
> > >
> > > The intended reading of the comment is not clear. Is it telling you to
> > > look at grouping_planner because that's where we
> > > generate_useful_gather_paths, or is it telling you to look there to
> > > see how we get the final target list together? If it's the former,
> > > then your fix is correct. If the latter, it's fine as it is.
> > >
> > > The real answer is probably that some years ago both things happened
> > > in that function. We've moved on from there, but I'm still not sure
> > > what the most useful phrasing of the comment is.
> >
> > Yeah, almost certainly, and the comments just didn't keep up.
> >
> > Would you prefer something that notes both that the broader concern is
> > happening via the grouping_planner() stage but still points to the
> > proper callsite (so that people don't go looking for that confused)?
>
> I don't really have a strong view on what the best thing to do is. I
> was just pointing out that the comment might not be quite so obviously
> wrong as you were supposing.

"Wrong" is certainly too strong; my apologies.

I'm really just hoping to improve it for future readers to save them
some confusion I had initially reading it.

James Coleman






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

* Re: Fix incorrect comment reference
@ 2023-01-23 23:42  James Coleman <[email protected]>
  parent: James Coleman <[email protected]>
  0 siblings, 1 reply; 34+ messages in thread

From: James Coleman @ 2023-01-23 23:42 UTC (permalink / raw)
  To: Robert Haas <[email protected]>; +Cc: pgsql-hackers

On Mon, Jan 23, 2023 at 4:07 PM James Coleman <[email protected]> wrote:
>
> On Mon, Jan 23, 2023 at 3:41 PM Robert Haas <[email protected]> wrote:
> >
> > On Mon, Jan 23, 2023 at 3:19 PM James Coleman <[email protected]> wrote:
> > > On Mon, Jan 23, 2023 at 1:26 PM Robert Haas <[email protected]> wrote:
> > > > On Mon, Jan 23, 2023 at 8:31 AM James Coleman <[email protected]> wrote:
> > > > > See the attached for a simple comment fix -- the referenced
> > > > > generate_useful_gather_paths call isn't in grouping_planner it's in
> > > > > apply_scanjoin_target_to_paths.
> > > >
> > > > The intended reading of the comment is not clear. Is it telling you to
> > > > look at grouping_planner because that's where we
> > > > generate_useful_gather_paths, or is it telling you to look there to
> > > > see how we get the final target list together? If it's the former,
> > > > then your fix is correct. If the latter, it's fine as it is.
> > > >
> > > > The real answer is probably that some years ago both things happened
> > > > in that function. We've moved on from there, but I'm still not sure
> > > > what the most useful phrasing of the comment is.
> > >
> > > Yeah, almost certainly, and the comments just didn't keep up.
> > >
> > > Would you prefer something that notes both that the broader concern is
> > > happening via the grouping_planner() stage but still points to the
> > > proper callsite (so that people don't go looking for that confused)?
> >
> > I don't really have a strong view on what the best thing to do is. I
> > was just pointing out that the comment might not be quite so obviously
> > wrong as you were supposing.
>
> "Wrong" is certainly too strong; my apologies.
>
> I'm really just hoping to improve it for future readers to save them
> some confusion I had initially reading it.

Updated patch attached.

Thanks,
James Coleman


Attachments:

  [application/octet-stream] v2-0001-Fixup-incorrect-comment.patch (1.0K, ../../CAAaqYe9F6uoMhAr+8rMLwvGzaKaSknPA0Wi3Ehtv8pbSYmJq-Q@mail.gmail.com/2-v2-0001-Fixup-incorrect-comment.patch)
  download | inline diff:
From c2729745c5560fb591d60155868c13b90c0defc7 Mon Sep 17 00:00:00 2001
From: jcoleman <[email protected]>
Date: Mon, 23 Jan 2023 08:27:40 -0500
Subject: [PATCH v2] Fixup incorrect comment

---
 src/backend/optimizer/path/allpaths.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c
index c2fc568dc8..689c2e6da5 100644
--- a/src/backend/optimizer/path/allpaths.c
+++ b/src/backend/optimizer/path/allpaths.c
@@ -3427,7 +3427,8 @@ standard_join_search(PlannerInfo *root, int levels_needed, List *initial_rels)
 			/*
 			 * Except for the topmost scan/join rel, consider gathering
 			 * partial paths.  We'll do the same for the topmost scan/join rel
-			 * once we know the final targetlist (see grouping_planner).
+			 * once we know the final targetlist (see grouping_planner's and
+			 * its call to apply_scanjoin_target_to_paths).
 			 */
 			if (!bms_equal(rel->relids, root->all_baserels))
 				generate_useful_gather_paths(root, rel, false);
-- 
2.32.1 (Apple Git-133)



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

* Re: Fix incorrect comment reference
@ 2023-09-29 18:26  Bruce Momjian <[email protected]>
  parent: James Coleman <[email protected]>
  0 siblings, 1 reply; 34+ messages in thread

From: Bruce Momjian @ 2023-09-29 18:26 UTC (permalink / raw)
  To: James Coleman <[email protected]>; +Cc: Robert Haas <[email protected]>; pgsql-hackers

On Mon, Jan 23, 2023 at 06:42:45PM -0500, James Coleman wrote:
> On Mon, Jan 23, 2023 at 4:07 PM James Coleman <[email protected]> wrote:
> >
> > On Mon, Jan 23, 2023 at 3:41 PM Robert Haas <[email protected]> wrote:
> > >
> > > On Mon, Jan 23, 2023 at 3:19 PM James Coleman <[email protected]> wrote:
> > > > On Mon, Jan 23, 2023 at 1:26 PM Robert Haas <[email protected]> wrote:
> > > > > On Mon, Jan 23, 2023 at 8:31 AM James Coleman <[email protected]> wrote:
> > > > > > See the attached for a simple comment fix -- the referenced
> > > > > > generate_useful_gather_paths call isn't in grouping_planner it's in
> > > > > > apply_scanjoin_target_to_paths.
> > > > >
> > > > > The intended reading of the comment is not clear. Is it telling you to
> > > > > look at grouping_planner because that's where we
> > > > > generate_useful_gather_paths, or is it telling you to look there to
> > > > > see how we get the final target list together? If it's the former,
> > > > > then your fix is correct. If the latter, it's fine as it is.
> > > > >
> > > > > The real answer is probably that some years ago both things happened
> > > > > in that function. We've moved on from there, but I'm still not sure
> > > > > what the most useful phrasing of the comment is.
> > > >
> > > > Yeah, almost certainly, and the comments just didn't keep up.
> > > >
> > > > Would you prefer something that notes both that the broader concern is
> > > > happening via the grouping_planner() stage but still points to the
> > > > proper callsite (so that people don't go looking for that confused)?
> > >
> > > I don't really have a strong view on what the best thing to do is. I
> > > was just pointing out that the comment might not be quite so obviously
> > > wrong as you were supposing.
> >
> > "Wrong" is certainly too strong; my apologies.
> >
> > I'm really just hoping to improve it for future readers to save them
> > some confusion I had initially reading it.
> 
> Updated patch attached.

Patch applied.

-- 
  Bruce Momjian  <[email protected]>        https://momjian.us
  EDB                                      https://enterprisedb.com

  Only you can decide what is important to you.






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

* Re: Fix incorrect comment reference
@ 2023-09-29 18:38  James Coleman <[email protected]>
  parent: Bruce Momjian <[email protected]>
  0 siblings, 0 replies; 34+ messages in thread

From: James Coleman @ 2023-09-29 18:38 UTC (permalink / raw)
  To: Bruce Momjian <[email protected]>; +Cc: Robert Haas <[email protected]>; pgsql-hackers

On Fri, Sep 29, 2023 at 2:26 PM Bruce Momjian <[email protected]> wrote:
>
> On Mon, Jan 23, 2023 at 06:42:45PM -0500, James Coleman wrote:
> > On Mon, Jan 23, 2023 at 4:07 PM James Coleman <[email protected]> wrote:
> > >
> > > On Mon, Jan 23, 2023 at 3:41 PM Robert Haas <[email protected]> wrote:
> > > >
> > > > On Mon, Jan 23, 2023 at 3:19 PM James Coleman <[email protected]> wrote:
> > > > > On Mon, Jan 23, 2023 at 1:26 PM Robert Haas <[email protected]> wrote:
> > > > > > On Mon, Jan 23, 2023 at 8:31 AM James Coleman <[email protected]> wrote:
> > > > > > > See the attached for a simple comment fix -- the referenced
> > > > > > > generate_useful_gather_paths call isn't in grouping_planner it's in
> > > > > > > apply_scanjoin_target_to_paths.
> > > > > >
> > > > > > The intended reading of the comment is not clear. Is it telling you to
> > > > > > look at grouping_planner because that's where we
> > > > > > generate_useful_gather_paths, or is it telling you to look there to
> > > > > > see how we get the final target list together? If it's the former,
> > > > > > then your fix is correct. If the latter, it's fine as it is.
> > > > > >
> > > > > > The real answer is probably that some years ago both things happened
> > > > > > in that function. We've moved on from there, but I'm still not sure
> > > > > > what the most useful phrasing of the comment is.
> > > > >
> > > > > Yeah, almost certainly, and the comments just didn't keep up.
> > > > >
> > > > > Would you prefer something that notes both that the broader concern is
> > > > > happening via the grouping_planner() stage but still points to the
> > > > > proper callsite (so that people don't go looking for that confused)?
> > > >
> > > > I don't really have a strong view on what the best thing to do is. I
> > > > was just pointing out that the comment might not be quite so obviously
> > > > wrong as you were supposing.
> > >
> > > "Wrong" is certainly too strong; my apologies.
> > >
> > > I'm really just hoping to improve it for future readers to save them
> > > some confusion I had initially reading it.
> >
> > Updated patch attached.
>
> Patch applied.

Thanks!

Regards,
James Coleman






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

* [PATCH v25 8/9] Row pattern recognition patch (typedefs.list).
@ 2024-12-21 06:19  Tatsuo Ishii <[email protected]>
  0 siblings, 0 replies; 34+ messages in thread

From: Tatsuo Ishii @ 2024-12-21 06:19 UTC (permalink / raw)

---
 src/tools/pgindent/typedefs.list | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 971a150dbb..bf78e162bc 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1690,6 +1690,7 @@ NamedLWLockTrancheRequest
 NamedTuplestoreScan
 NamedTuplestoreScanState
 NamespaceInfo
+NavigationInfo
 NestLoop
 NestLoopParam
 NestLoopState
@@ -2316,6 +2317,9 @@ RI_CompareKey
 RI_ConstraintInfo
 RI_QueryHashEntry
 RI_QueryKey
+RPCommonSyntax
+RPSkipTo
+RPSubsetItem
 RTEKind
 RTEPermissionInfo
 RWConflict
@@ -2670,6 +2674,7 @@ SimpleStringList
 SimpleStringListCell
 SingleBoundSortItem
 Size
+SkipContext
 SkipPages
 SlabBlock
 SlabContext
@@ -2761,6 +2766,7 @@ StreamStopReason
 String
 StringInfo
 StringInfoData
+StringSet
 StripnullState
 SubLink
 SubLinkType
@@ -3085,6 +3091,7 @@ VarString
 VarStringSortSupport
 Variable
 VariableAssignHook
+VariablePos
 VariableSetKind
 VariableSetStmt
 VariableShowStmt
-- 
2.25.1


----Next_Part(Sat_Dec_21_18_20_04_2024_526)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="v25-0009-Allow-to-print-raw-parse-tree.patch"



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

* [PATCH v25 8/9] Row pattern recognition patch (typedefs.list).
@ 2024-12-21 06:19  Tatsuo Ishii <[email protected]>
  0 siblings, 0 replies; 34+ messages in thread

From: Tatsuo Ishii @ 2024-12-21 06:19 UTC (permalink / raw)

---
 src/tools/pgindent/typedefs.list | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 971a150dbb..bf78e162bc 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1690,6 +1690,7 @@ NamedLWLockTrancheRequest
 NamedTuplestoreScan
 NamedTuplestoreScanState
 NamespaceInfo
+NavigationInfo
 NestLoop
 NestLoopParam
 NestLoopState
@@ -2316,6 +2317,9 @@ RI_CompareKey
 RI_ConstraintInfo
 RI_QueryHashEntry
 RI_QueryKey
+RPCommonSyntax
+RPSkipTo
+RPSubsetItem
 RTEKind
 RTEPermissionInfo
 RWConflict
@@ -2670,6 +2674,7 @@ SimpleStringList
 SimpleStringListCell
 SingleBoundSortItem
 Size
+SkipContext
 SkipPages
 SlabBlock
 SlabContext
@@ -2761,6 +2766,7 @@ StreamStopReason
 String
 StringInfo
 StringInfoData
+StringSet
 StripnullState
 SubLink
 SubLinkType
@@ -3085,6 +3091,7 @@ VarString
 VarStringSortSupport
 Variable
 VariableAssignHook
+VariablePos
 VariableSetKind
 VariableSetStmt
 VariableShowStmt
-- 
2.25.1


----Next_Part(Sat_Dec_21_18_20_04_2024_526)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="v25-0009-Allow-to-print-raw-parse-tree.patch"



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

* [PATCH v25 8/9] Row pattern recognition patch (typedefs.list).
@ 2024-12-21 06:19  Tatsuo Ishii <[email protected]>
  0 siblings, 0 replies; 34+ messages in thread

From: Tatsuo Ishii @ 2024-12-21 06:19 UTC (permalink / raw)

---
 src/tools/pgindent/typedefs.list | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 971a150dbb..bf78e162bc 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1690,6 +1690,7 @@ NamedLWLockTrancheRequest
 NamedTuplestoreScan
 NamedTuplestoreScanState
 NamespaceInfo
+NavigationInfo
 NestLoop
 NestLoopParam
 NestLoopState
@@ -2316,6 +2317,9 @@ RI_CompareKey
 RI_ConstraintInfo
 RI_QueryHashEntry
 RI_QueryKey
+RPCommonSyntax
+RPSkipTo
+RPSubsetItem
 RTEKind
 RTEPermissionInfo
 RWConflict
@@ -2670,6 +2674,7 @@ SimpleStringList
 SimpleStringListCell
 SingleBoundSortItem
 Size
+SkipContext
 SkipPages
 SlabBlock
 SlabContext
@@ -2761,6 +2766,7 @@ StreamStopReason
 String
 StringInfo
 StringInfoData
+StringSet
 StripnullState
 SubLink
 SubLinkType
@@ -3085,6 +3091,7 @@ VarString
 VarStringSortSupport
 Variable
 VariableAssignHook
+VariablePos
 VariableSetKind
 VariableSetStmt
 VariableShowStmt
-- 
2.25.1


----Next_Part(Sat_Dec_21_18_20_04_2024_526)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="v25-0009-Allow-to-print-raw-parse-tree.patch"



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

* [PATCH v26 8/9] Row pattern recognition patch (typedefs.list).
@ 2024-12-30 12:44  Tatsuo Ishii <[email protected]>
  0 siblings, 0 replies; 34+ messages in thread

From: Tatsuo Ishii @ 2024-12-30 12:44 UTC (permalink / raw)

---
 src/tools/pgindent/typedefs.list | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index e1c4f913f8..72906d0fc1 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1691,6 +1691,7 @@ NamedLWLockTrancheRequest
 NamedTuplestoreScan
 NamedTuplestoreScanState
 NamespaceInfo
+NavigationInfo
 NestLoop
 NestLoopParam
 NestLoopState
@@ -2317,6 +2318,9 @@ RI_CompareKey
 RI_ConstraintInfo
 RI_QueryHashEntry
 RI_QueryKey
+RPCommonSyntax
+RPSkipTo
+RPSubsetItem
 RTEKind
 RTEPermissionInfo
 RWConflict
@@ -2673,6 +2677,7 @@ SimpleStringList
 SimpleStringListCell
 SingleBoundSortItem
 Size
+SkipContext
 SkipPages
 SlabBlock
 SlabContext
@@ -2764,6 +2769,7 @@ StreamStopReason
 String
 StringInfo
 StringInfoData
+StringSet
 StripnullState
 SubLink
 SubLinkType
@@ -3088,6 +3094,7 @@ VarString
 VarStringSortSupport
 Variable
 VariableAssignHook
+VariablePos
 VariableSetKind
 VariableSetStmt
 VariableShowStmt
-- 
2.25.1


----Next_Part(Mon_Dec_30_22_37_18_2024_171)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="v26-0009-Allow-to-print-raw-parse-tree.patch"



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

* [PATCH v26 8/9] Row pattern recognition patch (typedefs.list).
@ 2024-12-30 12:44  Tatsuo Ishii <[email protected]>
  0 siblings, 0 replies; 34+ messages in thread

From: Tatsuo Ishii @ 2024-12-30 12:44 UTC (permalink / raw)

---
 src/tools/pgindent/typedefs.list | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index e1c4f913f8..72906d0fc1 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1691,6 +1691,7 @@ NamedLWLockTrancheRequest
 NamedTuplestoreScan
 NamedTuplestoreScanState
 NamespaceInfo
+NavigationInfo
 NestLoop
 NestLoopParam
 NestLoopState
@@ -2317,6 +2318,9 @@ RI_CompareKey
 RI_ConstraintInfo
 RI_QueryHashEntry
 RI_QueryKey
+RPCommonSyntax
+RPSkipTo
+RPSubsetItem
 RTEKind
 RTEPermissionInfo
 RWConflict
@@ -2673,6 +2677,7 @@ SimpleStringList
 SimpleStringListCell
 SingleBoundSortItem
 Size
+SkipContext
 SkipPages
 SlabBlock
 SlabContext
@@ -2764,6 +2769,7 @@ StreamStopReason
 String
 StringInfo
 StringInfoData
+StringSet
 StripnullState
 SubLink
 SubLinkType
@@ -3088,6 +3094,7 @@ VarString
 VarStringSortSupport
 Variable
 VariableAssignHook
+VariablePos
 VariableSetKind
 VariableSetStmt
 VariableShowStmt
-- 
2.25.1


----Next_Part(Mon_Dec_30_22_37_18_2024_171)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="v26-0009-Allow-to-print-raw-parse-tree.patch"



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

* [PATCH v26 8/9] Row pattern recognition patch (typedefs.list).
@ 2024-12-30 12:44  Tatsuo Ishii <[email protected]>
  0 siblings, 0 replies; 34+ messages in thread

From: Tatsuo Ishii @ 2024-12-30 12:44 UTC (permalink / raw)

---
 src/tools/pgindent/typedefs.list | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index e1c4f913f8..72906d0fc1 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1691,6 +1691,7 @@ NamedLWLockTrancheRequest
 NamedTuplestoreScan
 NamedTuplestoreScanState
 NamespaceInfo
+NavigationInfo
 NestLoop
 NestLoopParam
 NestLoopState
@@ -2317,6 +2318,9 @@ RI_CompareKey
 RI_ConstraintInfo
 RI_QueryHashEntry
 RI_QueryKey
+RPCommonSyntax
+RPSkipTo
+RPSubsetItem
 RTEKind
 RTEPermissionInfo
 RWConflict
@@ -2673,6 +2677,7 @@ SimpleStringList
 SimpleStringListCell
 SingleBoundSortItem
 Size
+SkipContext
 SkipPages
 SlabBlock
 SlabContext
@@ -2764,6 +2769,7 @@ StreamStopReason
 String
 StringInfo
 StringInfoData
+StringSet
 StripnullState
 SubLink
 SubLinkType
@@ -3088,6 +3094,7 @@ VarString
 VarStringSortSupport
 Variable
 VariableAssignHook
+VariablePos
 VariableSetKind
 VariableSetStmt
 VariableShowStmt
-- 
2.25.1


----Next_Part(Mon_Dec_30_22_37_18_2024_171)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="v26-0009-Allow-to-print-raw-parse-tree.patch"



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

* [PATCH v27 8/9] Row pattern recognition patch (typedefs.list).
@ 2024-12-30 23:53  Tatsuo Ishii <[email protected]>
  0 siblings, 0 replies; 34+ messages in thread

From: Tatsuo Ishii @ 2024-12-30 23:53 UTC (permalink / raw)

---
 src/tools/pgindent/typedefs.list | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index e1c4f913f8..72906d0fc1 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1691,6 +1691,7 @@ NamedLWLockTrancheRequest
 NamedTuplestoreScan
 NamedTuplestoreScanState
 NamespaceInfo
+NavigationInfo
 NestLoop
 NestLoopParam
 NestLoopState
@@ -2317,6 +2318,9 @@ RI_CompareKey
 RI_ConstraintInfo
 RI_QueryHashEntry
 RI_QueryKey
+RPCommonSyntax
+RPSkipTo
+RPSubsetItem
 RTEKind
 RTEPermissionInfo
 RWConflict
@@ -2673,6 +2677,7 @@ SimpleStringList
 SimpleStringListCell
 SingleBoundSortItem
 Size
+SkipContext
 SkipPages
 SlabBlock
 SlabContext
@@ -2764,6 +2769,7 @@ StreamStopReason
 String
 StringInfo
 StringInfoData
+StringSet
 StripnullState
 SubLink
 SubLinkType
@@ -3088,6 +3094,7 @@ VarString
 VarStringSortSupport
 Variable
 VariableAssignHook
+VariablePos
 VariableSetKind
 VariableSetStmt
 VariableShowStmt
-- 
2.25.1


----Next_Part(Tue_Dec_31_08_57_07_2024_963)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="v27-0009-Allow-to-print-raw-parse-tree.patch"



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

* [PATCH v27 8/9] Row pattern recognition patch (typedefs.list).
@ 2024-12-30 23:53  Tatsuo Ishii <[email protected]>
  0 siblings, 0 replies; 34+ messages in thread

From: Tatsuo Ishii @ 2024-12-30 23:53 UTC (permalink / raw)

---
 src/tools/pgindent/typedefs.list | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index e1c4f913f8..72906d0fc1 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1691,6 +1691,7 @@ NamedLWLockTrancheRequest
 NamedTuplestoreScan
 NamedTuplestoreScanState
 NamespaceInfo
+NavigationInfo
 NestLoop
 NestLoopParam
 NestLoopState
@@ -2317,6 +2318,9 @@ RI_CompareKey
 RI_ConstraintInfo
 RI_QueryHashEntry
 RI_QueryKey
+RPCommonSyntax
+RPSkipTo
+RPSubsetItem
 RTEKind
 RTEPermissionInfo
 RWConflict
@@ -2673,6 +2677,7 @@ SimpleStringList
 SimpleStringListCell
 SingleBoundSortItem
 Size
+SkipContext
 SkipPages
 SlabBlock
 SlabContext
@@ -2764,6 +2769,7 @@ StreamStopReason
 String
 StringInfo
 StringInfoData
+StringSet
 StripnullState
 SubLink
 SubLinkType
@@ -3088,6 +3094,7 @@ VarString
 VarStringSortSupport
 Variable
 VariableAssignHook
+VariablePos
 VariableSetKind
 VariableSetStmt
 VariableShowStmt
-- 
2.25.1


----Next_Part(Tue_Dec_31_08_57_07_2024_963)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="v27-0009-Allow-to-print-raw-parse-tree.patch"



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

* [PATCH v27 8/9] Row pattern recognition patch (typedefs.list).
@ 2024-12-30 23:53  Tatsuo Ishii <[email protected]>
  0 siblings, 0 replies; 34+ messages in thread

From: Tatsuo Ishii @ 2024-12-30 23:53 UTC (permalink / raw)

---
 src/tools/pgindent/typedefs.list | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index e1c4f913f8..72906d0fc1 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1691,6 +1691,7 @@ NamedLWLockTrancheRequest
 NamedTuplestoreScan
 NamedTuplestoreScanState
 NamespaceInfo
+NavigationInfo
 NestLoop
 NestLoopParam
 NestLoopState
@@ -2317,6 +2318,9 @@ RI_CompareKey
 RI_ConstraintInfo
 RI_QueryHashEntry
 RI_QueryKey
+RPCommonSyntax
+RPSkipTo
+RPSubsetItem
 RTEKind
 RTEPermissionInfo
 RWConflict
@@ -2673,6 +2677,7 @@ SimpleStringList
 SimpleStringListCell
 SingleBoundSortItem
 Size
+SkipContext
 SkipPages
 SlabBlock
 SlabContext
@@ -2764,6 +2769,7 @@ StreamStopReason
 String
 StringInfo
 StringInfoData
+StringSet
 StripnullState
 SubLink
 SubLinkType
@@ -3088,6 +3094,7 @@ VarString
 VarStringSortSupport
 Variable
 VariableAssignHook
+VariablePos
 VariableSetKind
 VariableSetStmt
 VariableShowStmt
-- 
2.25.1


----Next_Part(Tue_Dec_31_08_57_07_2024_963)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="v27-0009-Allow-to-print-raw-parse-tree.patch"



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

* Re: Add CASEFOLD() function.
@ 2025-06-17 15:37  Vik Fearing <[email protected]>
  0 siblings, 2 replies; 34+ messages in thread

From: Vik Fearing @ 2025-06-17 15:37 UTC (permalink / raw)
  To: Jeff Davis <[email protected]>; Joe Conway <[email protected]>; Ian Lawrence Barwick <[email protected]>; +Cc: pgsql-hackers; Peter Eisentraut <[email protected]>


On 16/12/2024 18:49, Jeff Davis wrote:
> One question I have is whether we want this function to normalize the
> output.


Yes, we do.


I am sorry that I am so late to the party, but I am currently writing 
the Change Proposal for the SQL Standard for this function.


For <fold> (which includes LOWER() and UPPER()), the text says in 
Section 6.35 GR 7.e:


If the character set of <character factor> is UTF8, UTF16, or UTF32, 
then FR is replaced by
     Case:
         i) If the <search condition> S IS NORMALIZED evaluates to True, 
then NORMALIZE (FR)
         ii) Otherwise, FR.


Here, FR is the result of the function and S is its argument.


It does not appear to me that our LOWER and UPPER functions obey this 
rule, so there is a valid argument that we should continue to ignore it. 
Or, we can say that we have at least one of three compliant.

-- 

Vik Fearing


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

* Re: Add CASEFOLD() function.
@ 2025-06-17 18:14  Jeff Davis <[email protected]>
  parent: Vik Fearing <[email protected]>
  1 sibling, 1 reply; 34+ messages in thread

From: Jeff Davis @ 2025-06-17 18:14 UTC (permalink / raw)
  To: Vik Fearing <[email protected]>; Joe Conway <[email protected]>; Ian Lawrence Barwick <[email protected]>; +Cc: pgsql-hackers; Peter Eisentraut <[email protected]>

On Tue, 2025-06-17 at 17:37 +0200, Vik Fearing wrote:
> If the character set of <character factor> is UTF8, UTF16, or UTF32,
> then FR is replaced by
>      Case:
>          i) If the <search condition> S IS NORMALIZED evaluates to
> True, then NORMALIZE (FR)
>          ii) Otherwise, FR.

I read that as "if the input is normalized, then the output should be
normalized", IOW preserve the normalization. But does it mean "preserve
whatever the input normal form is" or "preserve NFC if the input is
NFC, otherwise the normalization is undefined"?

The above wording seems to mean "preserve NFC if the input is NFC",
because that's what NORMALIZE(FR) does when the normal form is
unspecified.

> It does not appear to me that our LOWER and UPPER functions obey this
> rule,

You are correct:

   WITH s(t) AS
   (SELECT NORMALIZE(U&'\00C1\00DF\0301' COLLATE "en-US-x-icu"))
   SELECT UPPER(t) = NORMALIZE(UPPER(t)) FROM s;
    ?column? 
   ----------
    f

>  so there is a valid argument that we should continue to ignore it.
> Or, we can say that we have at least one of three compliant.

What do other databases do?

Given how costly normalization can be, imposing that on every caller
seems like a bit much. And favoring NFC for the user unconditionally
might not be the best thing. Then again, NFC is good most of the time,
and there are patches to speed up normalization.

I tend to think that a lot of users who want casefolding would also
want normalization, but it's hard to weigh that against the performance
cost. It might not matter outside of a few edge cases, though I'm not
sure exactly how many.

Regards,
	Jeff Davis






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

* Re: Add CASEFOLD() function.
@ 2025-06-18 17:09  Vik Fearing <[email protected]>
  parent: Jeff Davis <[email protected]>
  0 siblings, 1 reply; 34+ messages in thread

From: Vik Fearing @ 2025-06-18 17:09 UTC (permalink / raw)
  To: Jeff Davis <[email protected]>; Joe Conway <[email protected]>; Ian Lawrence Barwick <[email protected]>; +Cc: pgsql-hackers; Peter Eisentraut <[email protected]>


On 17/06/2025 20:14, Jeff Davis wrote:
> On Tue, 2025-06-17 at 17:37 +0200, Vik Fearing wrote:
>> If the character set of <character factor> is UTF8, UTF16, or UTF32,
>> then FR is replaced by
>>       Case:
>>           i) If the <search condition> S IS NORMALIZED evaluates to
>> True, then NORMALIZE (FR)
>>           ii) Otherwise, FR.
> I read that as "if the input is normalized, then the output should be
> normalized", IOW preserve the normalization. But does it mean "preserve
> whatever the input normal form is" or "preserve NFC if the input is
> NFC, otherwise the normalization is undefined"?
>
> The above wording seems to mean "preserve NFC if the input is NFC",
> because that's what NORMALIZE(FR) does when the normal form is
> unspecified.


Yes, and that is also the default for <normalized predicate>.


>> It does not appear to me that our LOWER and UPPER functions obey this
>> rule,
> You are correct:
>
>     WITH s(t) AS
>     (SELECT NORMALIZE(U&'\00C1\00DF\0301' COLLATE "en-US-x-icu"))
>     SELECT UPPER(t) = NORMALIZE(UPPER(t)) FROM s;
>      ?column?
>     ----------
>      f
>
>>   so there is a valid argument that we should continue to ignore it.
>> Or, we can say that we have at least one of three compliant.
> What do other databases do?


I don't know.  I am just pointing out what the Standard says.  I think 
we should either comply, or say that we don't do it for LOWER and UPPER 
so let's keep things implementation-consistent.


> Given how costly normalization can be, imposing that on every caller
> seems like a bit much.


How much does it cost to check for NFC?  I honestly don't know the 
answer to that question, but that is the only case where we need to 
maintain normalization.


> And favoring NFC for the user unconditionally
> might not be the best thing. Then again, NFC is good most of the time,
> and there are patches to speed up normalization.


It's not unconditionally, it's only if the input was NFC.


> I tend to think that a lot of users who want casefolding would also
> want normalization, but it's hard to weigh that against the performance
> cost. It might not matter outside of a few edge cases, though I'm not
> sure exactly how many.


I defer to you and others in the thread to make this decision.

-- 

Vik Fearing








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

* Re: Add CASEFOLD() function.
@ 2025-06-19 02:53  Jeff Davis <[email protected]>
  parent: Vik Fearing <[email protected]>
  0 siblings, 1 reply; 34+ messages in thread

From: Jeff Davis @ 2025-06-19 02:53 UTC (permalink / raw)
  To: Vik Fearing <[email protected]>; Joe Conway <[email protected]>; Ian Lawrence Barwick <[email protected]>; +Cc: pgsql-hackers; Peter Eisentraut <[email protected]>

On Wed, 2025-06-18 at 19:09 +0200, Vik Fearing wrote:
> I don't know.  I am just pointing out what the Standard says.  I
> think 
> we should either comply, or say that we don't do it for LOWER and
> UPPER 
> so let's keep things implementation-consistent.

For the standard, I see two potential philosophies:

I. CASEFOLD() is another variant of LOWER()/UPPER(), and it should
preserve NFC in the same way.

II. CASEFOLD() is not like LOWER()/UPPER(); it returns a semi-opaque
text value that is useful for caseless matching, but should not
ordinarily be used for display or sent to the application (those things
would be allowed, just not encouraged). For normalization, either:
  (A) Follow Unicode Default Caseless Matching (16.0 3.13.5 D144), and
don't require any kind of normalization; or
  (B) Follow Unicode Canonical Caseless Matching (D145), and require
that the input and output are normalized appropriately, but leave the
precise normal form as implementation-defined.


The current implementation could either be seen as philosophy (I) where
we've chosen to ignore the normalization part for the sake of
consistency with LOWER()/UPPER(); or it could be seen as philosophy
(II)(A).

> How much does it cost to check for NFC?  I honestly don't know the 
> answer to that question, but that is the only case where we need to 
> maintain normalization.

I attached a very rough patch and ran a very simple test on strings
averaging 36 bytes in length, all already in NFC and the result is also
NFC. Before the patch, doing a CASEFOLD() on 10M tuples took about 3
seconds, afterward about 8.

There's a patch to optimize some of the normalization paths, which I
haven't had a chance to review yet. So those numbers might come down. 

> 
> It's not unconditionally, it's only if the input was NFC.

Optimizing the case where the input is _not_ NFC seems strange to me.
If we are normalizing the output, I'd say we should just make the
output always NFC. Being more strict, this seems likely to comply with
the eventual standard.

Additionally, if we are normalizing the output, then we should also do
the input fixup for U+0345, which would make the result usable for
Canonical Caseless Matching. Again, this seems likely to comply with
the eventual standard.

> 

So I only see two reasonable implementations:

1. The current CASEFOLD() implementation.

2. Do the input fixup for U+0345 and unconditionally normalize the
output in NFC.

If there's a case to be made for both implementations, we could also
consider having two functions, say, CASEFOLD() for #1 and NCASEFOLD()
for #2. I'm not sure whether we'd want to standardize one or both of
those functions.

And if you think there's likely to be a collision with the standard
that's hard to anticipate and fix now, then we should consider
reverting CASEFOLD() for 18 and wait for more progress on the
standardization. What's the likelihood that the name changes or
something like that?

Regards,
	Jeff Davis



Attachments:

  [text/x-patch] casefold_normalize.diff (1.9K, ../../[email protected]/2-casefold_normalize.diff)
  download | inline diff:
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index 5bd1e01f7e4..12e688acec6 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -79,6 +79,7 @@
 #include "common/int.h"
 #include "common/unicode_case.h"
 #include "common/unicode_category.h"
+#include "common/unicode_norm.h"
 #include "mb/pg_wchar.h"
 #include "nodes/miscnodes.h"
 #include "parser/scansup.h"
@@ -1866,6 +1867,9 @@ str_casefold(const char *buff, size_t nbytes, Oid collid)
 		size_t		dstsize;
 		char	   *dst;
 		size_t		needed;
+		int mblen, i;
+		unsigned char *p;
+		pg_wchar   *decoded;
 
 		/* first try buffer of equal size plus terminating NUL */
 		dstsize = srclen + 1;
@@ -1882,7 +1886,54 @@ str_casefold(const char *buff, size_t nbytes, Oid collid)
 		}
 
 		Assert(dst[needed] == '\0');
-		result = dst;
+
+		/* convert to pg_wchar */
+		mblen = pg_mbstrlen_with_len(dst, needed);
+		decoded = palloc((mblen + 1) * sizeof(pg_wchar));
+		p = (unsigned char *) dst;
+		for (i = 0; i < mblen; i++)
+		{
+			decoded[i] = utf8_to_unicode(p);
+			p += pg_utf_mblen(p);
+		}
+		decoded[i] = (pg_wchar) '\0';
+
+		if (unicode_is_normalized_quickcheck(UNICODE_NFC, decoded) == UNICODE_NORM_QC_YES)
+		{
+			pfree(decoded);
+			result = dst;
+		}
+		else
+		{
+			pg_wchar *normalized;
+			unsigned char *normalized_utf8;
+
+			normalized = unicode_normalize(UNICODE_NFC, decoded);
+			pfree(decoded);
+
+			/* convert back to UTF-8 string */
+			mblen = 0;
+			for (pg_wchar *wp = normalized; *wp; wp++)
+			{
+				unsigned char buf[4];
+
+				unicode_to_utf8(*wp, buf);
+				mblen += pg_utf_mblen(buf);
+			}
+
+			normalized_utf8 = palloc(mblen + 1);
+
+			p = normalized_utf8;
+			for (pg_wchar *wp = normalized; *wp; wp++)
+			{
+				unicode_to_utf8(*wp, p);
+				p += pg_utf_mblen(p);
+			}
+			*p = '\0';
+			pfree(normalized);
+
+			result = (char *) normalized_utf8;
+		}
 	}
 
 	return result;


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

* Re: Add CASEFOLD() function.
@ 2025-06-19 04:03  Thom Brown <[email protected]>
  parent: Jeff Davis <[email protected]>
  0 siblings, 2 replies; 34+ messages in thread

From: Thom Brown @ 2025-06-19 04:03 UTC (permalink / raw)
  To: Jeff Davis <[email protected]>; +Cc: Vik Fearing <[email protected]>; Joe Conway <[email protected]>; Ian Lawrence Barwick <[email protected]>; pgsql-hackers; Peter Eisentraut <[email protected]>

On Thu, 19 Jun 2025, 03:53 Jeff Davis, <[email protected]> wrote:

> On Wed, 2025-06-18 at 19:09 +0200, Vik Fearing wrote:
> > I don't know.  I am just pointing out what the Standard says.  I
> > think
> > we should either comply, or say that we don't do it for LOWER and
> > UPPER
> > so let's keep things implementation-consistent.
>
> For the standard, I see two potential philosophies:
>
> I. CASEFOLD() is another variant of LOWER()/UPPER(), and it should
> preserve NFC in the same way.
>
> II. CASEFOLD() is not like LOWER()/UPPER(); it returns a semi-opaque
> text value that is useful for caseless matching, but should not
> ordinarily be used for display or sent to the application (those things
> would be allowed, just not encouraged). For normalization, either:
>   (A) Follow Unicode Default Caseless Matching (16.0 3.13.5 D144), and
> don't require any kind of normalization; or
>   (B) Follow Unicode Canonical Caseless Matching (D145), and require
> that the input and output are normalized appropriately, but leave the
> precise normal form as implementation-defined.
>
>
> The current implementation could either be seen as philosophy (I) where
> we've chosen to ignore the normalization part for the sake of
> consistency with LOWER()/UPPER(); or it could be seen as philosophy
> (II)(A).
>
> > How much does it cost to check for NFC?  I honestly don't know the
> > answer to that question, but that is the only case where we need to
> > maintain normalization.
>
> I attached a very rough patch and ran a very simple test on strings
> averaging 36 bytes in length, all already in NFC and the result is also
> NFC. Before the patch, doing a CASEFOLD() on 10M tuples took about 3
> seconds, afterward about 8.
>
> There's a patch to optimize some of the normalization paths, which I
> haven't had a chance to review yet. So those numbers might come down.
>
> >
> > It's not unconditionally, it's only if the input was NFC.
>
> Optimizing the case where the input is _not_ NFC seems strange to me.
> If we are normalizing the output, I'd say we should just make the
> output always NFC. Being more strict, this seems likely to comply with
> the eventual standard.
>
> Additionally, if we are normalizing the output, then we should also do
> the input fixup for U+0345, which would make the result usable for
> Canonical Caseless Matching. Again, this seems likely to comply with
> the eventual standard.
>
> >
>
> So I only see two reasonable implementations:
>
> 1. The current CASEFOLD() implementation.
>
> 2. Do the input fixup for U+0345 and unconditionally normalize the
> output in NFC.
>
> If there's a case to be made for both implementations, we could also
> consider having two functions, say, CASEFOLD() for #1 and NCASEFOLD()
> for #2. I'm not sure whether we'd want to standardize one or both of
> those functions.
>
> And if you think there's likely to be a collision with the standard
> that's hard to anticipate and fix now, then we should consider
> reverting CASEFOLD() for 18 and wait for more progress on the
> standardization. What's the likelihood that the name changes or
> something like that?
>

Late to the party, but is there an argument for porting this to the citext
type? Or supplementing the extension with an additional type ("cftext"?
*shrug*). It currently uses lower(), so our current recommendation for
dealing with all unicode characters is to use nondeterministic collations.

Thom

>


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

* Re: Add CASEFOLD() function.
@ 2025-06-19 04:26  Jeff Davis <[email protected]>
  parent: Thom Brown <[email protected]>
  1 sibling, 0 replies; 34+ messages in thread

From: Jeff Davis @ 2025-06-19 04:26 UTC (permalink / raw)
  To: Thom Brown <[email protected]>; +Cc: Vik Fearing <[email protected]>; Joe Conway <[email protected]>; Ian Lawrence Barwick <[email protected]>; pgsql-hackers; Peter Eisentraut <[email protected]>

On Thu, 2025-06-19 at 05:03 +0100, Thom Brown wrote:
> Late to the party, but is there an argument for porting this to the
> citext type? Or supplementing the extension with an additional type
> ("cftext"? *shrug*).

CASEFOLD() addresses a lot of the problems with using LOWER(), so that
sounds like a good idea. I'd be interested to hear from users of
citext.

Regards,
	Jeff Davis






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

* Re: Add CASEFOLD() function.
@ 2025-06-19 14:47  Peter Eisentraut <[email protected]>
  parent: Vik Fearing <[email protected]>
  1 sibling, 1 reply; 34+ messages in thread

From: Peter Eisentraut @ 2025-06-19 14:47 UTC (permalink / raw)
  To: Vik Fearing <[email protected]>; Jeff Davis <[email protected]>; Joe Conway <[email protected]>; Ian Lawrence Barwick <[email protected]>; +Cc: pgsql-hackers

On 17.06.25 17:37, Vik Fearing wrote:
> For <fold> (which includes LOWER() and UPPER()), the text says in 
> Section 6.35 GR 7.e:
> 
> 
> If the character set of <character factor> is UTF8, UTF16, or UTF32, 
> then FR is replaced by
>      Case:
>          i) If the <search condition> S IS NORMALIZED evaluates to True, 
> then NORMALIZE (FR)
>          ii) Otherwise, FR.
> 
> 
> Here, FR is the result of the function and S is its argument.
> 
> 
> It does not appear to me that our LOWER and UPPER functions obey this 
> rule, so there is a valid argument that we should continue to ignore it. 
> Or, we can say that we have at least one of three compliant.

The SQL standard also says in a few other places that normalization 
should be applied, and we do none of those, so this is probably not a 
reason to change CASEFOLD at this point.






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

* Re: Add CASEFOLD() function.
@ 2025-06-19 14:51  Peter Eisentraut <[email protected]>
  parent: Thom Brown <[email protected]>
  1 sibling, 1 reply; 34+ messages in thread

From: Peter Eisentraut @ 2025-06-19 14:51 UTC (permalink / raw)
  To: Thom Brown <[email protected]>; Jeff Davis <[email protected]>; +Cc: Vik Fearing <[email protected]>; Joe Conway <[email protected]>; Ian Lawrence Barwick <[email protected]>; pgsql-hackers

On 19.06.25 06:03, Thom Brown wrote:
> Late to the party, but is there an argument for porting this to the 
> citext type? Or supplementing the extension with an additional type 
> ("cftext"? *shrug*). It currently uses lower(), so our current 
> recommendation for dealing with all unicode characters is to use 
> nondeterministic collations.

What is the motivation for wanting a citext variant instead of using 
nondeterministic collations?






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

* Re: Add CASEFOLD() function.
@ 2025-06-19 15:36  Thom Brown <[email protected]>
  parent: Peter Eisentraut <[email protected]>
  0 siblings, 2 replies; 34+ messages in thread

From: Thom Brown @ 2025-06-19 15:36 UTC (permalink / raw)
  To: Peter Eisentraut <[email protected]>; +Cc: Jeff Davis <[email protected]>; Vik Fearing <[email protected]>; Joe Conway <[email protected]>; Ian Lawrence Barwick <[email protected]>; pgsql-hackers

On Thu, 19 Jun 2025 at 15:51, Peter Eisentraut <[email protected]> wrote:
>
> On 19.06.25 06:03, Thom Brown wrote:
> > Late to the party, but is there an argument for porting this to the
> > citext type? Or supplementing the extension with an additional type
> > ("cftext"? *shrug*). It currently uses lower(), so our current
> > recommendation for dealing with all unicode characters is to use
> > nondeterministic collations.
>
> What is the motivation for wanting a citext variant instead of using
> nondeterministic collations?

Ease of use, perhaps. It seems easier to use:

column_name cftext

rather than:

CREATE COLLATION case_insensitive_collation (
    PROVIDER = icu,
    LOCALE = 'und-u-ks-level2',
    DETERMINISTIC = FALSE
);

column_name text COLLATE case_insensitive_collation

But I see the arguments against it. It creates an unnecessary
dependency on an extension, and if someone wants to ignore both case
and accents, they may resort to using 2 extensions (citext + unaccent)
when none are needed. I guess I don't feel strongly about it either
way.

Thom





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

* Re: Add CASEFOLD() function.
@ 2025-06-19 16:15  Robert Treat <[email protected]>
  parent: Thom Brown <[email protected]>
  1 sibling, 0 replies; 34+ messages in thread

From: Robert Treat @ 2025-06-19 16:15 UTC (permalink / raw)
  To: Thom Brown <[email protected]>; +Cc: Peter Eisentraut <[email protected]>; Jeff Davis <[email protected]>; Vik Fearing <[email protected]>; Joe Conway <[email protected]>; Ian Lawrence Barwick <[email protected]>; pgsql-hackers

On Thu, Jun 19, 2025 at 11:37 AM Thom Brown <[email protected]> wrote:
> On Thu, 19 Jun 2025 at 15:51, Peter Eisentraut <[email protected]> wrote:
> > On 19.06.25 06:03, Thom Brown wrote:
> > > Late to the party, but is there an argument for porting this to the
> > > citext type? Or supplementing the extension with an additional type
> > > ("cftext"? *shrug*). It currently uses lower(), so our current
> > > recommendation for dealing with all unicode characters is to use
> > > nondeterministic collations.
> >
> > What is the motivation for wanting a citext variant instead of using
> > nondeterministic collations?
>
> Ease of use, perhaps. It seems easier to use:
>
> column_name cftext
>
> rather than:
>
> CREATE COLLATION case_insensitive_collation (
>     PROVIDER = icu,
>     LOCALE = 'und-u-ks-level2',
>     DETERMINISTIC = FALSE
> );
>
> column_name text COLLATE case_insensitive_collation
>
> But I see the arguments against it. It creates an unnecessary
> dependency on an extension, and if someone wants to ignore both case
> and accents, they may resort to using 2 extensions (citext + unaccent)
> when none are needed. I guess I don't feel strongly about it either
> way.

Don't forget, if you have a defined insensitive / normalized
collations, you also enable on-the-fly collation based matching, a la
"SELECT 'Å' = 'A' COLLATE ignore_accent_case;" regardless of the
provided collations (which I think is much more common certain in
other databases)

Robert Treat
https://xzilla.net





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

* Re: Add CASEFOLD() function.
@ 2025-06-19 16:21  Vik Fearing <[email protected]>
  parent: Peter Eisentraut <[email protected]>
  0 siblings, 1 reply; 34+ messages in thread

From: Vik Fearing @ 2025-06-19 16:21 UTC (permalink / raw)
  To: Peter Eisentraut <[email protected]>; Jeff Davis <[email protected]>; Joe Conway <[email protected]>; Ian Lawrence Barwick <[email protected]>; +Cc: pgsql-hackers


On 19/06/2025 16:47, Peter Eisentraut wrote:
> On 17.06.25 17:37, Vik Fearing wrote:
>> For <fold> (which includes LOWER() and UPPER()), the text says in 
>> Section 6.35 GR 7.e:
>>
>>
>> If the character set of <character factor> is UTF8, UTF16, or UTF32, 
>> then FR is replaced by
>>      Case:
>>          i) If the <search condition> S IS NORMALIZED evaluates to 
>> True, then NORMALIZE (FR)
>>          ii) Otherwise, FR.
>>
>>
>> Here, FR is the result of the function and S is its argument.
>>
>>
>> It does not appear to me that our LOWER and UPPER functions obey this 
>> rule, so there is a valid argument that we should continue to ignore 
>> it. Or, we can say that we have at least one of three compliant.
>
> The SQL standard also says in a few other places that normalization 
> should be applied, and we do none of those, so this is probably not a 
> reason to change CASEFOLD at this point.
>

Works for me.

-- 

Vik Fearing.






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

* Re: Add CASEFOLD() function.
@ 2025-06-19 16:33  Jeff Davis <[email protected]>
  parent: Thom Brown <[email protected]>
  1 sibling, 2 replies; 34+ messages in thread

From: Jeff Davis @ 2025-06-19 16:33 UTC (permalink / raw)
  To: Thom Brown <[email protected]>; Peter Eisentraut <[email protected]>; +Cc: Vik Fearing <[email protected]>; Joe Conway <[email protected]>; Ian Lawrence Barwick <[email protected]>; pgsql-hackers

On Thu, 2025-06-19 at 16:36 +0100, Thom Brown wrote:
> Ease of use, perhaps. It seems easier to use:
> 
> column_name cftext
> 
> rather than:
> 
> CREATE COLLATION case_insensitive_collation (
>     PROVIDER = icu,
>     LOCALE = 'und-u-ks-level2',
>     DETERMINISTIC = FALSE
> );

We could auto-create such a collation at initdb time for ICU-enabled
builds.

> But I see the arguments against it. It creates an unnecessary
> dependency on an extension, and if someone wants to ignore both case
> and accents, they may resort to using 2 extensions (citext +
> unaccent)
> when none are needed.

There are at least three ways to do case insensitivity (or other kinds
of equivalence):

* Explicit function calls in queries, as well as index and constraint
definitions. E.g. expression index on LOWER(), queries that explicitly
do "LOWER(x) = ..."

* Wrap those function calls up in a separate data type, like citext.

* Non-deterministic collations.

Given that we have collations, which are a way of organizing alternate
behaviors for existing data types, I'm not sure I see the need for
creating an entirely separate data type.

> I guess I don't feel strongly about it either
> way.

Are you a user of citext? I'm genuinely interested in the use cases,
and whether the separate-data-type approach has merits that are missing
in the other approaches.

Regards,
	Jeff Davis






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

* Re: Add CASEFOLD() function.
@ 2025-06-19 16:51  Robert Treat <[email protected]>
  parent: Jeff Davis <[email protected]>
  1 sibling, 0 replies; 34+ messages in thread

From: Robert Treat @ 2025-06-19 16:51 UTC (permalink / raw)
  To: Jeff Davis <[email protected]>; +Cc: Thom Brown <[email protected]>; Peter Eisentraut <[email protected]>; Vik Fearing <[email protected]>; Joe Conway <[email protected]>; Ian Lawrence Barwick <[email protected]>; pgsql-hackers

On Thu, Jun 19, 2025 at 12:33 PM Jeff Davis <[email protected]> wrote:
>
> On Thu, 2025-06-19 at 16:36 +0100, Thom Brown wrote:
> > Ease of use, perhaps. It seems easier to use:
> >
> > column_name cftext
> >
> > rather than:
> >
> > CREATE COLLATION case_insensitive_collation (
> >     PROVIDER = icu,
> >     LOCALE = 'und-u-ks-level2',
> >     DETERMINISTIC = FALSE
> > );
>
> We could auto-create such a collation at initdb time for ICU-enabled
> builds.
>

Providing a generic insensitive/non-deterministic collation by default
would solve a number of different use cases, so +1 on the idea from
me.
And TBH I usually build --without-icu but this would likely cause me
to change that.

> > But I see the arguments against it. It creates an unnecessary
> > dependency on an extension, and if someone wants to ignore both case
> > and accents, they may resort to using 2 extensions (citext +
> > unaccent)
> > when none are needed.
>
> There are at least three ways to do case insensitivity (or other kinds
> of equivalence):
>
> * Explicit function calls in queries, as well as index and constraint
> definitions. E.g. expression index on LOWER(), queries that explicitly
> do "LOWER(x) = ..."
>
> * Wrap those function calls up in a separate data type, like citext.
>
> * Non-deterministic collations.
>
> Given that we have collations, which are a way of organizing alternate
> behaviors for existing data types, I'm not sure I see the need for
> creating an entirely separate data type.
>
> > I guess I don't feel strongly about it either
> > way.
>
> Are you a user of citext? I'm genuinely interested in the use cases,
> and whether the separate-data-type approach has merits that are missing
> in the other approaches.
>

Yeah, I'd be interested to hear if there is some missing bit that
existing users have concerns over; as a former user of citext, it was
a great workaround at the time, but there are "better ways" to handle
those things now (imho).


Robert Treat
https://xzilla.net





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

* Re: Add CASEFOLD() function.
@ 2025-06-19 16:52  Jeff Davis <[email protected]>
  parent: Vik Fearing <[email protected]>
  0 siblings, 0 replies; 34+ messages in thread

From: Jeff Davis @ 2025-06-19 16:52 UTC (permalink / raw)
  To: Vik Fearing <[email protected]>; Peter Eisentraut <[email protected]>; Joe Conway <[email protected]>; Ian Lawrence Barwick <[email protected]>; +Cc: pgsql-hackers

On Thu, 2025-06-19 at 18:21 +0200, Vik Fearing wrote:
> > 
> > The SQL standard also says in a few other places that normalization
> > should be applied, and we do none of those, so this is probably not
> > a 
> > reason to change CASEFOLD at this point.
> > 
> 
> Works for me.

Sounds good. We can document compatibility notes around this point.

If normalization becomes important, we can take the time to work out
the performance implications more carefully, and potentially introduce
an NCASEFOLD() if needed.

Regards,
	Jeff Davis






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

* Re: Add CASEFOLD() function.
@ 2025-06-19 16:59  Thom Brown <[email protected]>
  parent: Jeff Davis <[email protected]>
  1 sibling, 1 reply; 34+ messages in thread

From: Thom Brown @ 2025-06-19 16:59 UTC (permalink / raw)
  To: Jeff Davis <[email protected]>; +Cc: Peter Eisentraut <[email protected]>; Vik Fearing <[email protected]>; Joe Conway <[email protected]>; Ian Lawrence Barwick <[email protected]>; pgsql-hackers

On Thu, 19 Jun 2025, 17:33 Jeff Davis, <[email protected]> wrote:

> On Thu, 2025-06-19 at 16:36 +0100, Thom Brown wrote:
> > Ease of use, perhaps. It seems easier to use:
> >
> > column_name cftext
> >
> > rather than:
> >
> > CREATE COLLATION case_insensitive_collation (
> >     PROVIDER = icu,
> >     LOCALE = 'und-u-ks-level2',
> >     DETERMINISTIC = FALSE
> > );
>
> We could auto-create such a collation at initdb time for ICU-enabled
> builds.
>
> > But I see the arguments against it. It creates an unnecessary
> > dependency on an extension, and if someone wants to ignore both case
> > and accents, they may resort to using 2 extensions (citext +
> > unaccent)
> > when none are needed.
>
> There are at least three ways to do case insensitivity (or other kinds
> of equivalence):
>
> * Explicit function calls in queries, as well as index and constraint
> definitions. E.g. expression index on LOWER(), queries that explicitly
> do "LOWER(x) = ..."
>
> * Wrap those function calls up in a separate data type, like citext.
>
> * Non-deterministic collations.
>
> Given that we have collations, which are a way of organizing alternate
> behaviors for existing data types, I'm not sure I see the need for
> creating an entirely separate data type.
>
> > I guess I don't feel strongly about it either
> > way.
>
> Are you a user of citext? I'm genuinely interested in the use cases,
> and whether the separate-data-type approach has merits that are missing
> in the other approaches.
>

No. But given the options, I would personally choose nondeterministic
collations now that they are available. I just wish they were more
user-friendly as I suspect the majority of people either won't know about
them, or won't know how to use them. But like you say, maybe having a set
of predefined nd-collections would help. As it stands, I'm just bringing up
the consideration of citext in case it has any value, which it doesn't
appear to. In fact it's probably even an argument to begin the process of
deprecation.

Thom

>


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

* Re: Add CASEFOLD() function.
@ 2025-06-19 17:38  David E. Wheeler <[email protected]>
  parent: Thom Brown <[email protected]>
  0 siblings, 1 reply; 34+ messages in thread

From: David E. Wheeler @ 2025-06-19 17:38 UTC (permalink / raw)
  To: Thom Brown <[email protected]>; +Cc: Jeff Davis <[email protected]>; Peter Eisentraut <[email protected]>; Vik Fearing <[email protected]>; Joe Conway <[email protected]>; Ian Lawrence Barwick <[email protected]>; pgsql-hackers

On Jun 19, 2025, at 12:59, Thom Brown <[email protected]> wrote:

> No. But given the options, I would personally choose nondeterministic collations now that they are available. I just wish they were more user-friendly as I suspect the majority of people either won't know about them, or won't know how to use them.

I suspect there are a lot of uses of citext for databases created before nondeterministic collations existed and people are unaware of them or unclear on the migration path from one to the other, let alone implications for any infrastructure they built around cutest (like function signatures and return values). As long as citext conteinues to be maintained there and there’s no super clear path to migrate, I’d bet good money that few would bother to switch.

Best,

David




Attachments:

  [application/pgp-signature] signature.asc (833B, ../../[email protected]/2-signature.asc)
  download

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

* Re: Add CASEFOLD() function.
@ 2025-06-19 18:55  Thom Brown <[email protected]>
  parent: David E. Wheeler <[email protected]>
  0 siblings, 0 replies; 34+ messages in thread

From: Thom Brown @ 2025-06-19 18:55 UTC (permalink / raw)
  To: David E. Wheeler <[email protected]>; +Cc: Jeff Davis <[email protected]>; Peter Eisentraut <[email protected]>; Vik Fearing <[email protected]>; Joe Conway <[email protected]>; Ian Lawrence Barwick <[email protected]>; pgsql-hackers

On Thu, 19 Jun 2025 at 18:39, David E. Wheeler <[email protected]> wrote:
>
> On Jun 19, 2025, at 12:59, Thom Brown <[email protected]> wrote:
>
> > No. But given the options, I would personally choose nondeterministic collations now that they are available. I just wish they were more user-friendly as I suspect the majority of people either won't know about them, or won't know how to use them.
>
> I suspect there are a lot of uses of citext for databases created before nondeterministic collations existed and people are unaware of them or unclear on the migration path from one to the other, let alone implications for any infrastructure they built around cutest (like function signatures and return values). As long as citext conteinues to be maintained there and there’s no super clear path to migrate, I’d bet good money that few would bother to switch.

Maybe the citext doc page should explain how to get unhooked from it.
Something like:

ALTER TABLE mytable
  ALTER COLUMN ci_column
  SET DATA TYPE TEXT COLLATE case_insensitive_collation;

or

CREATE DOMAIN ci_text AS text
  COLLATE case_insensitive_collation;

ALTER TABLE mytable
  ALTER COLUMN ci_column
  SET DATA TYPE ci_text;

And because they're binary-compatible, they should also be free. No
doubt a procedure could do this to every instance in the database,
although I guess it gets trickier when it comes to functions that
accept citext as a parameter type, and other similar examples.

Thom





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


end of thread, other threads:[~2025-06-19 18:55 UTC | newest]

Thread overview: 34+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-02-06 09:14 [PATCH v5] ALTER tbl rewrite loses CLUSTER ON index Amit Langote <[email protected]>
2020-03-16 07:01 [PATCH v7 1/2] ALTER tbl rewrite loses CLUSTER ON index Amit Langote <[email protected]>
2023-01-23 20:19 Re: Fix incorrect comment reference James Coleman <[email protected]>
2023-01-23 20:41 ` Re: Fix incorrect comment reference Robert Haas <[email protected]>
2023-01-23 21:07   ` Re: Fix incorrect comment reference James Coleman <[email protected]>
2023-01-23 23:42     ` Re: Fix incorrect comment reference James Coleman <[email protected]>
2023-09-29 18:26       ` Re: Fix incorrect comment reference Bruce Momjian <[email protected]>
2023-09-29 18:38         ` Re: Fix incorrect comment reference James Coleman <[email protected]>
2024-12-21 06:19 [PATCH v25 8/9] Row pattern recognition patch (typedefs.list). Tatsuo Ishii <[email protected]>
2024-12-21 06:19 [PATCH v25 8/9] Row pattern recognition patch (typedefs.list). Tatsuo Ishii <[email protected]>
2024-12-21 06:19 [PATCH v25 8/9] Row pattern recognition patch (typedefs.list). Tatsuo Ishii <[email protected]>
2024-12-30 12:44 [PATCH v26 8/9] Row pattern recognition patch (typedefs.list). Tatsuo Ishii <[email protected]>
2024-12-30 12:44 [PATCH v26 8/9] Row pattern recognition patch (typedefs.list). Tatsuo Ishii <[email protected]>
2024-12-30 12:44 [PATCH v26 8/9] Row pattern recognition patch (typedefs.list). Tatsuo Ishii <[email protected]>
2024-12-30 23:53 [PATCH v27 8/9] Row pattern recognition patch (typedefs.list). Tatsuo Ishii <[email protected]>
2024-12-30 23:53 [PATCH v27 8/9] Row pattern recognition patch (typedefs.list). Tatsuo Ishii <[email protected]>
2024-12-30 23:53 [PATCH v27 8/9] Row pattern recognition patch (typedefs.list). Tatsuo Ishii <[email protected]>
2025-06-17 15:37 Re: Add CASEFOLD() function. Vik Fearing <[email protected]>
2025-06-17 18:14 ` Re: Add CASEFOLD() function. Jeff Davis <[email protected]>
2025-06-18 17:09   ` Re: Add CASEFOLD() function. Vik Fearing <[email protected]>
2025-06-19 02:53     ` Re: Add CASEFOLD() function. Jeff Davis <[email protected]>
2025-06-19 04:03       ` Re: Add CASEFOLD() function. Thom Brown <[email protected]>
2025-06-19 04:26         ` Re: Add CASEFOLD() function. Jeff Davis <[email protected]>
2025-06-19 14:51         ` Re: Add CASEFOLD() function. Peter Eisentraut <[email protected]>
2025-06-19 15:36           ` Re: Add CASEFOLD() function. Thom Brown <[email protected]>
2025-06-19 16:15             ` Re: Add CASEFOLD() function. Robert Treat <[email protected]>
2025-06-19 16:33             ` Re: Add CASEFOLD() function. Jeff Davis <[email protected]>
2025-06-19 16:51               ` Re: Add CASEFOLD() function. Robert Treat <[email protected]>
2025-06-19 16:59               ` Re: Add CASEFOLD() function. Thom Brown <[email protected]>
2025-06-19 17:38                 ` Re: Add CASEFOLD() function. David E. Wheeler <[email protected]>
2025-06-19 18:55                   ` Re: Add CASEFOLD() function. Thom Brown <[email protected]>
2025-06-19 14:47 ` Re: Add CASEFOLD() function. Peter Eisentraut <[email protected]>
2025-06-19 16:21   ` Re: Add CASEFOLD() function. Vik Fearing <[email protected]>
2025-06-19 16:52     ` Re: Add CASEFOLD() function. Jeff Davis <[email protected]>

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