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

[YSQL] SELECTing directly from a sequence throws an error #999

Closed
hectorgcr opened this issue Mar 14, 2019 · 5 comments
Closed

[YSQL] SELECTing directly from a sequence throws an error #999

hectorgcr opened this issue Mar 14, 2019 · 5 comments
Assignees
Labels
kind/bug This issue is a bug

Comments

@hectorgcr
Copy link
Contributor

Currently we don't support selecting directly from a sequence:

CREATE SEQUENCE
postgres=# select last_value from s;
ERROR:  Not found: Error loading table with id 000047c5000030008000000000006710: Not found (yb/master/catalog_manager.cc:3398): The table does not exist: table_id: "000047c5000030008000000000006710"```
@hectorgcr hectorgcr added the kind/bug This issue is a bug label Mar 14, 2019
@hectorgcr hectorgcr self-assigned this Mar 14, 2019
@kmuthukk
Copy link
Collaborator

This could be lower-pri, right? I am not sure if this is a common flow. Most apps would do s.nextVal() rather than query this table.

@hectorgcr
Copy link
Contributor Author

hectorgcr commented Mar 14, 2019

This could be lower-pri, right? I am not sure if this is a common flow. Most apps would do s.nextVal() rather than query this table.

Correct. But I'm just trying to open bugs for all the issues I know that are related to sequences.

For now we will improve the error message to let the user know that we don't support selecting from sequences directly instead of throwing some error directly from catalog_manager.cc.

The disadvantage of using nextval() is that it increments the last_value.

@kmuthukk
Copy link
Collaborator

makes sense @hectorgcr .

yugabyte-ci pushed a commit that referenced this issue Mar 15, 2019
Summary:
Currently we get this error:

```
CREATE SEQUENCE
postgres=# select last_value from s;
ERROR:  Not found: Error loading table with id 000047c5000030008000000000006710: Not found (yb/master/catalog_manager.cc:3398): The table does not exist: table_id: "000047c5000030008000000000006710"```

Changing the code to give a more informative error
```ERROR:  "s" is a sequence table
DETAIL:  Querying sequence tables is not supported yet.
HINT:  Use lastval() and currval().```

Test Plan: New unit test

Reviewers: mihnea, robert

Reviewed By: robert

Subscribers: yql

Differential Revision: https://phabricator.dev.yugabyte.com/D6333
@hectorgcr
Copy link
Contributor Author

hectorgcr commented Apr 17, 2019

@ndeodhar found that pg_dump doesn't work correctly for sequences because it is trying to do a SELECT on the sequence:

pg_dump: [archiver (db)] query failed: ERROR:  "bar_a_seq" is a sequence table
DETAIL:  Querying sequence tables is not supported yet.
HINT:  Use lastval() and currval() instead.
pg_dump: [archiver (db)] query was: SELECT last_value, is_called FROM public.bar_a_seq./postgres/bin/pg_dump -d postgres -h 127.0.0.1 -p 5433 -U postgres
pg_dump: [archiver (db)] query failed: ERROR:  "bar_a_seq" is a sequence table
DETAIL:  Querying sequence tables is not supported yet.
HINT:  Use lastval() and currval() instead.
pg_dump: [archiver (db)] query was: SELECT last_value, is_called FROM public.bar_a_seq```

@ndeodhar
Copy link
Contributor

Another thing to verify: Since we create a separate postgres table for sequence, it's likely that pg_dump will add a "create table" statement for that sequence table. This may cause issues while loading the data.

yugabyte-ci pushed a commit that referenced this issue Jul 8, 2019
Summary:
It is now possible to do SELECT statements on sequences, which was formerly impossible
because the data from all sequences was stored in a single YugaByte table rather than each sequence
having their own table as PostgreSQL expects. To simulate the expected behavior, when Postgres
attempts to read a data page from the sequence, a blank data page is allocated and filled with the
data that is read from YugaByte.

Test Plan:
In `ysqlsh`, create a sequence (`CREATE SEQUENCE seq`) and select from it
(`SELECT * FROM seq`). There should be three columns returned: `last_value`, `log_cnt`, and
`is_called`. It should start with `last_value` as 1. Do something like `SELECT nextval('seq')` to
increment the sequence and then perform another `SELECT` to ensure that `last_value` was
appropriately incremented that same number of times.

Reviewers: kannan, hector, neha

Reviewed By: hector, neha

Subscribers: yql

Differential Revision: https://phabricator.dev.yugabyte.com/D6841
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug This issue is a bug
Projects
None yet
Development

No branches or pull requests

4 participants