Commit f63eea0
committed
fix(postgres): schema-qualify the primary-key subquery in getTableColumns
The PK subquery joined tc.constraint_name = ku.constraint_name and filtered on
ku.table_name alone, with no schema predicate anywhere. Postgres auto-names
primary keys "<table>_pkey", so two schemas holding a same-named table collide
by construction — the join cross-matches them.
Measured against two schemas each with an `orders` table (s_a's PK is `other`,
s_b's is `name`), asking for s_b.orders:
column_name | is_primary_key
name | t
name | t <- duplicated row
other | t <- false positive: `other` is s_a's PK, not s_b's
other | t <- duplicated row
Ground truth from pg_index: s_b.orders has exactly one PK column, `name`. So the
provider reported every column as a primary key and returned each one twice —
duplicate ColumnInfo entries, and a table with no real single PK. Adding
tc.table_schema = ku.table_schema and ku.table_schema = ? returns the correct
`name | t`, `other | f`.
This predates the search_path change and was mostly latent while the provider
only ever read `public`: a collision needed some other schema to hold a
same-named table. Now that it targets whatever the session resolves to, that is
no longer the exception — staging/marts/public each holding `orders` or
`customers` is the normal shape of the dbt warehouse this change was made for.
So the earlier commit does not introduce this bug, but it does move it from
unlikely to expected, which is why it is fixed on the same branch.
Also hoists resolveSchema() out of the argument list: this method runs once per
table, and each call costs a round-trip.
Tests: 12/12. A mocked ResultSet cannot exercise SQL semantics, so the new test
asserts the two schema predicates are present and that every placeholder is
bound — enough to stop the qualification being dropped again. The correctness
evidence is the measurement above, run against Postgres 18.1 parent 2a23bc4 commit f63eea0
2 files changed
Lines changed: 64 additions & 4 deletions
File tree
- backend/src
- main/java/com/dbaagent/provider/postgres
- test/java/com/dbaagent/provider/postgres
Lines changed: 32 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
159 | 179 | | |
160 | 180 | | |
161 | 181 | | |
162 | 182 | | |
163 | 183 | | |
164 | 184 | | |
165 | 185 | | |
166 | | - | |
167 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
168 | 191 | | |
169 | 192 | | |
170 | 193 | | |
171 | 194 | | |
172 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
173 | 200 | | |
174 | 201 | | |
175 | | - | |
176 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
177 | 205 | | |
178 | 206 | | |
179 | 207 | | |
| |||
Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
201 | 233 | | |
202 | 234 | | |
203 | 235 | | |
| |||
0 commit comments