Skip to content

Latest commit

 

History

History
47 lines (29 loc) · 2.31 KB

README.md

File metadata and controls

47 lines (29 loc) · 2.31 KB

MySQL Visual Explain CLI

MySQL Workbench comes with a Visual Explain feature that is written in Python using Cairo. This project simply extracts that code and provides a minimalist CLI for it.

Since Cairo supports both PNG and SVG, with only a few line changes, I was able to add support for SVG. However, due to the fact that underlying code vectorizes input text, the SVG output is generally larger than PNG output.

Usages

Install

Provided releases are Python 3 zipapp.

sudo apt-get install python3-cairocffi

curl -L https://github.com/leonyu/mysql-visual-explain-cli/releases/latest/download/mysql_visual_explain_cli.pyz -o ./mysql_visual_explain_cli
chmod +x ./mysql_visual_explain_cli

Convert JSON Explain file to PNG/SVG

./mysql_visual_explain_cli explain.json explain.png
./mysql_visual_explain_cli explain.json explain.svg

Pipe EXPLAIN Output from MySQL

mysql --raw --skip-column-names -e "EXPLAIN FORMAT=JSON SELECT * FROM INFORMATION_SCHEMA.COLUMNS;" | ./mysql_visual_explain_cli - columns_explained.png

Example Outputs

PNG SVG
PNG example SVG example

Notes

The MySQL Workbench Python code calls Cairo C ABI via SWIG bindings, thus this project depends on CairoCFFI which provides a similar facility via FFI.

MySQL Workbench uses Swig typemap to wrap some C functions so the function signatures exposed are more Pythonic. Those wrapped functions with different APIs include cairo.cairo_text_extents() and cairo.cairo_set_dash(). The Swig typemap also performed str to byte conversion for the Python code. These changes have to be unpatched in this project.

License

This project is a derivative work of MySQL Workbench which is GPLv2. Meaning unless I have money for a lawyer, it will forever be GPLv2 as well.