Skip to content

Support BETWEEN SYMMETRIC and explicit ASYMMETRIC#106057

Open
BITree2004 wants to merge 1 commit into
ClickHouse:masterfrom
BITree2004:fix-between-symmetric-105955
Open

Support BETWEEN SYMMETRIC and explicit ASYMMETRIC#106057
BITree2004 wants to merge 1 commit into
ClickHouse:masterfrom
BITree2004:fix-between-symmetric-105955

Conversation

@BITree2004
Copy link
Copy Markdown

Closes #105955.

Summary

This PR adds parser support for PostgreSQL-style BETWEEN qualifiers:

  • BETWEEN ASYMMETRIC as an explicit no-op qualifier for existing BETWEEN behavior.
  • NOT BETWEEN ASYMMETRIC as an explicit no-op qualifier for existing NOT BETWEEN behavior.
  • BETWEEN SYMMETRIC, which checks an inclusive range regardless of endpoint order.
  • NOT BETWEEN SYMMETRIC, which checks values outside that unordered inclusive range.

Implementation

The symmetric form is lowered through ordinary comparison operators:

(a >= b AND a <= c) OR (a >= c AND a <= b)

and for NOT BETWEEN SYMMETRIC:

(a < b OR a > c) AND (a < c OR a > b)

This avoids rewriting through least() / greatest(), because in ClickHouse their NULL behavior depends on least_greatest_legacy_null_behavior.

The change also updates:

  • the C++ expression parser;
  • ANTLR grammar files;
  • SQL playground keyword highlighting;
  • SQL reference docs;
  • stateless regression tests;
  • formatting consistency coverage.

Compatibility note

SYMMETRIC and ASYMMETRIC are parsed as contextual range qualifiers immediately after BETWEEN or NOT BETWEEN.

If a column with one of these names is used as the lower bound in that position, it must be quoted:

SELECT x BETWEEN `symmetric` AND y FROM t;

Testing

Built and tested locally with Clang 21.1.6:

PATH=/home/bitree/repo/toolchains/LLVM-21.1.6-Linux-X64/bin:$PATH \
  ninja -C build-pr-clang21 -j6 clickhouse

The build completed successfully and linked build-pr-clang21/programs/clickhouse.

For the local build, Rust, HDFS, ISA-L, and embedded LLVM/JIT/DWARF/BLAKE3 were disabled because those optional components required missing local tools or were not needed for this parser/stateless validation.

Manually checked parser/runtime behavior:

build-pr-clang21/programs/clickhouse local -q \
  "SELECT 2 BETWEEN SYMMETRIC 3 AND 1, 2 NOT BETWEEN SYMMETRIC 3 AND 1, 2 BETWEEN ASYMMETRIC 3 AND 1"

Result:

1	0	0

Ran the relevant stateless tests against a local server started from the same binary:

tests/clickhouse-test -b build-pr-clang21/programs/clickhouse --no-zookeeper --no-shard --timeout 60 04278_between_symmetric
tests/clickhouse-test -b build-pr-clang21/programs/clickhouse --no-zookeeper --no-shard --timeout 60 03920_formatting_consistency

Both tests passed.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 28, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support BETWEEN SYMMETRIC (and the explicit ASYMMETRIC keyword)

2 participants