# Query execution
source: https://docs.chalk.ai/docs/chalkdf/query-execution

## Inspect a logical plan and materialize its result locally.

### Inspect the plan

Call [`explain_logical()`](/dataframe-docs#DataFrame.explain_logical) on an intermediate frame to inspect the columns and operations that lead to its result. Read the plan from its input at the bottom to its final operation at the top.

```python
import pyarrow as pa
from chalk import _
from chalkdf import DataFrame

tx = DataFrame({"user": ["a", "a", "b"], "amount": [12, 8, 30]})

query = tx.filter(_.amount >= 10).select("user", "amount")
pa.table({"logical_plan": query.explain_logical().splitlines()})
```

| logical_plan · `string` |
| --- |
| #0 Project (projections=['user':user, 'amount':amount]) |
| └── #1 Filter (mask=gte(amount, 10)) |
|     └── #2 ValuesNode (num_batches=1, num_rows=3) |

### Materialize the rows

Request the result after inspecting the plan.

```python
query.run()
```

| user · `string` | amount · `int64` |
| --------------- | ---------------- |
| a               | 12               |
| b               | 30               |

To inspect the plan selected for execution, call [`query.explain_physical()`](/dataframe-docs#DataFrame.explain_physical).

### Work with the result

Save [`result = query.run()`](/dataframe-docs#DataFrame.run) to reuse the materialized rows. For a Python consumer that accepts Arrow, use [`query.to_arrow()`](/dataframe-docs#DataFrame.to_arrow). Each request to execute a lazy frame can run its plan again.

### Named table inputs

Use [`DataFrame.named_table`](/dataframe-docs#DataFrame.named_table) to build a plan before its rows arrive. Declare the input schema once, then supply each batch under the same name. If your batch is already a ChalkDF frame, pass its Arrow table to [`run(tables=...)`](/dataframe-docs#DataFrame.run).

```python
schema = pa.schema([("id", pa.string()), ("amount", pa.int32())])
orders = DataFrame.named_table("orders", schema)
large_orders = orders.filter(_.amount >= 10)

batch = DataFrame({"id": ["001", "002"], "amount": pa.array([8, 30], type=pa.int32())})
large_orders.run(tables={"orders": batch.to_arrow()})
```

| id · `string` | amount · `int32` |
| ------------- | ---------------- |
| 002           | 30               |

See [`DataFrame.explain_logical`](/dataframe-docs#DataFrame.explain_logical), [`DataFrame.explain_physical`](/dataframe-docs#DataFrame.explain_physical), [`DataFrame.run`](/dataframe-docs#DataFrame.run), [`DataFrame.to_arrow`](/dataframe-docs#DataFrame.to_arrow).

To submit the same plan to a worker and retrieve its results, see [Run Remotely](/docs/chalkdf/remote-execution).





