Column transforms, half-open ranges, and rejected type conversion
When one day of orders is searched with DATE(ord_dt) or >= … <, KDBS uses only the leading column of the index. Only a BETWEEN closed at both ends reads the second column as a range too. Comparing a number with a string column is rejected before execution.
SQL
Situation
A customer support screen finds one customer's orders on a specific date. The query compares only the date with a date function.
Tables
| Table | Column | Type | Description |
|---|---|---|---|
orders | cust_id | int64 | Customer ID |
orders | ord_dt | timestamp | Order date and time |
orders | ord_no | varchar(24) | Order number. A string made only of digits |
| Index | Columns |
|---|---|
orders_x1 | cust_id, ord_dt |
orders_x3 | ord_no |
Orders of customer 101 on 2025-06-27
BEFORE · DATE() comparison
SELECT *
FROM orders
WHERE cust_id = 101
AND DATE(ord_dt) = '2025-06-27'
Run it and look at the step name (IndexProbe, IndexRange) and Buffers.
Approach
1. See how many index columns were used
The leading column cust_id of orders_x1(cust_id, ord_dt) is used with equality. Check whether the second column ord_dt became a range boundary or was used only as a condition that filters the rows found.
2. Strip the function and compare the column as is
DATE(ord_dt) = '2025-06-27' means ord_dt is between 00:00 and 23:59:59 of that day.
3. Close both ends of the range
KDBS reads a window closed at both ends (BETWEEN, or >=/> with <=) as a range. A window with one end < (an open end) is not used as a range when another access path (an index) exists (KDBS SQL reference).
Explanation
DATE() → closed BETWEEN
AFTER · BETWEEN
SELECT *
FROM orders
WHERE cust_id = 101
AND ord_dt BETWEEN '2025-06-27 00:00:00' AND '2025-06-27 23:59:59'
Why it got faster
- Before is
IndexProbe. It reads the whole index segment forcust_id = 101, reads the table row for each of that customer's orders, and filters by computingDATE(ord_dt). Buffers 16. - After is
IndexRange. It reads only from(101, 2025-06-27 00:00:00)to(101, 2025-06-27 23:59:59). Buffers 2 (1 index, 1 row).
TRY · Half-open range (>= … <)
SELECT *
FROM orders
WHERE cust_id = 101
AND ord_dt >= '2025-06-27 00:00:00'
AND ord_dt < '2025-06-28 00:00:00'
>= … <, the standard date range in other DBs, is in KDBS the sameIndexProbeas Before, Buffers 16. A window with an open end is not used as a range.timestampholds microseconds, so using23:59:59as the end can miss values such as23:59:59.5. Values in this sandbox are in whole seconds, so nothing is missed.
No type conversion: finding a string column with a number
TRY · Finding ord_no with a numeric literal
SELECT *
FROM orders
WHERE ord_no = 2025083101946001
- Oracle and SQL Server convert
ord_noto a number to compare, cannot use the index, and read everything (implicit type conversion). KDBS rejects it before execution:column 'ord_no' literal at byte 36: expects a string literal. Instead of a slow query reaching production, an error occurs during development.
TRY · String literal
SELECT *
FROM orders
WHERE ord_no = '2025083101946001'
IndexProbeonorders_x3, Buffers 2.
Key points
- Wrapping an index column in a function makes that column a filter condition instead of a range boundary (common to all DBs).
- KDBS uses only closed windows as index ranges. Write date ranges as
BETWEEN '… 00:00:00' AND '… 23:59:59'. - KDBS has no implicit type conversion. A statement is rejected unless the literal has the same type as the column.