Repository navigation
Description
Description
Sequence functions cannot address a sequence outside the current database, and qualified names are mis-resolved by prefixing the current database again:
CREATE DATABASE seqdb;
CREATE SEQUENCE seqdb.s1 START 100; -- created fine
USE otherdb;
SELECT nextval('seqdb.s1');
-- ERROR 1146 (42S02): no such table otherdb.seqdb.s1
-- (resolution reshaped the qualified name to <current-db>.<qualified-name-as-singlepart>)Effectively:
nextval('seqdb.s1')from any session whose current database is notseqdb→ 1146 with a mangled three-part name (otherdb.seqdb.s1,seqdb.seqdb.s1etc.). The error message itself reveals the resolver treats the argument as a single identifier.nextval('s1')works — but only for sequences in the current database.NEXT VALUE FOR <qualified>is rejected at parse level entirely (only a single-part name is accepted:syntax error near " seqtest.s1").
Net effect: a sequence is only usable from within its own database — no cross-database nextval, no qualified access, and the failure mode is a misleading "no such table" with a doubled database prefix. MySQL doesn't have sequences (MO follows PostgreSQL-style here), but MO's own docs show nextval('db.seq') qualified usage, and the double-prefix resolution is a resolver defect regardless of the SQL dialect.
Reproduction
CREATE DATABASE seqdb; CREATE SEQUENCE seqdb.s1 START 100;
CREATE DATABASE otherdb;
-- session A (no default db): SELECT nextval('seqdb.s1'); -- parse error ExpectedEOB
-- session B (USE seqdb): SELECT nextval('seqdb.s1'); -- ERROR 1146: no such table seqdb.seqtest.s1-style doubled name
-- session C (USE otherdb): SELECT nextval('seqdb.s1'); -- ERROR 1146: no such table otherdb.seqdb.s1
-- session C: SELECT NEXT VALUE FOR seqdb.s1; -- parser syntax error
-- session C: SELECT nextval('s1'); -- ERROR (no sequence in otherdb)Impact
- Applications following MO's documented qualified
nextval('db.seq')pattern break with confusing doubled-name errors. - Schema designs sharing a central sequence across databases (multi-tenant key patterns, ETL watermark sequences) are impossible.
- The doubled-name error (
otherdb.seqdb.s1) makes diagnosis hard — users see a "table" that never existed in their statement.
Expected behavior
nextval('db.seq') (and NEXT VALUE FOR db.seq) should resolve the qualified name correctly from any session context, matching MO's documented usage; until then the resolver should at least not silently prepend the current database to an already-qualified argument.
Activity
Ariznawlll commentedon Oct 28, 2026
Cross-environment retest found a regression on the 4.2.1 hotfix cloud build that goes beyond this issue's current scope description:
Same-database, bare-name
nextval('sq')also fails on the 4.2.1-hotfix cloud build (works on main):8.0.30-MatrixOne-v4.2.6, image built 2026-10-18)8.0.30-MatrixOne-v4.2.1-hotfix-20261026ERROR 1146 (HY000): no such table mo_seq_test.sqZSo the statement in this issue — "nextval('s1') works — but only for sequences in the current database" — holds on main, but the same-database path is also broken on the 4.2.1-hotfix cloud build (sequence name resolved as a table). This looks like either a fix that was not backported or a regression introduced on the hotfix branch — noting it here for backport triage.
Additionally (consistent across both environments, within this issue's original scope): with no default database selected,
SELECT nextval('db.seq')surfaces a bareERROR at line 1: ExpectedEOBto the client — the internal OkExpectedEOB error code leaks without an error code / SQLSTATE. Worth normalizing the client-facing error when the resolution is fixed.Ariznawlll commentedon Oct 29, 2026
A more severe failure shape of this same resolver bug, reproduced today on main
c6683bd2f5(2026-10-29): in certain states a qualifiednextval('db.seq')doesn't even reach the clean 1146 — it leaks the raw internal sentinel to the client:Observed pattern in one session, in order:
SELECT NEXTVAL('srx.sq')right after the DDL →ERROR (0, 'ExpectedEOB')(raw sentinel, the same shape as previously fixed leaks [Bug]: CREATE TEMPORARY TABLE in a database created in the same transaction leaks raw(0, 'ExpectedEOB')#30506/[Bug]: Temporary-table cleanup emits ExpectedEOB from DROP TABLE IF EXISTS #27463 and my [Bug]: mo_ctl flush bad target leaks errno 0 ExpectedEOB #31663 for mo_ctl flush);USE srxthen retry bareNEXTVAL('sq')→ works, sequence advances fine;INSERT INTO srx.t VALUES (nextval('srx.sq'), 1)→ERROR 1146: no such table srx.srx.sq(the double-prefix mis-resolution already documented in this issue);INSERT ... nextval('sq')(bare) → OK.So the qualified-name path has two user-visible defects — the mangled 1146 name (this issue's main subject) and, on the resolution miss that precedes it, a raw
OkExpectedEOBpropagation to the client. The ExpectedEOB variant is the more dangerous one for tooling: errno 0 reads as success, and the message is not a real user error.Environment: dual-CN launch, reproducible after warm-up sequence usage in the same session; cold sessions mostly give the 1146 shape first.