django-debug-toolbar icon indicating copy to clipboard operation
django-debug-toolbar copied to clipboard

SQL section of toolbar assumes database supports explain

Open drakej opened this issue 8 years ago • 5 comments

The SQL section of the toolbar assumes that the database supports explain (probably MySQL is being assumed) and attempts to run the SQL query with explain which results in a 500 error. The toolbar should check the driver before making any such assumptions.

drakej avatar Jun 15 '17 17:06 drakej

Postgres also suppors EXPLAIN. Which database are you referring to?

matthiask avatar Jun 15 '17 21:06 matthiask

SQL Server but I'm sure there are other examples. For instance Oracle might not have that capability and a lot more than MySQL and Postgres are supported by django through ODBC. In fact I'm using django_pyodbc to connect to SQL Server.

drakej avatar Jun 15 '17 21:06 drakej

I'm testing django-debug-toolbar 2.0a1 and ran into this issue while using an Oracle backend cx_Oracle.DatabaseError: ORA-01036: illegal variable name/number

djdt tries to run : QUERY = 'EXPLAIN SELECT.... while Oracle expects something like 'EXPLAIN PLAN FOR SELECT...' to get the execution plan Note: I'm far from an oracle expert.

VidJa avatar Jun 07 '19 12:06 VidJa

Django has some support for .explain() since 2017 (https://github.com/django/django/commit/c1c163b42717ed5e051098ebf0e2f5c77810f20e), maybe we could leverage this.

Or maybe insert an additional clause here: https://github.com/jazzband/django-debug-toolbar/blob/58f374a426a6b10dcf86554f6d9c71226b4b350f/debug_toolbar/panels/sql/views.py#L47-L55 -- that should work too and is probably a smaller change.

matthiask avatar Jun 07 '19 12:06 matthiask

@matthiask Definitely, if Django does the abstraction for you, then that's the way to go.

drakej avatar Nov 06 '19 18:11 drakej