Skip to content

Commit

Permalink
TA 97090 (cockroachdb#16342)
Browse files Browse the repository at this point in the history
* TA 97090

* links

* review

* review
  • Loading branch information
gemma-shay authored Mar 6, 2023
1 parent c449250 commit f9484df
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions advisories/a97090.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: Technical Advisory 97090
advisory: A-97090
summary: Queries planned with a zigzag join could produce incorrect results if the two indexes used for the join had a matching suffix of index key columns where the direction was different between the two indexes.
toc: true
affected_versions: v19.1 to v22.1.15, v22.2.0 to v22.2.5
advisory_date: 2023-02-24
docs_area: releases
---

Publication date: {{ page.advisory_date | date: "%B %e, %Y" }}

## Description

In all versions of CockroachDB from [v19.1](../releases/index.html#v19-1) to [v22.1.15](../releases/v22.1.html#v22-1-15) and [v22.2.0](../releases/v22.2.html#v22-2-0) to [v22.2.5](../releases/v22.2.html#v22-2-5), queries that used a [zigzag join](../{{site.versions["stable"]}}/cost-based-optimizer.html#zigzag-joins) could return incorrect results in some cases. Zigzag joins can be planned when at least two columns from the same table are fixed to constant values by the query predicate, and [indexes](../{{site.versions["stable"]}}/indexes.html) exist on both of those columns. The bug could occur when the two indexes used had a matching suffix of key columns where the direction of at least one column differed between the two indexes.

For example, if a table `t` contained indexes `INDEX (a ASC, c DESC)` and `INDEX (b ASC, c ASC)`, a query such as `SELECT * FROM t WHERE a = 1 AND b = 2;` could return incorrect results, since the direction of column `c` was `DESC` in one index and `ASC` in the other.


## Statement

This is resolved in CockroachDB by [#97151](https://github.com/cockroachdb/cockroach/pull/97151), which prevents the [optimizer](../{{site.versions["stable"]}}/cost-based-optimizer.html) from planning zigzag joins when any columns in the matching suffix between two candidate indexes have different directions.

The fix has been applied to maintenance releases of CockroachDB [v22.1.16](../releases/v22.1.html#v22-1-16) and [v22.2.6](../releases/v22.2.html#v22-2-6).

This public issue is tracked by [#97090](https://github.com/cockroachdb/cockroach/issues/97090).

## Mitigation

Users of CockroachDB [v19.1](../releases/index.html#v19-1) to [v22.1.15](../releases/v22.1.html#v22-1-15) and [v22.2.0](../releases/v22.2.html#v22-2-0) to [v22.2.5](../releases/v22.2.html#v22-2-5) are encouraged to upgrade to [v22.1.16](../releases/v22.1.html#v22-1-16), [v22.2.6](../releases/v22.2.html#v22-2-6), or a later version.

To determine whether your queries may be affected by this issue on prior versions, you should examine your query plans. If the output of [`EXPLAIN`](../{{site.versions["stable"]}}/explain.html) shows that the query is using a zigzag join, it may be affected by this issue. You can mitigate the problem by setting the [session setting](../{{site.versions["stable"]}}/set-vars.html) `enable_zigzag_join` to `false`. On v21.2 or later, you can also force the optimizer to avoid zigzag joins with a [`NO_ZIGZAG_JOIN` hint](../{{site.versions["stable"]}}/cost-based-optimizer.html#prevent-or-force-a-zigzag-join).

The best mitigation, however, is to upgrade to [v22.1.16](../releases/v22.1.html#v22-1-16) or [v22.2.6](../releases/v22.2.html#v22-2-6) as soon as possible.

## Impact

Some queries planned with a zigzag join could produce incorrect results if the two indexes used for the zigzag join had a matching suffix of index key columns where the direction (`ASC`/`DESC`) was different between the two indexes. Versions affected include all versions of CockroachDB [v19.1](../releases/index.html#v19-1) to [v22.1.15](../releases/v22.1.html#v22-1-15) and [v22.2.0](../releases/v22.2.html#v22-2-0) to [v22.2.5](../releases/v22.2.html#v22-2-5).

Questions about any technical alert can be directed to our [support team](https://support.cockroachlabs.com/).

0 comments on commit f9484df

Please sign in to comment.