Commit bb84596
authored
feat(analyzer): Analyze queries using a running PostgreSQL database (#2805)
* feat(analyzer): Analyze queries using a running PostgreSQL database
94 of the open issues on sqlc are related to the analyzer. There are
many cases where the current analyzer produces false positives or
false negatives.
sqlx and some other projects have proven that it's possible to extract
query metadata from a running database.
This approach is a bit different, in that the database analysis is
layered on top of the existing query analyzer. We use the new analysis
to provide better type information and support a wider set of cases when
the existing analyzer fails.
* test(analyzer): Update endtoend tests for new analyzer
Add a `contexts` key to exec.json to opt certain tests into or out of
database-backed analysis.
Fix many incorrect test cases that didn't run against an actual
database.1 parent 4b7fddd commit bb84596
File tree
478 files changed
+4422
-996
lines changed- examples
- authors
- booktest
- jets
- ondeck
- internal
- analyzer
- cmd
- codegen/golang
- compiler
- config
- endtoend
- testdata
- alias/postgresql/stdlib
- coalesce_as/postgresql
- pganalyze
- go
- pgx
- v4
- v5
- stdlib
- codegen_json
- codegen_struct_field_names/stdlib/go
- cte_left_join
- postgresql/pgx
- go
- cte_multiple_alias
- postgresql/pgx
- go
- cte_recursive_employees
- postgresql/pgx
- go
- cte_recursive_star
- postgresql/pgx
- go
- cte_select_one
- postgresql/pgx
- go
- cte_with_in/postgresql/pganalyze
- go
- diff_output
- enum/postgresql
- pgx
- v4
- go
- v5
- go
- stdlib
- go
- func_aggregate
- pganalyze
- go
- postgresql
- go
- func_call_cast/postgresql
- pgx
- v4
- go
- v5
- go
- stdlib
- go
- func_match_types/postgresql
- go
- func_return_date/postgresql
- pganalyze
- go
- pgx/v5
- go
- stdlib
- go
- func_return_series/postgresql
- pgx
- v4
- go
- v5
- go
- stdlib
- go
- func_return/postgresql
- pgx
- v4
- go
- v5
- go
- stdlib
- go
- func_variadic/postgresql/stdlib
- go
- insert_select_invalid/postgresql
- pgx
- v4
- stderr
- v5
- stderr
- stdlib
- stderr
- insert_select_param
- postgresql/pgx
- go
- insert_values_only
- postgresql/pgx
- go
- interval
- pgx
- v4
- v5
- stdlib
- invalid_func_args
- pgx
- v4
- stderr
- v5
- stderr
- stdlib
- stderr
- invalid_group_by_reference/postgresql
- stderr
- invalid_insert_unknown_column
- postgresql/pgx
- db
- invalid_params_type_mismatch
- postgresql/pgx
- invalid_params
- pgx
- v4
- stderr
- v5
- stderr
- stdlib
- stderr
- invalid_queries_bar
- pgx
- v4
- stderr
- v5
- stderr
- stdlib
- stderr
- invalid_queries_foo
- pgx
- v4
- v5
- stdlib
- invalid_table_alias/postgresql
- stderr
- invalid_update_unknown_column
- postgresql/pgx
- join_left/postgresql
- join_validate_columns
- postgresql/pgx
- json_param_type
- postgresql/pgx
- go
- limit
- pgx
- v4
- v5
- stdlib
- missing_semicolon
- pgx
- v4
- v5
- stdlib
- mix_param_types/postgresql
- nested_select
- postgresql/pgx
- go
- null_if_type
- postgresql
- pganalyzer
- db
- stdlib
- db
- operator_string_concat/postgresql
- pgx
- v4
- go
- v5
- go
- stdlib
- go
- order_by_binds
- pganalyze
- go
- postgresql
- order_by_non_existing_column
- mysql
- postgresql
- stderr
- sqlite
- params_location/postgresql
- pgx
- v4
- v5
- stdlib
- params_placeholder_in_left_expr/postgresql
- pg_dump
- pg_generate_series/postgresql
- pgx
- v4
- go
- v5
- go
- stdlib
- go
- pointer_type_import/postgresql/pgx/v5
- process_plugin_sqlc_gen_json
- query_parameter_limit/-1/python_postgresql
- relation_does_not_exist/postgresql
- stderr
- select_limit/postgresql
- pgx
- v4
- v5
- stdlib
- select_union/postgres
- pgx
- v4
- v5
- stdlib
- single_param_conflict/postgresql
- pgx
- v4
- go
- v5
- go
- stdlib
- go
- sqlc_arg_invalid
- mysql
- postgresql
- sqlite
- strict_function_checks/postgresql
- stderr
- sum_type
- postgresql/pgx
- go
- table_function/postgresql
- pgx
- v4
- go
- v5
- go
- stdlib
- go
- unknown_func
- pganalyze
- pgx
- v4
- v5
- stdlib
- unnest_star
- postgresql/pgx
- go
- update_set_on_conflict
- postgresql/pgx
- valid_group_by_reference
- pganalyzer
- go
- postgresql
- go
- engine/postgresql/analyzer
- sql
- named
- validate
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
478 files changed
+4422
-996
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
| |||
21 | 24 | | |
22 | 25 | | |
23 | 26 | | |
24 | | - | |
| 27 | + | |
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
103 | 104 | | |
| 105 | + | |
| 106 | + | |
104 | 107 | | |
105 | 108 | | |
106 | 109 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
200 | | - | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
201 | 204 | | |
202 | 205 | | |
203 | 206 | | |
| |||
219 | 222 | | |
220 | 223 | | |
221 | 224 | | |
222 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
223 | 230 | | |
224 | 231 | | |
225 | 232 | | |
| |||
234 | 241 | | |
235 | 242 | | |
236 | 243 | | |
237 | | - | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
238 | 249 | | |
239 | 250 | | |
240 | 251 | | |
| |||
277 | 288 | | |
278 | 289 | | |
279 | 290 | | |
280 | | - | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
281 | 296 | | |
282 | 297 | | |
283 | 298 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
16 | | - | |
17 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
143 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
144 | 147 | | |
145 | 148 | | |
146 | 149 | | |
| |||
343 | 346 | | |
344 | 347 | | |
345 | 348 | | |
346 | | - | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
347 | 355 | | |
348 | 356 | | |
349 | 357 | | |
| |||
0 commit comments