cmu-db / peloton

The Self-Driving Database Management System
http://pelotondb.io
Apache License 2.0
2.03k stars 623 forks source link

EXPLAIN handle push down #1350

Open ChTimTsubasa opened 6 years ago

ChTimTsubasa commented 6 years ago

The way #1108 add support to EXPLAIN is to extract the explained statement directly from query string at protocol handler layer, which is not the best place to handle EXPLAIN for 2 reasons:

  1. Pointed out by @nappelson, #1108 only support EXPLAIN for Postgres Simple Protocol and would fail Postgres Extended Protocol used by JDBC. This is because Optimizer does not support handling EXPLAIN.

  2. Protocol handler should only handle logic to protocol-specific things such as packet format serializing and deserializing. This is also true for PREPARE and EXECUTE, which would be pushed down too in a later fix.

The correct way to do this is to push down the logic on optimizer and let it identify the special statements and report to traffic_cop and traffic_cop should schedule special treatments to those plans.

apavlo commented 6 years ago

What if we just made a special ExplainExecutor that just generates the plan string and then outputs that as a single tuple?

chenboy commented 6 years ago

We just looked at Postgres and found they handle all utility commands in the traffic cop, I'm not quite sure why they do it this way though.

ChTimTsubasa commented 6 years ago

I would say one reason they do that in this way is that utility queries would touch some of the frontend components during execution. For example, EXPLAIN would need optimizer, PREPARE and EXECUTE would need plan cache (Statement Cache in our system)

ChTimTsubasa commented 6 years ago

Utility commands are all executed in https://github.com/postgres/postgres/blob/master/src/backend/tcop/utility.c#L337 While general commands are executed in https://github.com/postgres/postgres/blob/master/src/backend/executor/execMain.c