vmware-archive / quickstep

Quickstep Project
Apache License 2.0
27 stars 13 forks source link

Visualize the optimized physical plan in DOT format #232

Closed jianqiao closed 8 years ago

jianqiao commented 8 years ago

This PR adds an initial support for visualizing the query plans.

Currently it will print the final physical plan in DOT format by setting the flag -visualize_plan to true, e.g.

./quickstep_cli_shell -visualize_plan=true

Then the graph description of each query's plan will be printed via stderr.

For example, the output for query

SELECT SUM(x * y)
FROM generate_series(1, 10, 2) AS gs1(x),
     generate_series(1, 10, 3) AS gs2(y)
WHERE x = y;

should be:

digraph g {
  rankdir=BT
  node [penwidth=2]
  edge [fontsize=16 fontcolor=gray penwidth=2]

  5 [label="TableGenerator
est. # = 4
est. Selectivity = 1.000000"]
  6 [label="TableGenerator
est. # = 5
est. Selectivity = 1.000000"]
  4 [label="HashJoin
gs2 = gs1
est. # = 6
est. Selectivity = 1.000000" style=filled fillcolor="red"]
  3 [label="Aggregate
est. # = 1
est. Selectivity = 1.000000"]
  2 [label="Selection
est. # = 1
est. Selectivity = 1.000000" style=filled fillcolor="#90EE90"]
  1 [label="TopLevelPlan
est. # = 1
est. Selectivity = 1.000000"]

  5 -> 4 [label="gs2"]
  6 -> 4 [label="gs1"]
  4 -> 3 [label="x
y"]
  3 -> 2 [label="$aggregate0"]
  2 -> 1 [label="SUM((x*y))"]
}

+--------------------+
|SUM((x*y))          |
+--------------------+
|                  50|
+--------------------+
...

To convert the DOT description into a real image. A quick way is to use online visualization tools (e.g. http://www.webgraphviz.com). Just copy and paste the graph description into the webpage's textbox and click Generate Graph!.

Or we can dump the DOT description into a file with command:

./quickstep_cli_shell -visualize_plan=true < some_query.sql 2> some_graph.dot

Then use the dot tool to generate the real image:

dot -Gsize="8,10.5" -Teps some_graph.dot -o some_graph.eps

Here eps can be pdf, png, etc.

pateljm commented 8 years ago

LGTM. Merging.