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

sql: inverted index queries with non-top level scalars are incorrect #23897

Closed
jordanlewis opened this issue Mar 15, 2018 · 0 comments · Fixed by #23934
Closed

sql: inverted index queries with non-top level scalars are incorrect #23897

jordanlewis opened this issue Mar 15, 2018 · 0 comments · Fixed by #23934
Assignees
Labels
A-sql-json JSON handling in SQL. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
Milestone

Comments

@jordanlewis
Copy link
Member

Expected:

root@:26257/test> select '{"a": [3]}' @> '{"a": 3}';
+----------------------------+
| '{"a": [3]}' @> '{"a": 3}' |
+----------------------------+
|            true            |
+----------------------------+
(1 row)

Actual:

root@:26257/test> insert into j values('{"a": [3]}');
INSERT 1
root@:26257/test> select * from j where j @> '{"a": 3}'::jsonb;
+---+
| j |
+---+
+---+
(0 rows)

root@:26257/test> explain select * from j where j @> '{"a": 3}'::jsonb;
+-----------------+-------+-------------------------+
|      Tree       | Field |       Description       |
+-----------------+-------+-------------------------+
| render          |       |                         |
|  └── index-join |       |                         |
|       ├── scan  |       |                         |
|       │         | table | j@j_j_idx               |
|       │         | spans | /"a"/3-/"a"/3/PrefixEnd |
|       └── scan  |       |                         |
|                 | table | j@primary               |
+-----------------+-------+-------------------------+
(7 rows)

The problem is that the fix applied by #22503 was incomplete - it only applies to top level scalars.

@jordanlewis jordanlewis added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. A-sql-json JSON handling in SQL. labels Mar 15, 2018
@jordanlewis jordanlewis added this to the 2.0 milestone Mar 15, 2018
@jordanlewis jordanlewis self-assigned this Mar 15, 2018
justinj pushed a commit to justinj/cockroach that referenced this issue Mar 15, 2018
Closes cockroachdb#23897.

The problem here wasn't actually with our inverted index queries - we
had the implementation of this operator wrong from Postgres. Only
*top-level* arrays contain scalars.

Release note (bug fix): fix behaviour of @> operator with arrays and
scalars.
@vivekmenezes vivekmenezes assigned justinj and unassigned jordanlewis Mar 16, 2018
justinj pushed a commit to justinj/cockroach that referenced this issue Mar 16, 2018
Closes cockroachdb#23897.

The problem here wasn't actually with our inverted index queries - we
had the implementation of this operator wrong from Postgres. Only
*top-level* arrays contain scalars.

Release note (bug fix): fix behaviour of @> operator with arrays and
scalars.
justinj pushed a commit to justinj/cockroach that referenced this issue Mar 16, 2018
Closes cockroachdb#23897.

The problem here wasn't actually with our inverted index queries - we
had the implementation of this operator wrong from Postgres. Only
*top-level* arrays contain scalars.

Release note (bug fix): fix behaviour of @> operator with arrays and
scalars.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-json JSON handling in SQL. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants