Skip to content

Commit

Permalink
Don't add newlines and indentation when deparsing query (#173)
Browse files Browse the repository at this point in the history
Without this change our query deparsing logic adds newlines and
indentation to the query it sends to DuckDB. While you might expect this
to be a nice thing for debugging it actually makes debugging harder in
many common cases.

A major one is that it results in very little context being provided by
DuckDB if a query fails, because it only shows the failing line of the
query and even very simple queries are split into multiple lines by
`PRETTYFLAG_INDENT`. See the changed tests for the improvement in this
area.

Also in EXPLAIN ANALYZE the query actually gets more unreadable because
DuckDB seems to strip newlines from the query there, but still keeps
indentation. So now there's a bunch of weird whitespace being added.

Before:

```
> explain analyze select b, b, b from a;
                                              QUERY PLAN
──────────────────────────────────────────────────────────────────────────────────────────────────────
 Custom Scan (DuckDBScan)  (cost=0.00..0.00 rows=0 width=0) (actual time=2.033..2.102 rows=1 loops=1)
   DuckDB Execution Plan:

 ┌─────────────────────────────────────┐
 │┌───────────────────────────────────┐│
 ││    Query Profiling Information    ││
 │└───────────────────────────────────┘│
 └─────────────────────────────────────┘
 EXPLAIN ANALYZE  SELECT b,     b,     b    FROM a
```

After:

```
> explain analyze select b, b, b from a;
                                              QUERY PLAN
──────────────────────────────────────────────────────────────────────────────────────────────────────
 Custom Scan (DuckDBScan)  (cost=0.00..0.00 rows=0 width=0) (actual time=2.047..2.115 rows=1 loops=1)
   DuckDB Execution Plan:

 ┌─────────────────────────────────────┐
 │┌───────────────────────────────────┐│
 ││    Query Profiling Information    ││
 │└───────────────────────────────────┘│
 └─────────────────────────────────────┘
 EXPLAIN ANALYZE SELECT b, b, b FROM a
```
  • Loading branch information
JelteF authored Sep 12, 2024
1 parent 957a8bc commit d62ba97
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/vendor/pg_ruleutils_16.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
/* Standard conversion of a "bool pretty" option to detailed flags */
#define GET_PRETTY_FLAGS(pretty) \
((pretty) ? (PRETTYFLAG_PAREN | PRETTYFLAG_INDENT | PRETTYFLAG_SCHEMA) \
: PRETTYFLAG_INDENT)
: 0)

/* Default line length for pretty-print wrapping: 0 means wrap always */
#define WRAP_COLUMN_DEFAULT 0
Expand Down
2 changes: 1 addition & 1 deletion src/vendor/pg_ruleutils_17.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
/* Standard conversion of a "bool pretty" option to detailed flags */
#define GET_PRETTY_FLAGS(pretty) \
((pretty) ? (PRETTYFLAG_PAREN | PRETTYFLAG_INDENT | PRETTYFLAG_SCHEMA) \
: PRETTYFLAG_INDENT)
: 0)

/* Default line length for pretty-print wrapping: 0 means wrap always */
#define WRAP_COLUMN_DEFAULT 0
Expand Down
4 changes: 2 additions & 2 deletions test/regression/expected/execution_error.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ insert into int_as_varchar SELECT * from (
) t(a);
select a::INTEGER from int_as_varchar;
ERROR: Duckdb execute returned an error: Conversion Error: Could not convert string 'abc' to INT32
LINE 1: SELECT (a)::integer AS a
^
LINE 1: SELECT (a)::integer AS a FROM int_as_varchar
^
4 changes: 2 additions & 2 deletions test/regression/expected/views.out
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ create view vw2 as select * from "s.t";
select * from vw1, vw2;
WARNING: (DuckDB) Binder Error: Referenced table "t" not found!
Candidate tables: "s.t"
LINE 3: FROM ( SELECT t."?column?"
^
LINE 1: ...?column?", vw2."?column?" FROM (SELECT t."?column?" FROM s.t) vw1, (SELECT "s....
^
?column? | ?column?
----------+----------
21 | 42
Expand Down

0 comments on commit d62ba97

Please sign in to comment.