Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Clarify Lazy API / Query plan
Browse files Browse the repository at this point in the history
  • Loading branch information
aglebov committed Jun 22, 2023
1 parent f806f74 commit 5110859
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/src/python/user-guide/lazy/query_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
.with_columns(pl.col("name").str.to_uppercase())
.filter(pl.col("comment_karma") > 0)
)
q1.show_graph(optimized=False)
# --8<-- [end:plan]

# --8<-- [start:createplan]
Expand Down
17 changes: 10 additions & 7 deletions docs/user-guide/lazy/query_plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ We can understand both the non-optimized and optimized query plans with visualiz

### Graphviz visualization

First we visualise the non-optimized plan by setting `optimized=False`.

{{code_block('user-guide/lazy/query_plan','plan',['show_graph'])}}

<div style="display:none">
```python exec="on" result="text" session="user-guide/lazy/query_plan"
--8<-- "python/user-guide/lazy/query_plan.py:setup"
--8<-- "python/user-guide/lazy/query_plan.py:plan"
```
</div>

First we visualise the non-optimized plan by setting `optimized=False`.

{{code_block('user-guide/lazy/query_plan','plan',['show_graph'])}}

```python exec="on" session="user-guide/lazy/query_plan"
--8<-- "python/user-guide/lazy/query_plan.py:createplan"
```
Expand All @@ -36,7 +35,11 @@ The query plan visualisation should be read from bottom to top. In the visualisa

We can also print the non-optimized plan with `explain(optimized=False)`

{{code_block('user-guide/lazy/query_plan','plan',['explain'])}}
{{code_block('user-guide/lazy/query_plan','describe',['explain'])}}

```python exec="on" session="user-guide/lazy/query_plan"
--8<-- "python/user-guide/lazy/query_plan.py:describe"
```

```text
FILTER [(col("comment_karma")) > (0)] FROM WITH_COLUMNS:
Expand Down Expand Up @@ -82,4 +85,4 @@ The optimized plan is to:
- apply the filter on the `comment_karma` column while the CSV is being read line-by-line
- transform the `name` column to uppercase

In this case the query optimizer has identified that the `filter` can be applied while the CSV is read from disk rather than writing the whole file to disk and then applying it. This optimization is called *Predicate Pushdown*.
In this case the query optimizer has identified that the `filter` can be applied while the CSV is read from disk rather than reading the whole file into memory and then applying the filter. This optimization is called *Predicate Pushdown*.

0 comments on commit 5110859

Please sign in to comment.