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

Integer Overflow with Index Hints #110409

Closed
bajinsheng opened this issue Sep 12, 2023 · 2 comments
Closed

Integer Overflow with Index Hints #110409

bajinsheng opened this issue Sep 12, 2023 · 2 comments
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-community Originated from the community T-sql-queries SQL Queries Team

Comments

@bajinsheng
Copy link

bajinsheng commented Sep 12, 2023

Describe the problem

For the same query, running with an index hint returns an error, while running without the hint returns the correct result.

To Reproduce

CREATE TABLE t1 (c0 VARBIT(134), c1 DECIMAL);
CREATE TABLE t3 (c0 TIMESTAMP);
CREATE TABLE t5 (c0 BIT(184));

INSERT INTO t1 (rowid, c1) VALUES(-2125308029, -1799230729);
INSERT INTO t1 (c1) VALUES(-1584079189);
INSERT INTO t3 (rowid, c0) VALUES(-367137600, TIMESTAMP '1970-01-26T01:27:10');
CREATE INDEX ON t1(rowid);

SELECT * FROM t5, t1, t3 WHERE (t3.rowid > SOME (48544246, 1140549043*t1.rowid)); -- {}
SELECT * FROM t1 @{FORCE_INDEX=t1_pkey,DESC}, t5, t3 WHERE (t3.rowid > SOME (48544246, 1140549043*t1.rowid)); -- {ERROR: integer out of range}

Expected behavior
The second query should return the result as well?

Additional data / screenshots

Environment:

  • CockroachDB version [ CockroachDB CCL v23.2.0-alpha.00000000-dev-d7738743c955be36b1c9304a40d9e4e7b3edc4ad]
  • Server OS: [Linux/Ubuntu]
  • Client app [cockroach sql]

Additional context

Jira issue: CRDB-31408

@bajinsheng bajinsheng added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Sep 12, 2023
@blathers-crl
Copy link

blathers-crl bot commented Sep 12, 2023

Hello, I am Blathers. I am here to help you get the issue triaged.

Hoot - a bug! Though bugs are the bane of my existence, rest assured the wretched thing will get the best of care here.

I was unable to automatically find someone to ping.

If we have not gotten back to your issue within a few business days, you can try the following:

  • Join our community slack channel and ask on #cockroachdb.
  • Try find someone from here if you know they worked closely on the area and CC them.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@blathers-crl blathers-crl bot added O-community Originated from the community X-blathers-untriaged blathers was unable to find an owner labels Sep 12, 2023
@yuzefovich yuzefovich added T-sql-queries SQL Queries Team and removed X-blathers-untriaged blathers was unable to find an owner labels Sep 12, 2023
@DrewKimball DrewKimball self-assigned this Sep 19, 2023
@mgartner
Copy link
Collaborator

I don't think this is a bug. The optimizer generally does not guarantee the order in which expressions or rows are evaluated, with a few exceptions. Therefore, it is perfectly valid for this query to error some of the time.

A similar case has the same error in Postgres, FWIW:

CREATE TABLE t1 (rowid INT8, c0 VARBIT(134), c1 DECIMAL);
CREATE TABLE t3 (rowid INT8, c0 TIMESTAMP);
CREATE TABLE t5 (rowid INT8, c0 BIT(184));

INSERT INTO t1 (rowid, c1) VALUES(-2125308029, -1799230729);
INSERT INTO t1 (rowid, c1) VALUES(967638252729237505, -1584079189);
INSERT INTO t3 (rowid, c0) VALUES(-367137600, TIMESTAMP '1970-01-26T01:27:10');
CREATE INDEX ON t1(rowid);

SELECT * FROM t5, t1, t3 WHERE (t3.rowid > SOME (ARRAY[48544246, 1140549043*t1.rowid]));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-community Originated from the community T-sql-queries SQL Queries Team
Projects
Status: Done
Development

No branches or pull requests

4 participants