Skip to content

Commit

Permalink
sql: fix limits on virtual index scans
Browse files Browse the repository at this point in the history
Previously, virtual indexes mis-reported their key columns as containing
only their index key. Virtual indexes always need to contain the dummy
PK column since they're not guaranteed to be unique. This caused some
broken behavior like limits not working properly in some cases.

Release note (bug fix): virtual index scans respect limits properly as
they did in 20.1 and prior.

Release justification: bug fix to new functionality
  • Loading branch information
jordanlewis committed Aug 28, 2020
1 parent c046a2b commit 4aa891b
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 222 deletions.
10 changes: 10 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/pg_catalog
Original file line number Diff line number Diff line change
Expand Up @@ -2665,3 +2665,13 @@ WHERE
AND attname = 'x'
----
'howdy'::STRING

# Regression test for limits on virtual index scans. (#53522)

let $testid
SELECT 't47285'::REGCLASS::OID

query T
SELECT attname FROM pg_attribute WHERE attrelid = $testid LIMIT 1
----
x
4 changes: 2 additions & 2 deletions pkg/sql/opt/exec/execbuilder/testdata/catalog
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,5 @@ scan abx
query T
EXPLAIN (OPT) select * from pg_type where oid = 1000
----
scan pg_type@pg_type_oid_idx
└── constraint: /2: [/1000 - /1000]
scan pg_type@pg_type_oid_idx
└── constraint: /2/1: [/1000 - /1000]
143 changes: 70 additions & 73 deletions pkg/sql/opt/exec/execbuilder/testdata/explain
Original file line number Diff line number Diff line change
Expand Up @@ -179,65 +179,63 @@ sort · ·
query TTT
SELECT * FROM [EXPLAIN SHOW TABLES] WHERE field != 'size'
----
· distribution local
· vectorized false
sort · ·
│ order +nspname,+relname
└── render · ·
└── hash join (right outer) · ·
│ equality (table_id) = (column44)
├── virtual table · ·
│ table table_row_statistics@primary
└── render · ·
└── hash join · ·
│ equality (oid) = (relnamespace)
├── filter · ·
│ │ filter nspname NOT IN ('crdb_internal', 'information_schema', 'pg_catalog', 'pg_extension')
│ └── virtual table · ·
│ table pg_namespace@primary
└── hash join (left outer) · ·
│ equality (oid) = (objoid)
│ left cols are key ·
├── filter · ·
│ │ filter relkind IN ('S', 'r', 'v')
│ └── virtual table · ·
│ table pg_class@primary
└── filter · ·
│ filter objsubid = 0
└── virtual table · ·
· table pg_description@primary
· distribution local
· vectorized false
sort · ·
│ order +nspname,+relname
└── render · ·
└── hash join (right outer) · ·
│ equality (table_id) = (column44)
├── virtual table · ·
│ table table_row_statistics@primary
└── render · ·
└── hash join · ·
│ equality (oid) = (relnamespace)
├── filter · ·
│ │ filter nspname NOT IN ('crdb_internal', 'information_schema', 'pg_catalog', 'pg_extension')
│ └── virtual table · ·
│ table pg_namespace@primary
└── hash join (left outer) · ·
│ equality (oid) = (objoid)
├── filter · ·
│ │ filter relkind IN ('S', 'r', 'v')
│ └── virtual table · ·
│ table pg_class@primary
└── filter · ·
│ filter objsubid = 0
└── virtual table · ·
· table pg_description@primary


query TTT
SELECT * FROM [EXPLAIN SHOW TABLES WITH COMMENT] WHERE field != 'size'
----
· distribution local
· vectorized false
sort · ·
│ order +nspname,+relname
└── render · ·
└── hash join (right outer) · ·
│ equality (table_id) = (column44)
├── virtual table · ·
│ table table_row_statistics@primary
└── render · ·
└── hash join · ·
│ equality (oid) = (relnamespace)
├── filter · ·
│ │ filter nspname NOT IN ('crdb_internal', 'information_schema', 'pg_catalog', 'pg_extension')
│ └── virtual table · ·
│ table pg_namespace@primary
└── hash join (left outer) · ·
│ equality (oid) = (objoid)
│ left cols are key ·
├── filter · ·
│ │ filter relkind IN ('S', 'r', 'v')
│ └── virtual table · ·
│ table pg_class@primary
└── filter · ·
│ filter objsubid = 0
└── virtual table · ·
· table pg_description@primary
· distribution local
· vectorized false
sort · ·
│ order +nspname,+relname
└── render · ·
└── hash join (right outer) · ·
│ equality (table_id) = (column44)
├── virtual table · ·
│ table table_row_statistics@primary
└── render · ·
└── hash join · ·
│ equality (oid) = (relnamespace)
├── filter · ·
│ │ filter nspname NOT IN ('crdb_internal', 'information_schema', 'pg_catalog', 'pg_extension')
│ └── virtual table · ·
│ table pg_namespace@primary
└── hash join (left outer) · ·
│ equality (oid) = (objoid)
├── filter · ·
│ │ filter relkind IN ('S', 'r', 'v')
│ └── virtual table · ·
│ table pg_class@primary
└── filter · ·
│ filter objsubid = 0
└── virtual table · ·
· table pg_description@primary

query TTT
SELECT * FROM [EXPLAIN SHOW DATABASE] WHERE field != 'size'
Expand Down Expand Up @@ -347,25 +345,24 @@ render · ·
query TTT
EXPLAIN SHOW CONSTRAINTS FROM foo
----
· distribution local
· vectorized false
sort · ·
│ order +conname
└── render · ·
└── hash join · ·
│ equality (oid) = (relnamespace)
├── filter · ·
│ │ filter nspname = 'public'
│ └── virtual table · ·
│ table pg_namespace@primary
└── virtual table lookup join · ·
│ table pg_constraint@pg_constraint_conrelid_idx
│ equality (oid) = (conrelid)
│ equality cols are key ·
└── filter · ·
│ filter relname = 'foo'
└── virtual table · ·
· table pg_class@primary
· distribution local
· vectorized false
sort · ·
│ order +conname
└── render · ·
└── hash join · ·
│ equality (relnamespace) = (oid)
├── virtual table lookup join · ·
│ │ table pg_constraint@pg_constraint_conrelid_idx
│ │ equality (oid) = (conrelid)
│ └── filter · ·
│ │ filter relname = 'foo'
│ └── virtual table · ·
│ table pg_class@primary
└── filter · ·
│ filter nspname = 'public'
└── virtual table · ·
· table pg_namespace@primary

query TTT
EXPLAIN SHOW USERS
Expand Down

0 comments on commit 4aa891b

Please sign in to comment.