Skip to content

sql: extra inverted index keys generated for NULL #45154

@jordanlewis

Description

@jordanlewis

The following setup creates an inverted index key, where it really shouldn't (as it's pointless):

CREATE TABLE a (j JSON, INVERTED INDEX(j));
INSERT INTO a VALUES(NULL);

This actually inserts a NULL entry into the inverted index, which is never queryable or useful in any way. Instead, this should insert no entries into the inverted index.

The same probably goes for stuff like '{}'and '[]', which can't be queried for using the inverted index using Postgres. With Cockroach you can query for these values (SELECT * FROM a WHERE j @> '{}') but it seems questionable how useful this pattern is.

The obstacle to fixing this is that many users of the index key creation methods expect there to be at least one index key returned for each index. This change will violate that assumption. However, the same problem will be present for empty arrays when we begin to support array inverted indexes, so we'll have to fix this at some point anyway (or be forced to introduce a pointless index key for all empty arrays).

Metadata

Metadata

Assignees

Labels

C-cleanupTech debt, refactors, loose ends, etc. Solution not expected to significantly change behavior.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions