--- url: "https://use-the-index-luke.com/sql/where-clause" titulek: "Indexing for performance - The WHERE-Clause" h1: "The Where Clause" popis: "How to write efficient WHERE clauses and add the right indexes. Recipes for high performance SQL. Common mistakes and anti-patterns explained." jazyk: "en" kanonicka: "https://use-the-index-luke.com/sql/where-clause" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 05:53:24" znaku: 3927 slov: 514 kodovani: "utf-8" sha256: "95e79c144f26375a1e4c4d1c69ca696fc9e44636bded889ebc055fef48cda202" --- by [Markus Winand](//winand.at/home). # The Where Clause --- The [previous chapter](/sql/anatomy) described the structure of indexes and explained the cause of poor index performance. In the next step we learn how to spot and avoid these problems in SQL statements. We start by looking at the `where` clause. The `where` clause defines the search condition of an SQL statement, and it thus falls into the core functional domain of an index: finding data quickly. Although the `where` clause has a huge impact on performance, it is often phrased carelessly so that the database has to scan a large part of the index. The result: a poorly written `where` clause is the first ingredient of a slow query. This chapter explains how different operators affect index usage and how to make sure that an index is usable for as many queries as possible. The last section shows common anti-patterns and presents alternatives that deliver better performance. ## Contents 1. *[The Equals Operator](/sql/where-clause/the-equals-operator)* — Exact key lookup 1. *[Primary Keys](/sql/where-clause/the-equals-operator/primary-keys)* — Verifying index usage 2. *[Concatenated Keys](/sql/where-clause/the-equals-operator/concatenated-keys)* — Multi-column indexes 3. *[Slow Indexes, Part II](/sql/where-clause/the-equals-operator/slow-indexes-part-ii)* — The first ingredient, revisited 2. *[Functions](/sql/where-clause/functions)* — Using functions in the `where` clause 1. *[Case-Insensitive Search](/sql/where-clause/functions/case-insensitive-search)* — `UPPER` and `LOWER` 2. *[User-Defined Functions](/sql/where-clause/functions/user-defined-functions)* — Limitations of function-based indexes 3. *[Over-Indexing](/sql/where-clause/functions/over-indexing)* — Avoid redundancy 3. *[Bind Variables](/sql/where-clause/bind-parameters)* — For security and performance 4. *[Searching for Ranges](/sql/where-clause/searching-for-ranges)* — Beyond equality 1. *[Greater, Less and `BETWEEN`](/sql/where-clause/searching-for-ranges/greater-less-between-tuning-sql-access-filter-predicates)* — The column order revisited 2. *[Indexing SQL `LIKE` Filters](/sql/where-clause/searching-for-ranges/like-performance-tuning)* — `LIKE` is not for full-text search 3. *[Index Combine](/sql/where-clause/searching-for-ranges/index-merge-performance)* — Why not using one index for every column? 5. *[Partial Indexes](/sql/where-clause/partial-and-filtered-indexes)* — Indexing selected rows 6. *[`NULL` in the Oracle Database](/sql/where-clause/null)* — An important curiosity 1. *[`NULL` in Indexes](/sql/where-clause/null/index)* — Every index is a partial index 2. *[`NOT NULL` Constraints](/sql/where-clause/null/not-null-constraint)* — affect index usage 3. *[Emulating Partial Indexes](/sql/where-clause/null/partial-index)* — using function-based indexing 7. *[Obfuscated Conditions](/sql/where-clause/obfuscation)* — Common anti-patterns 1. *[Dates](/sql/where-clause/obfuscation/dates)* — Pay special attention to `DATE` types 2. *[Numeric Strings](/sql/where-clause/obfuscation/numeric-strings)* — Don’t mix types 3. *[Combining Columns](/sql/where-clause/obfuscation/concatenation)* — use redundant `where` clauses 4. *[Smart Logic](/sql/where-clause/obfuscation/smart-logic)* — The smartest way to make SQL slow 5. *[Math](/sql/where-clause/obfuscation/math)* — Databases don’t solve equations *You can’t learn everything in one day. Subscribe the newsletter via **[E-Mail](https://winand.at/lists)**, **[Bluesky](https://bsky.app/profile/winand.at)** or **[RSS](/blog/feed)** to gradually catch up. Have a look at [modern-⁠sql.com](https://modern-sql.com) as well.* ## About the Author Markus Winand provides insights into SQL and shows how different systems support it at [modern-sql.com](https://modern-sql.com). Previously he made [use-the-index-luke.com](https://use-the-index-luke.com), which is still actively maintained. Markus can be hired as trainer, speaker and consultant via [winand.at](https://winand.at).