Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial indexes #8242

Merged
merged 1 commit into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions _includes/sidebar-data-v20.2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,12 @@
"/${VERSION}/inverted-indexes.html"
]
},
{
"title": "Partial Indexes",
"urls": [
"/${VERSION}/partial-indexes.html"
]
},
{
"title": "Column Families",
"urls": [
Expand Down
167 changes: 86 additions & 81 deletions _includes/v20.2/sql/diagrams/create_index.html

Large diffs are not rendered by default.

58 changes: 33 additions & 25 deletions _includes/v20.2/sql/diagrams/index_def.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div><svg width="1928" height="276">
<div><svg width="1922" height="386">
<polygon points="9 61 1 57 1 65"></polygon>
<polygon points="17 61 9 57 9 65"></polygon>
<rect x="71" y="79" width="74" height="32" rx="10"></rect>
Expand Down Expand Up @@ -50,6 +50,9 @@
<rect x="1281" y="123" width="82" height="32" rx="10"></rect>
<rect x="1279" y="121" width="82" height="32" class="terminal" rx="10"></rect>
<text class="terminal" x="1289" y="141">STORING</text>
<rect x="1281" y="167" width="80" height="32" rx="10"></rect>
<rect x="1279" y="165" width="80" height="32" class="terminal" rx="10"></rect>
<text class="terminal" x="1289" y="185">INCLUDE</text>
<rect x="1413" y="79" width="26" height="32" rx="10"></rect>
<rect x="1411" y="77" width="26" height="32" class="terminal" rx="10"></rect>
<text class="terminal" x="1421" y="97">(</text>
Expand All @@ -71,32 +74,37 @@
<rect x="1755" y="45" width="124" height="32" class="nonterminal"></rect>
<text class="nonterminal" x="1765" y="65">opt_partition_by</text>
</a>
<rect x="51" y="211" width="88" height="32" rx="10"></rect>
<rect x="49" y="209" width="88" height="32" class="terminal" rx="10"></rect>
<text class="terminal" x="59" y="229">INVERTED</text>
<rect x="159" y="211" width="62" height="32" rx="10"></rect>
<rect x="157" y="209" width="62" height="32" class="terminal" rx="10"></rect>
<text class="terminal" x="167" y="229">INDEX</text>
<rect x="51" y="255" width="88" height="32" rx="10"></rect>
<rect x="49" y="253" width="88" height="32" class="terminal" rx="10"></rect>
<text class="terminal" x="59" y="273">INVERTED</text>
<rect x="159" y="255" width="62" height="32" rx="10"></rect>
<rect x="157" y="253" width="62" height="32" class="terminal" rx="10"></rect>
<text class="terminal" x="167" y="273">INDEX</text>
<a xlink:href="sql-grammar.html#name" xlink:title="name">
<rect x="261" y="243" width="54" height="32"></rect>
<rect x="259" y="241" width="54" height="32" class="nonterminal"></rect>
<text class="nonterminal" x="269" y="261">name</text>
<rect x="261" y="287" width="54" height="32"></rect>
<rect x="259" y="285" width="54" height="32" class="nonterminal"></rect>
<text class="nonterminal" x="269" y="305">name</text>
</a>
<rect x="355" y="211" width="26" height="32" rx="10"></rect>
<rect x="353" y="209" width="26" height="32" class="terminal" rx="10"></rect>
<text class="terminal" x="363" y="229">(</text>
<rect x="355" y="255" width="26" height="32" rx="10"></rect>
<rect x="353" y="253" width="26" height="32" class="terminal" rx="10"></rect>
<text class="terminal" x="363" y="273">(</text>
<a xlink:href="sql-grammar.html#index_elem" xlink:title="index_elem">
<rect x="421" y="211" width="92" height="32"></rect>
<rect x="419" y="209" width="92" height="32" class="nonterminal"></rect>
<text class="nonterminal" x="429" y="229">index_elem</text>
<rect x="421" y="255" width="92" height="32"></rect>
<rect x="419" y="253" width="92" height="32" class="nonterminal"></rect>
<text class="nonterminal" x="429" y="273">index_elem</text>
</a>
<rect x="421" y="167" width="24" height="32" rx="10"></rect>
<rect x="419" y="165" width="24" height="32" class="terminal" rx="10"></rect>
<text class="terminal" x="429" y="185">,</text>
<rect x="553" y="211" width="26" height="32" rx="10"></rect>
<rect x="551" y="209" width="26" height="32" class="terminal" rx="10"></rect>
<text class="terminal" x="561" y="229">)</text>
<path class="line" d="m17 61 h2 m40 0 h10 m0 0 h84 m-114 0 h20 m94 0 h20 m-134 0 q10 0 10 10 m114 0 q0 -10 10 -10 m-124 10 v12 m114 0 v-12 m-114 12 q0 10 10 10 m94 0 q10 0 10 -10 m-104 10 h10 m74 0 h10 m20 -32 h10 m62 0 h10 m0 0 h10 m126 0 h10 m0 0 h10 m26 0 h10 m20 0 h10 m92 0 h10 m-132 0 l20 0 m-1 0 q-9 0 -9 -10 l0 -24 q0 -10 10 -10 m112 44 l20 0 m-20 0 q10 0 10 -10 l0 -24 q0 -10 -10 -10 m-112 0 h10 m24 0 h10 m0 0 h68 m20 44 h10 m26 0 h10 m20 0 h10 m0 0 h534 m-564 0 h20 m544 0 h20 m-584 0 q10 0 10 10 m564 0 q0 -10 10 -10 m-574 10 v12 m564 0 v-12 m-564 12 q0 10 10 10 m544 0 q10 0 10 -10 m-554 10 h10 m64 0 h10 m0 0 h10 m58 0 h10 m0 0 h10 m58 0 h10 m0 0 h10 m130 0 h10 m0 0 h10 m30 0 h10 m0 0 h10 m84 0 h10 m40 -32 h10 m0 0 h334 m-364 0 h20 m344 0 h20 m-384 0 q10 0 10 10 m364 0 q0 -10 10 -10 m-374 10 v12 m364 0 v-12 m-364 12 q0 10 10 10 m344 0 q10 0 10 -10 m-334 10 h10 m92 0 h10 m-132 0 h20 m112 0 h20 m-152 0 q10 0 10 10 m132 0 q0 -10 10 -10 m-142 10 v24 m132 0 v-24 m-132 24 q0 10 10 10 m112 0 q10 0 10 -10 m-122 10 h10 m82 0 h10 m0 0 h10 m20 -44 h10 m26 0 h10 m0 0 h10 m80 0 h10 m0 0 h10 m26 0 h10 m20 -32 h10 m112 0 h10 m0 0 h10 m124 0 h10 m-1870 0 h20 m1850 0 h20 m-1890 0 q10 0 10 10 m1870 0 q0 -10 10 -10 m-1880 10 v144 m1870 0 v-144 m-1870 144 q0 10 10 10 m1850 0 q10 0 10 -10 m-1860 10 h10 m88 0 h10 m0 0 h10 m62 0 h10 m20 0 h10 m0 0 h64 m-94 0 h20 m74 0 h20 m-114 0 q10 0 10 10 m94 0 q0 -10 10 -10 m-104 10 v12 m94 0 v-12 m-94 12 q0 10 10 10 m74 0 q10 0 10 -10 m-84 10 h10 m54 0 h10 m20 -32 h10 m26 0 h10 m20 0 h10 m92 0 h10 m-132 0 l20 0 m-1 0 q-9 0 -9 -10 l0 -24 q0 -10 10 -10 m112 44 l20 0 m-20 0 q10 0 10 -10 l0 -24 q0 -10 -10 -10 m-112 0 h10 m24 0 h10 m0 0 h68 m20 44 h10 m26 0 h10 m0 0 h1302 m23 -164 h-3"></path>
<polygon points="1919 61 1927 57 1927 65"></polygon>
<polygon points="1919 61 1911 57 1911 65"></polygon>
<rect x="421" y="211" width="24" height="32" rx="10"></rect>
<rect x="419" y="209" width="24" height="32" class="terminal" rx="10"></rect>
<text class="terminal" x="429" y="229">,</text>
<rect x="553" y="255" width="26" height="32" rx="10"></rect>
<rect x="551" y="253" width="26" height="32" class="terminal" rx="10"></rect>
<text class="terminal" x="561" y="273">)</text>
<a xlink:href="sql-grammar.html#opt_where_clause" xlink:title="opt_where_clause">
<rect x="1759" y="353" width="136" height="32"></rect>
<rect x="1757" y="351" width="136" height="32" class="nonterminal"></rect>
<text class="nonterminal" x="1767" y="371">opt_where_clause</text>
</a>
<path class="line" d="m17 61 h2 m40 0 h10 m0 0 h84 m-114 0 h20 m94 0 h20 m-134 0 q10 0 10 10 m114 0 q0 -10 10 -10 m-124 10 v12 m114 0 v-12 m-114 12 q0 10 10 10 m94 0 q10 0 10 -10 m-104 10 h10 m74 0 h10 m20 -32 h10 m62 0 h10 m0 0 h10 m126 0 h10 m0 0 h10 m26 0 h10 m20 0 h10 m92 0 h10 m-132 0 l20 0 m-1 0 q-9 0 -9 -10 l0 -24 q0 -10 10 -10 m112 44 l20 0 m-20 0 q10 0 10 -10 l0 -24 q0 -10 -10 -10 m-112 0 h10 m24 0 h10 m0 0 h68 m20 44 h10 m26 0 h10 m20 0 h10 m0 0 h534 m-564 0 h20 m544 0 h20 m-584 0 q10 0 10 10 m564 0 q0 -10 10 -10 m-574 10 v12 m564 0 v-12 m-564 12 q0 10 10 10 m544 0 q10 0 10 -10 m-554 10 h10 m64 0 h10 m0 0 h10 m58 0 h10 m0 0 h10 m58 0 h10 m0 0 h10 m130 0 h10 m0 0 h10 m30 0 h10 m0 0 h10 m84 0 h10 m40 -32 h10 m0 0 h334 m-364 0 h20 m344 0 h20 m-384 0 q10 0 10 10 m364 0 q0 -10 10 -10 m-374 10 v12 m364 0 v-12 m-364 12 q0 10 10 10 m344 0 q10 0 10 -10 m-334 10 h10 m92 0 h10 m-132 0 h20 m112 0 h20 m-152 0 q10 0 10 10 m132 0 q0 -10 10 -10 m-142 10 v24 m132 0 v-24 m-132 24 q0 10 10 10 m112 0 q10 0 10 -10 m-122 10 h10 m82 0 h10 m0 0 h10 m-122 -10 v20 m132 0 v-20 m-132 20 v24 m132 0 v-24 m-132 24 q0 10 10 10 m112 0 q10 0 10 -10 m-122 10 h10 m80 0 h10 m0 0 h12 m20 -88 h10 m26 0 h10 m0 0 h10 m80 0 h10 m0 0 h10 m26 0 h10 m20 -32 h10 m112 0 h10 m0 0 h10 m124 0 h10 m-1870 0 h20 m1850 0 h20 m-1890 0 q10 0 10 10 m1870 0 q0 -10 10 -10 m-1880 10 v188 m1870 0 v-188 m-1870 188 q0 10 10 10 m1850 0 q10 0 10 -10 m-1860 10 h10 m88 0 h10 m0 0 h10 m62 0 h10 m20 0 h10 m0 0 h64 m-94 0 h20 m74 0 h20 m-114 0 q10 0 10 10 m94 0 q0 -10 10 -10 m-104 10 v12 m94 0 v-12 m-94 12 q0 10 10 10 m74 0 q10 0 10 -10 m-84 10 h10 m54 0 h10 m20 -32 h10 m26 0 h10 m20 0 h10 m92 0 h10 m-132 0 l20 0 m-1 0 q-9 0 -9 -10 l0 -24 q0 -10 10 -10 m112 44 l20 0 m-20 0 q10 0 10 -10 l0 -24 q0 -10 -10 -10 m-112 0 h10 m24 0 h10 m0 0 h68 m20 44 h10 m26 0 h10 m0 0 h1302 m22 -208 l2 0 m2 0 l2 0 m2 0 l2 0 m-186 306 l2 0 m2 0 l2 0 m2 0 l2 0 m2 0 h10 m136 0 h10 m3 0 h-3"></path>
<polygon points="1913 367 1921 363 1921 371"></polygon>
<polygon points="1913 367 1905 363 1905 371"></polygon>
</svg></div>
3 changes: 2 additions & 1 deletion v20.2/create-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The following types cannot be included in an index key, but can be stored (and u
- [`ARRAY`](array.html)
- The computed [`TUPLE`](scalar-expressions.html#tuple-constructor) type, even if it is constructed from indexed fields

To create an index on the schemaless data in a [`JSONB`](jsonb.html) column, use an [inverted index](inverted-indexes.html).
To create an index on the schemaless data in a [`JSONB`](jsonb.html) column, or on the data in an [`ARRAY`](array.html), use an [inverted index](inverted-indexes.html).

{{site.data.alerts.callout_info}}
Indexes are automatically created for a table's [`PRIMARY KEY`](primary-key.html) and [`UNIQUE`](unique.html) columns. When querying a table, CockroachDB uses the fastest index. For more information about that process, see [Index Selection in CockroachDB](https://www.cockroachlabs.com/blog/index-selection-cockroachdb-2/).
Expand Down Expand Up @@ -49,6 +49,7 @@ Parameter | Description
`STORING ...`| Store (but do not sort) each column whose name you include.<br><br>For information on when to use `STORING`, see [Store Columns](#store-columns). Note that columns that are part of a table's [`PRIMARY KEY`](primary-key.html) cannot be specified as `STORING` columns in secondary indexes on the table.<br><br>`COVERING` and `INCLUDE` are aliases for `STORING` and work identically.
`opt_interleave` | You can potentially optimize query performance by [interleaving indexes](interleave-in-parent.html), which changes how CockroachDB stores your data.<br>{{site.data.alerts.callout_info}}[Hash-sharded indexes](indexes.html#hash-sharded-indexes) cannot be interleaved.{{site.data.alerts.end}}
`opt_partition_by` | An [enterprise-only](enterprise-licensing.html) option that lets you [define index partitions at the row level](partitioning.html).
`opt_where_clause` | <span class="version-tag">New in v20.2:</span> An optional `WHERE` clause that defines the predicate boolean expression of a [partial index](partial-indexes.html).
`USING HASH WITH BUCKET COUNT` | Creates a [hash-sharded index](indexes.html#hash-sharded-indexes) with `n_buckets` number of buckets.<br>{{site.data.alerts.callout_info}}To enable hash-sharded indexes, set the `experimental_enable_hash_sharded_indexes` [session variable](set-vars.html) to `on`.{{site.data.alerts.end}}
`CONCURRENTLY` | Optional, no-op syntax for PostgreSQL compatibility. All indexes are created concurrently in CockroachDB.

Expand Down
1 change: 1 addition & 0 deletions v20.2/create-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Parameter | Description
`LIKE table_name like_table_option_list` | <span class="version-tag">New in v20.2:</span> Create a new table based on the schema of an existing table, using supported specifiers. For details, see [Create a table like an existing table](#create-a-table-like-an-existing-table). For examples, see [Create a new table from an existing one](#create-a-new-table-from-an-existing-one).
`opt_interleave` | You can potentially optimize query performance by [interleaving tables](interleave-in-parent.html), which changes how CockroachDB stores your data.<br>{{site.data.alerts.callout_info}}[Hash-sharded indexes](indexes.html#hash-sharded-indexes) cannot be interleaved.{{site.data.alerts.end}}
`opt_partition_by` | An [enterprise-only](enterprise-licensing.html) option that lets you define table partitions at the row level. You can define table partitions by list or by range. See [Define Table Partitions](partitioning.html) for more information.
`opt_where_clause` | <span class="version-tag">New in v20.2:</span> An optional `WHERE` clause that defines the predicate boolean expression of a [partial index](partial-indexes.html).

## Table-level replication

Expand Down
2 changes: 2 additions & 0 deletions v20.2/indexes.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ After a column is indexed, SQL can easily filter its values using the index inst

For example, if you index an `INT` column and then filter it <code>WHERE &lt;indexed column&gt; = 10</code>, SQL can use the index to find values starting at 10 but less than 11. In contrast, without an index, SQL would have to evaluate _every_ row in the table for values equaling 10. This is also known as a "full table scan", and it can be very bad for query performance.

<span class="version-tag">New in v20.2:</span> You can also create an index on a subset of rows. This type of index is called a partial index. For more information, see [Partial indexes](partial-indexes.html).

### Creation

Each table automatically has an index created called `primary`, which indexes either its [primary key](primary-key.html) or&mdash;if there is no primary key&mdash;a unique value for each row known as `rowid`. We recommend always defining a primary key because the index it creates provides much better performance than letting CockroachDB use `rowid`.
Expand Down
Loading