Skip to content

sql: enabling forward indexes and ORDERBY on JSONB columns#99275

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
Shivs11:jsonb_forward_indexes_composite_testing
Apr 11, 2023
Merged

sql: enabling forward indexes and ORDERBY on JSONB columns#99275
craig[bot] merged 1 commit intocockroachdb:masterfrom
Shivs11:jsonb_forward_indexes_composite_testing

Conversation

@Shivs11
Copy link
Copy Markdown
Contributor

@Shivs11 Shivs11 commented Mar 22, 2023

Currently, #97928 outlines the scheme for JSONB encoding
and decoding for forward indexes. However, the PR doesn't
enable this feature to our users. This current PR aims
to allow forward indexes on JSONB columns. The presence
of a lexicographical ordering, as described in #97928,
shall now allow primary and secondary indexes on JSONB
columns along with the ability to use ORDER BY filter
in their queries.

Additionally, JSON values consist of decimal numbers
and containers, such as Arrays and Objects, which can
contain these decimal numbers. In order to preserve
the values after the decimal, JSONB columns are now
required to be composite in nature. This shall enable
such values to be stored in both the key and the value
side of a K/V pair in hopes of receiving the exact value.

Fixes: #35706

Release note (sql change): This PR adds support for enabling
forward indexes and ordering on JSON values.

Epic: CRDB-24501

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@Shivs11 Shivs11 force-pushed the jsonb_forward_indexes_composite_testing branch 3 times, most recently from 1b476b6 to 09a0281 Compare March 28, 2023 21:42
@Shivs11 Shivs11 changed the title Jsonb forward indexes composite testing sql: enabling forward indexes and ORDERBY on JSONB columns Mar 28, 2023
@Shivs11 Shivs11 force-pushed the jsonb_forward_indexes_composite_testing branch 13 times, most recently from dbbdd2b to e14460d Compare March 29, 2023 20:59
Copy link
Copy Markdown
Contributor Author

@Shivs11 Shivs11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained


pkg/sql/ttl/ttljob/ttljob_test.go line 583 at r2 (raw file):

			indexableTyps = append(indexableTyps, typ)
		}
	}

An issue has been raised here: #99432

@Shivs11 Shivs11 force-pushed the jsonb_forward_indexes_composite_testing branch 4 times, most recently from 44fc0db to 890ba2f Compare March 30, 2023 20:00
@Shivs11 Shivs11 marked this pull request as ready for review March 30, 2023 20:07
@Shivs11 Shivs11 requested review from a team March 30, 2023 20:07
@Shivs11 Shivs11 requested a review from a team as a code owner March 30, 2023 20:07
@Shivs11 Shivs11 requested review from rharding6373 and removed request for rharding6373 March 30, 2023 20:07
Shivs11 added a commit to Shivs11/cockroach that referenced this pull request Apr 11, 2023
Currently, cockroachdb#97928 and cockroachdb#99275 are responsible for laying out
a lexicographical ordering for JSON columns to be forward
indexable in nature. This ordering is based on the rules
posted by Postgres and is defined here: cockroachdb#99849

However, Postgres currently sorts the empty JSON array
before any other JSON values. An issue has been opened:
https://www.postgresql.org/message-id/17873-826fdc8bbcace4f1%40postgresql.org

Thus, this PR intends on replicating this behaviour until
the issue has been identified and resolved by Postgres.

Epic: CRDB-24501

Release note (sql change): This PR shall now place the empty JSON array
to have the lowest (highest) precedence when the JSON column
is being sorted in ascending (descending) order.
Shivs11 added a commit to Shivs11/cockroach that referenced this pull request Apr 21, 2023
Previously, cockroachdb#99275 and cockroachdb#97298 were responsible for laying the
foundations of a JSON lexicographical order as well as enabling JSON
forward indexes in CRDB. However, these commits did not account for
version gates. In a given cluster, all of its nodes are required to be
at a certain version number for creating JSON forward indexes as well as
for ordering JSON columns.  Thus, this PR aims to enable version gates
for ensuring all nodes in a given cluster meet this requirement.

Epic: CRDB-24501

Release note (sql change): This PR adds version gates which requires all
nodes in a given cluster to have a minimum binary version number which
in turn is required for creating forward indexes on JSON columns and for
ordering JSON columns.

Fixes: cockroachdb#35706
Shivs11 added a commit to Shivs11/cockroach that referenced this pull request Apr 24, 2023
Previously, cockroachdb#99275 and cockroachdb#97298 were responsible for laying the
foundations of a JSON lexicographical order as well as enabling JSON
forward indexes in CRDB. However, these commits did not account for
version gates. In a given cluster, all of its nodes are required to be
at a certain version number for creating JSON forward indexes as well as
for ordering JSON columns.  Thus, this PR aims to enable version gates
for ensuring all nodes in a given cluster meet this requirement.

Epic: CRDB-24501

Release note (sql change): This PR adds version gates which requires all
nodes in a given cluster to have a minimum binary version number which
in turn is required for creating forward indexes on JSON columns and for
ordering JSON columns.

Fixes: cockroachdb#35706
Shivs11 added a commit to Shivs11/cockroach that referenced this pull request Apr 26, 2023
Previously, cockroachdb#99275 and cockroachdb#97298 were responsible for laying the
foundations of a JSON lexicographical order as well as enabling JSON
forward indexes in CRDB. However, these commits did not account for
version gates. In a given cluster, all of its nodes are required to be
at a certain version number for creating JSON forward indexes as well as
for ordering JSON columns.  Thus, this PR aims to enable version gates
for ensuring all nodes in a given cluster meet this requirement.

Epic: CRDB-24501

Release note (sql change): This PR adds version gates which requires all
nodes in a given cluster to have a minimum binary version number which
in turn is required for creating forward indexes on JSON columns and for
ordering JSON columns.

Fixes: cockroachdb#35706
Shivs11 added a commit to Shivs11/cockroach that referenced this pull request Apr 26, 2023
Previously, cockroachdb#99275 and cockroachdb#97298 were responsible for laying the
foundations of a JSON lexicographical order as well as enabling JSON
forward indexes in CRDB. However, these commits did not account for
version gates. In a given cluster, all of its nodes are required to be
at a certain version number for creating JSON forward indexes as well as
for ordering JSON columns.  Thus, this PR aims to enable version gates
for ensuring all nodes in a given cluster meet this requirement.

Epic: CRDB-24501

Release note (sql change): This PR adds version gates which requires all
nodes in a given cluster to have a minimum binary version number which
in turn is required for creating forward indexes on JSON columns and for
ordering JSON columns.

Fixes: cockroachdb#35706
rharding6373 pushed a commit to Shivs11/cockroach that referenced this pull request May 15, 2023
Previously, cockroachdb#99275 and cockroachdb#97928 were responsible for laying the
foundations of a JSON lexicographical order as well as enabling JSON
forward indexes in CRDB. However, these commits did not account for
version gates. In a given cluster, all of its nodes are required to be
at a certain version number for creating JSON forward indexes as well as
for ordering JSON columns.  Thus, this PR aims to enable version gates
for ensuring all nodes in a given cluster meet this requirement.

Epic: CRDB-24501

Fixes: cockroachdb#35706

Release note (sql change): This PR adds version gates which requires all
nodes in a given cluster to have a minimum binary version number which
in turn is required for creating forward indexes on JSON columns and for
ordering JSON columns.
rharding6373 pushed a commit to Shivs11/cockroach that referenced this pull request May 15, 2023
Previously, cockroachdb#99275 and cockroachdb#97928 were responsible for laying the
foundations of a JSON lexicographical order as well as enabling JSON
forward indexes in CRDB. However, these commits did not account for
version gates. In a given cluster, all of its nodes are required to be
at a certain version number for creating JSON forward indexes as well as
for ordering JSON columns.  Thus, this PR aims to enable version gates
for ensuring all nodes in a given cluster meet this requirement.

Epic: CRDB-24501

Fixes: cockroachdb#35706

Release note (sql change): This PR adds version gates which requires all
nodes in a given cluster to have a minimum binary version number which
in turn is required for creating forward indexes on JSON columns and for
ordering JSON columns.
rharding6373 pushed a commit to Shivs11/cockroach that referenced this pull request May 15, 2023
Previously, cockroachdb#99275 and cockroachdb#97928 were responsible for laying the
foundations of a JSON lexicographical order as well as enabling JSON
forward indexes in CRDB. However, these commits did not account for
version gates. In a given cluster, all of its nodes are required to be
at a certain version number for creating JSON forward indexes as well as
for ordering JSON columns.  Thus, this PR aims to enable version gates
for ensuring all nodes in a given cluster meet this requirement.

Epic: CRDB-24501

Fixes: cockroachdb#35706

Release note (sql change): This PR adds version gates which requires all
nodes in a given cluster to have a minimum binary version number which
in turn is required for creating forward indexes on JSON columns and for
ordering JSON columns.
rharding6373 pushed a commit to Shivs11/cockroach that referenced this pull request May 15, 2023
Previously, cockroachdb#99275 and cockroachdb#97928 were responsible for laying the
foundations of a JSON lexicographical order as well as enabling JSON
forward indexes in CRDB. However, these commits did not account for
version gates. In a given cluster, all of its nodes are required to be
at a certain version number for creating JSON forward indexes as well as
for ordering JSON columns.  Thus, this PR aims to enable version gates
for ensuring all nodes in a given cluster meet this requirement.

Epic: CRDB-24501

Fixes: cockroachdb#35706

Release note (sql change): This PR adds version gates which requires all
nodes in a given cluster to have a minimum binary version number which
in turn is required for creating forward indexes on JSON columns and for
ordering JSON columns.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql: support ordering by JSON (pq: unable to encode table key: *tree.DJSON)

6 participants