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.
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
./mysql_visual_explain_cli explain.json explain.png
./mysql_visual_explain_cli explain.json explain.svg
mysql --raw --skip-column-names -e "EXPLAIN FORMAT=JSON SELECT * FROM INFORMATION_SCHEMA.COLUMNS;" | ./mysql_visual_explain_cli - columns_explained.png
PNG | SVG |
---|---|
The MySQL Workbench Python code calls Cairo C directly via FFI instead of the more common Pycairo library, thus this project depends on CairoCFFI
The following C functions appear to have been patched compared to what is distributed with modern Debian distributions.
cairo.cairo_text_extents()
cairo.cairo_set_dash()
The version of Python bundled with MySQL Workbench also seems to perform implicit str
to byte
conversion.
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.