# LIKELY/UNLIKELY

<table data-header-hidden><thead><tr><th width="150">Expression</th><th>Description</th></tr></thead><tbody><tr><td>Expression</td><td>Description</td></tr><tr><td><code>LIKELY(X)</code></td><td>Provides a hint to the query planner that argument <code>X</code> is a Boolean value that is usually true. The planner can prioritize filters on the value <code>X</code> earlier in the execution cycle and return results more efficiently.</td></tr><tr><td><code>UNLIKELY(X)</code></td><td>Provides a hint to the query planner that argument <code>X</code> is a Boolean value that is usually not true. The planner can prioritize filters on the value <code>X</code> later in the execution cycle and return results more efficiently.</td></tr></tbody></table>

**Usage Notes**

SQL normally assumes that terms in the `WHERE` clause that cannot be used by indices are usually true. If this assumption is incorrect, it could lead to a suboptimal query plan. Use the `LIKELY(X)` and `UNLIKELY(X)` SQL functions to provide hints to the query planner about clause terms that are probably not true, which helps the query planner to select the best possible plan.

Use `LIKELY`/`UNLIKELY` to optimize evaluation of `OR`/`AND` logical expressions. `LIKELY`/`UNLIKELY` causes the left side of an expression to be evaluated first. This allows the right side of the query to be skipped when possible. For example, in the clause `UNLIKELY(A) AND B`, if `A` evaluates to `FALSE`, `B` does not need to be evaluated.

Consider the following:

```sql
SELECT COUNT(*) FROM test WHERE UNLIKELY(x IN (7, 8, 9, 10)) AND y > 42;
```

If `x` is one of the values `7`, `8`, `9`, or `10`, the filter `y > 42` is applied. If `x` is not one of those values, the filter `y > 42` is not applied.
