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: virtual tables don't respect LIMIT when there is a WHERE clause #53522

Closed
rafiss opened this issue Aug 26, 2020 · 3 comments · Fixed by #53529
Closed

sql: virtual tables don't respect LIMIT when there is a WHERE clause #53522

rafiss opened this issue Aug 26, 2020 · 3 comments · Fixed by #53529
Labels
A-sql-vtables Virtual tables - pg_catalog, information_schema etc C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.

Comments

@rafiss
Copy link
Collaborator

rafiss commented Aug 26, 2020

To reproduce

It might relate to the indexes that were added to vtables.

root@:26257/defaultdb> create table t (id int primary key, name text, notselected text, ts timestamp with time zone, intarr int[]);
CREATE TABLE

Time: 74.401ms

root@:26257/defaultdb> select oid from pg_class where relname = 't';;
  oid
-------
  800
(1 row)

Time: 54.675ms

root@:26257/defaultdb> select attname from pg_attribute limit 1;
     attname
-----------------
  descriptor_id
(1 row)

Time: 52.461ms

root@:26257/defaultdb> select attname from pg_attribute where attrelid = 800 limit 1;
    attname
---------------
  id
  name
  notselected
  ts
  intarr
(5 rows)

On v20.2

@rafiss rafiss added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. A-sql-vtables Virtual tables - pg_catalog, information_schema etc labels Aug 26, 2020
@jordanlewis
Copy link
Member

Hm, yeah, looks like the optimizer thinks this can be at most 1 row so it removes the limit. Not sure why.


[email protected]:57327/defaultdb> explain(opt,verbose) select attname from pg_attribute where attrelid = 800 limit 5;
                         text
-------------------------------------------------------
  project
   ├── columns: attname:3
   ├── cardinality: [0 - 1]
   ├── stats: [rows=1]
   ├── cost: 1.29
   ├── key: ()
   ├── fd: ()-->(3)
   ├── prune: (3)
   └── scan pg_attribute@pg_attribute_attrelid_idx
        ├── columns: attrelid:2 attname:3
        ├── constraint: /2: [/800 - /800]
        ├── cardinality: [0 - 1]
        ├── stats: [rows=1, distinct(2)=1, null(2)=0]
        ├── cost: 1.27
        ├── key: ()
        └── fd: ()-->(2,3)
(16 rows)

@rohany
Copy link
Contributor

rohany commented Aug 26, 2020

Is the index advertised as unique?

@jordanlewis
Copy link
Member

No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-vtables Virtual tables - pg_catalog, information_schema etc 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.

3 participants