From: aaron-congo (@aaron-congo) <noreply+aaron-congo@github.com>
To: aws/aws-advanced-jdbc-wrapper <noreply+aws-aws-advanced-jdbc-wrapper@github.com>
Subject: Re: [aws/aws-advanced-jdbc-wrapper] PR #2261: fix: use the built-in equality operator in KMS metadata and key SQL on PostgreSQL
Date: Thu, 19 Nov 2026 21:27:23 +0000
Message-ID: <gh-aws-aws-advanced-jdbc-wrapper-2261-rc4635341636@github.com> (raw)
In-Reply-To: <gh-aws-aws-advanced-jdbc-wrapper-2261-rc4634140129@github.com>
References: <gh-aws-aws-advanced-jdbc-wrapper-2261@github.com>
<gh-aws-aws-advanced-jdbc-wrapper-2261-rc4634140129@github.com>
(on wrapper/src/main/java/software/amazon/jdbc/plugin/encryption/key/KeyManagementUtility.java:262)
Good catch - yes, it should. I've updated it so the re-encryption SQL qualifies the primary key comparisons too: the page query now uses `pk OPERATOR(pg_catalog.>) ?` and the update uses `pk OPERATOR(pg_catalog.=) ?`, alongside the value column check that was already qualified.
The catch is that the primary key can be any type the application chose, and forcing the pg_catalog operators isn't safe for every type. For `citext`, it would quietly cast to `text` and compare case-sensitively, while `ORDER BY pk` still sorts case-insensitively, so keyset paging could skip rows. For a custom type with no cast to a built-in type, the query would just fail. So on PostgreSQL, `rotateDataKeyAndReencrypt()` and `reencryptRemainingRows()` now check the primary key column's type before changing anything, and refuse with a clear error if it isn't a built-in type (a domain over a built-in type is fine). MySQL is unchanged.
This only affects those two re-encryption methods. Normal reads and writes, with or without the KMS plugin, work with any primary key type. I added a line in the plugin docs about the requirement.