Duckdb source code reading

less than 1 minute read

Published:

In this blog, I will introduce the brief architecture of duckdb and show the solution of debugging.

1. Build and deployment

1.1 Download the source code

1.2 Debugging

2. Brief execution procedure

Queries first enter in the main function in shell.cpp, the incompleted call chain can be represented as ProcessInput -> ExecuteSQL -> PendingQuery.

shared_ptr<PreparedStatementData>
ClientContext::CreatePreparedStatementInternal(ClientContextLock &lock, const string &query,
                                               unique_ptr<SQLStatement> statement,
                                               optional_ptr<case_insensitive_map_t<BoundParameterData>> values) {
  // ...
  Planner logical_planner(*this);
	if (values) {
		auto &parameter_values = *values;
		for (auto &value : parameter_values) {
			logical_planner.parameter_data.emplace(value.first, BoundParameterData(value.second));
		}
	}

	logical_planner.CreatePlan(std::move(statement));
  
	// ...
  
  PhysicalPlanGenerator physical_planner(*this);
	result->physical_plan = physical_planner.Plan(std::move(logical_plan));
  
  // ...
}