Posts

Showing posts from April, 2024

MySQL Query Analyzer

MySQL Select Query Analyzer Below python script will analyzes an SQL query before executing it.  It provides details such as the number of tables, joins, subqueries,  and unions in the query. Additionally, it retrieves details about  the tables involved in the query, including the table name, index name, column name, non-uniqueness, number of rows, data size, and index size.  The script also displays the MySQL explain plan for the given query.    import sqlparse import pymysql.cursors # Default Test SQL query # sql_query = """ # SELECT # t1.id, t1.name, t2.age # FROM # table1 AS t1 # JOIN # table2 AS t2 ON t1.id = t2.id # WHERE # t1.name = 'John'; # """ # Override default Test SQL query sql_query = input ( "Enter your SQL query: " ) # Parse the SQL query parsed = sqlparse.parse(sql_query)[ 0 ] # Extract table names tables = set () for token in parsed.tokens: if isinstance (token, sqlparse.sql.Ide