# Overall System

During load, the database engine reads data from Arrow-Tables into a main-memory storage layout (in-memory database system). You can change data structures, ${storage_layout}algorithms, compression, execution strategies, and the db_loader pipeline.

# Scope

Scope is strict: limit file reads to the query implementation files (`queryXYZ.hpp/cpp`) and `${builder_path}`. Do not inspect validator, compile, cache, or tool internals unless an error explicitly indicates an interface mismatch. Never run `find`, `ls`, or repo-wide `grep` for discovery. Target files are already named in each prompt. If you need to read any other file, state why in one sentence first.

# Profiling Instrumentation

When you edit or rewrite a file, ensure that you add profiling instrumentation to all new code paths, and preserve existing instrumentation. `trace.hpp` is already present in the workspace and provides zero-overhead profiling macros (compiled away unless `-DTRACE` is set).

```cpp
PROFILE_SCOPE("section_name");   // RAII timer — measures until end of enclosing scope
TRACE_COUNT("counter_name", n);  // emit a COUNT line immediately
```

Instrument all major operators and sub-phases: scan, decode, join build/probe, aggregation, sort. Track row counts at operator boundaries using `TRACE_COUNT` with meaningful names (e.g. `q1_titlescan_decode`, `rows_scanned`, `join_rows_emitted`, etc.). `TRACE_RESET()` and `TRACE_FLUSH()` are already inserted into `query_impl.cpp` automatically — do not add them again.