File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed
lib/active_record/connection_adapters
test/cases/adapters/postgresql Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change
1
+ * Stop using ` LOWER() ` for case-insensitive queries on ` citext ` columns
2
+
3
+ Previously, ` LOWER() ` was added for e.g. uniqueness validations with
4
+ ` case_sensitive: false ` .
5
+ It wasn't mentioned in the documentation that the index without ` LOWER() `
6
+ wouldn't be used in this case.
7
+
8
+ * Phil Pirozhkov*
9
+
1
10
* Extract ` #sync_timezone_changes ` method in AbstractMysqlAdapter to enable subclasses
2
11
to sync database timezone changes without overriding ` #raw_execute ` .
3
12
Original file line number Diff line number Diff line change @@ -1031,7 +1031,10 @@ def build_statement_pool
1031
1031
end
1032
1032
1033
1033
def can_perform_case_insensitive_comparison_for? ( column )
1034
- @case_insensitive_cache ||= { }
1034
+ # NOTE: citext is an exception. It is possible to perform a
1035
+ # case-insensitive comparison using `LOWER()`, but it is
1036
+ # unnecessary, as `citext` is case-insensitive by definition.
1037
+ @case_insensitive_cache ||= { "citext" => false }
1035
1038
@case_insensitive_cache . fetch ( column . sql_type ) do
1036
1039
@case_insensitive_cache [ column . sql_type ] = begin
1037
1040
sql = <<~SQL
Original file line number Diff line number Diff line change @@ -71,6 +71,12 @@ def test_select_case_insensitive
71
71
assert_equal "Cased Text" , x . cival
72
72
end
73
73
74
+ def test_case_insensitiveness
75
+ attr = Citext . arel_table [ :cival ]
76
+ comparison = @connection . case_insensitive_comparison ( attr , nil )
77
+ assert_no_match ( /lower/i , comparison . to_sql )
78
+ end
79
+
74
80
def test_schema_dump_with_shorthand
75
81
output = dump_table_schema ( "citexts" )
76
82
assert_match %r[t\. citext "cival"] , output
You can’t perform that action at this time.
0 commit comments