This is an automated email from the ASF dual-hosted git repository.

leborchuk pushed a commit to branch REL_2_STABLE
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit fb971850bce7ca85fc0e922e6551714eaf03ba2c
Author: Peter Eisentraut <[email protected]>
AuthorDate: Fri Dec 1 15:48:06 2023 +0100

    Check collation when creating partitioned index
    
    When creating a partitioned index, the partition key must be a subset
    of the index's columns.  But this currently doesn't check that the
    collations between the partition key and the index definition match.
    So you can construct a unique index that fails to enforce uniqueness.
    (This would most likely involve a nondeterministic collation, so it
    would have to be crafted explicitly and is not something that would
    just happen by accident.)
    
    This patch adds the required collation check.  As a result, any
    previously allowed unique index that has a collation mismatch would no
    longer be allowed to be created.
    
    Reviewed-by: Tom Lane <[email protected]>
    Discussion: 
https://www.postgresql.org/message-id/flat/3327cb54-f7f1-413b-8fdb-7a9dceebb938%40eisentraut.org
    (cherry picked from commit e846fc491923a499a6d8b388292798fc808cd7a3)
---
 src/backend/commands/indexcmds.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 0a6df42bce9..0fa8a961f0b 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -1379,10 +1379,13 @@ DefineIndex(Oid relationId,
                        {
                                if (key->partattrs[i] == 
indexInfo->ii_IndexAttrNumbers[j])
                                {
-                                       /* Matched the column, now what about 
the equality op? */
+                                       /* Matched the column, now what about 
the collation and equality op? */
                                        Oid                     idx_opfamily;
                                        Oid                     idx_opcintype;
 
+                                       if (key->partcollation[i] != 
collationObjectId[j])
+                                               continue;
+
                                        if 
(get_opclass_opfamily_and_input_type(classObjectId[j],
                                                                                
                                        &idx_opfamily,
                                                                                
                                        &idx_opcintype))


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to