Skip to content

SQL DDL normalises its keyword arguments with the JVM default locale, so on a Turkish-locale server COLLATE ci silently builds a CASE-SENSITIVE index and NULL_STRATEGY index is rejected outright #7900

Closed

Description

@rspereiratech

Summary

Several SQL DDL statements normalise a keyword argument with the no-argument String.toUpperCase(),
which uses the JVM default locale. In the Turkish, Azeri and Lithuanian locales 'i' uppercases to
the dotted 'İ' (U+0130), not to 'I', so a keyword the user wrote in lower case no longer matches
the constant it is compared against.

Two live consequences, both reproduced on the same binary with nothing changed but -Duser.language:

  1. Silent, permanent loss of case-insensitivity. CreateIndexStatement.executeDDL() builds the
    collation list with prop.collate.getStringValue().toUpperCase(), and IndexMetadata recognises
    case-insensitivity by COLLATION_CI.equals(...) against the literal "CI". Under tr_TR
    "ci".toUpperCase() is "Cİ", which never matches, so CREATE INDEX ... (n COLLATE ci) UNIQUE
    produces an ordinary case-SENSITIVE index. No warning, no error. The unique constraint stops
    rejecting 'alpha' next to 'Alpha', and WHERE n = 'ALPHA' answers zero rows. Worse, the
    collation list is what gets persisted (IndexMetadata reads/writes the collations JSON array),
    so the "Cİ" is written into the schema and the index stays case-sensitive even after the
    database is moved to a server with a normal locale.
  2. A DDL statement that cannot be run at all. SQLASTBuilder does
    NULL_STRATEGY.valueOf(nsId.getValue().toUpperCase()), so NULL_STRATEGY index fails with a raw
    IllegalArgumentException: No enum constant ... NULL_STRATEGY.İNDEX.

Both work when the keyword is typed in upper case, which is why this hides: COLLATE CI and
NULL_STRATEGY INDEX are fine, COLLATE ci and NULL_STRATEGY index are not, and SQL keywords are
otherwise case-insensitive everywhere in this dialect.

Where (HEAD 06b033d)

engine/src/main/java/com/arcadedb/query/sql/parser/CreateIndexStatement.java:363

    // Pass collation settings (e.g., CI for case-insensitive)
    final List<String> collations = new ArrayList<>();
    for (final Property prop : propertyList)
      collations.add(prop.collate != null ? prop.collate.getStringValue().toUpperCase() : "DEFAULT");
    builder.withCollations(collations);

read back by engine/src/main/java/com/arcadedb/schema/IndexMetadata.java:339

  public boolean isCaseInsensitive(final int propertyIndex) {
    return collations != null && propertyIndex < collations.size()
        && COLLATION_CI.equals(collations.get(propertyIndex));
  }

where engine/src/main/java/com/arcadedb/schema/IndexMetadata.java:34 is
public static final String COLLATION_CI = "CI";, and persisted at
engine/src/main/java/com/arcadedb/schema/IndexMetadata.java:116

    final JSONArray collationsJSON = metadata.getJSONArray("collations", null);
    if (collationsJSON != null)
      collations = collationsJSON.toListOfStrings();

engine/src/main/java/com/arcadedb/query/sql/antlr/SQLASTBuilder.java:6011 and :6100

        stmt.nullStrategy = LSMTreeIndexAbstract.NULL_STRATEGY.valueOf(nsId.getValue().toUpperCase());

against engine/src/main/java/com/arcadedb/index/lsm/LSMTreeIndexAbstract.java:67

  public enum NULL_STRATEGY {ERROR, SKIP, INDEX}

The same no-locale toUpperCase() guards other enum-valued DDL keywords whose constants contain an
I, so they are the same defect waiting for a user who types lower case:
LSMVectorIndexMetadata.java:251 (VectorSimilarityFunction.valueOf, e.g. cosine),
LSMVectorIndexMetadata.java:295 (VectorQuantizationType.valueOf, e.g. binary),
GeoIndexMetadata.java:157 and :181 (TOKENIZATION.valueOf),
CreateTriggerStatement.java:79/:140 (Trigger.TriggerEvent.valueOf, e.g. insert),
CreateGraphAnalyticalViewStatement.java:146 (UpdateMode.valueOf),
FullTextIndexMetadata.java:535 (similarity, e.g. tfidf),
LSMSparseVectorIndexMetadata.java:75/:133/:147 (modifier).

Repro

One program, one jar, run twice with only the locale system properties changed. Two document types,
each with a UNIQUE index declared COLLATE ci (lower case) and COLLATE CI (upper case), then
'Alpha' and 'alpha' inserted into each.

=== en-US ===
>>> locale = en_US
>>> OK   | CREATE INDEX ON A (n collate ci) unique
>>> OK   | insert A 'Alpha'
>>> FAIL | insert A 'alpha' => DuplicatedKeyException
>>> OK   | SELECT count(*) as c FROM A => rows=1
>>> OK   | SELECT FROM A WHERE n = 'ALPHA' => rows=1
>>> OK   | CREATE INDEX ON B (n collate CI) unique
>>> OK   | insert B 'Alpha'
>>> FAIL | insert B 'alpha' => DuplicatedKeyException
>>> OK   | SELECT FROM B WHERE n = 'ALPHA' => rows=1

=== tr-TR ===
>>> locale = tr_TR
>>> OK   | CREATE INDEX ON A (n collate ci) unique
>>> OK   | insert A 'Alpha'
>>> OK   | insert A 'alpha'          <-- the UNIQUE constraint no longer fires
>>> OK   | SELECT count(*) as c FROM A => rows=1
>>> OK   | SELECT FROM A WHERE n = 'ALPHA' => rows=0    <-- was 1 on en_US
>>> OK   | CREATE INDEX ON B (n collate CI) unique
>>> OK   | insert B 'Alpha'
>>> FAIL | insert B 'alpha' => DuplicatedKeyException   <-- upper case still works
>>> OK   | SELECT FROM B WHERE n = 'ALPHA' => rows=1

and for the null strategy, same two runs:

=== en-US ===
>>> OK   | CREATE INDEX ON Doc (other) notunique null_strategy index
=== tr-TR ===
>>> FAIL | CREATE INDEX ON Doc (other) notunique null_strategy index
           => IllegalArgumentException: No enum constant com.arcadedb.index.lsm.LSMTreeIndexAbstract.NULL_STRATEGY.İNDEX

(the rows= figures are result-set row counts, so the count(*) lines read 1 in both runs simply
because an aggregate returns one row; the lines that carry the finding are the second insert A,
which succeeds only under tr_TR, and WHERE n = 'ALPHA', which answers 1 under en_US and 0 under
tr_TR.)

Suggested fix

Pass Locale.ROOT at every one of these sites: getStringValue().toUpperCase(Locale.ROOT) and
valueOf(x.toUpperCase(Locale.ROOT)). Internal keyword normalisation must never use the default
locale; the same rule was already applied to the com.arcadedb.function package and is asserted by
LocaleSensitivityTest. Extend that test class (or add a parser-side sibling) with a tr_TR case
that issues CREATE INDEX ... COLLATE ci, NULL_STRATEGY index and one lower-case vector
similarity, and assert the resulting metadata. A repo-wide ban on the no-argument
toUpperCase()/toLowerCase() in src/main would stop the family coming back: 82 call sites
remain.

Scope / confidence

Reproduced end to end on an embedded database, changing nothing but -Duser.language/-Duser.country.
Rated high because arm 1 is a silent correctness and data-integrity failure - a declared UNIQUE
case-insensitive constraint stops being enforced, duplicate rows are accepted, and indexed lookups
return fewer rows than the same predicate without the index - and because the corrupted collation is
persisted into the schema rather than recomputed at open, so restoring the server locale does not
repair an index already built. It needs a server whose default locale is one of tr/az/lt and a
lower-case keyword, which narrows exposure; it does not depend on the client's locale, only the
server JVM's.

Activity

  1. added
    engine
    on Sep 18, 2026
  2. added this to the 26.10.1 milestone on Sep 18, 2026
  3. added
    in progress
    on Sep 19, 2026
  4. self-assigned this
    on Sep 19, 2026
  5. lvca commented on Sep 19, 2026

    @lvca
    Member

    Fixed in 26.10.1 (#7942).

    CREATE INDEX ... COLLATE ci and NULL_STRATEGY index now behave the same on every server, whatever its system locale. Previously, on a Turkish, Azeri or Lithuanian server the lower-case keyword was not recognised: the index was built case-sensitive with no warning, and because that was written into the schema, moving the database elsewhere did not repair it.

    Two changes:

    • every internal keyword is now matched locale-independently, across the engine and all wire protocols;
    • a collation the engine does not support is now rejected instead of silently stored, so a typo cannot quietly produce the wrong index either.

    An index created by an affected server before this fix stays wrong until you rebuild it (REBUILD INDEX).

    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  6. removed
    in progress
    on Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugenginesql

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions