# 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.heavy.ai/sql/data-manipulation-dml/sql-capabilities/likely-unlikely.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
