From 30415ef305cccaf7175f5a4d582e6d51bab52145 Mon Sep 17 00:00:00 2001
From: Rui Zhao <zhaorui126@gmail.com>
Date: Sun, 4 Oct 2026 22:58:28 +0800
Subject: [PATCH 3/3] Exercise ASCII normalization with stored text values

The VALUES-based column case folds to a constant, so it does not
exercise the all-ASCII return path on values fetched from a tuple.
Use a table with short and compressed text values instead.
---
 src/test/regress/expected/unicode.out | 9 +++++++--
 src/test/regress/sql/unicode.sql      | 9 +++++++--
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/test/regress/expected/unicode.out b/src/test/regress/expected/unicode.out
index ea93ad9c945..c19cb43eb03 100644
--- a/src/test/regress/expected/unicode.out
+++ b/src/test/regress/expected/unicode.out
@@ -80,13 +80,18 @@ SELECT normalize('abc') = 'abc' COLLATE "C" AS test_ascii_idem;
  t
 (1 row)
 
-SELECT normalize(val) = val COLLATE "C" AS test_ascii_idem_column
-FROM (VALUES ('abc'::text)) v(val);
+-- Use stored values so this check is not folded to a constant.
+CREATE TABLE unicode_ascii_input (val text);
+INSERT INTO unicode_ascii_input VALUES
+    (''), ('abc'), (repeat('a', 64)), (repeat('b', 5000));
+SELECT bool_and(normalize(val) = val COLLATE "C") AS test_ascii_idem_column
+FROM unicode_ascii_input;
  test_ascii_idem_column 
 ------------------------
  t
 (1 row)
 
+DROP TABLE unicode_ascii_input;
 SELECT "normalize"('abc', 'def');  -- run-time error
 ERROR:  invalid normalization form: def
 SELECT "normalize"('abc', 'NFCx');  -- run-time error
diff --git a/src/test/regress/sql/unicode.sql b/src/test/regress/sql/unicode.sql
index 81e08d99b81..b225701e6c3 100644
--- a/src/test/regress/sql/unicode.sql
+++ b/src/test/regress/sql/unicode.sql
@@ -18,8 +18,13 @@ SELECT normalize(U&'\00E4\24D1c', NFD) = U&'\0061\0308\24D1c' COLLATE "C" AS tes
 SELECT normalize(U&'\0061\0308\24D1c', NFKC) = U&'\00E4bc' COLLATE "C" AS test_nfkc;
 SELECT normalize(U&'\00E4\24D1c', NFKD) = U&'\0061\0308bc' COLLATE "C" AS test_nfkd;
 SELECT normalize('abc') = 'abc' COLLATE "C" AS test_ascii_idem;
-SELECT normalize(val) = val COLLATE "C" AS test_ascii_idem_column
-FROM (VALUES ('abc'::text)) v(val);
+-- Use stored values so this check is not folded to a constant.
+CREATE TABLE unicode_ascii_input (val text);
+INSERT INTO unicode_ascii_input VALUES
+    (''), ('abc'), (repeat('a', 64)), (repeat('b', 5000));
+SELECT bool_and(normalize(val) = val COLLATE "C") AS test_ascii_idem_column
+FROM unicode_ascii_input;
+DROP TABLE unicode_ascii_input;
 
 SELECT "normalize"('abc', 'def');  -- run-time error
 SELECT "normalize"('abc', 'NFCx');  -- run-time error
-- 
2.43.7

