NULL
value is considered to be lower than any value of the type of the column. This means that it is possible to have an index segment with only the NULL values by specifying a first range separator that is smaller than any expected value of that column. (Note: In the case of a string type, the minimal possible value is the empty string ''
.)
orders
table that has an order_status
column.order_status
could have.delivered
and returned
.orders
that don’t have a status, that is, their status is NULL
. Without getting into too much business logic in this artificial example, suppose that scans are likely over order_status
values that are not delivered
or returned
. For example, periodically the application may want to send reminders for orders that are unpaid
. The following definition of the range separators would put the index for rows with order_status
of NULL
, delivered
and returned
into separate index segments that contain only those values:
''
. As explained in above, all the rows that have a NULL order_status
will be indexed in this index segment (and only those rows).
There is a subtle difference between the range separators 'delivered'
and 'delivered '
. The difference is the extra space at the end of the second. The only strings that are greater than or equal to the first but less than the second are those that are exactly 'delivered'
, so only rows with this value as their order_status
will be indexed in this index segment. The same logic holds for 'returned'
and 'returned '
.