Rule-Based SQL Performance Analyzer built with Java Swing, JDBC, and MySQL
QueryLens is a desktop developer tool that helps identify inefficient SQL queries through static rule-based analysis and MySQL execution-plan inspection. It detects common SQL anti-patterns, assigns performance scores, recommends indexes, suggests safer query rewrites, tracks query history, and exports results to CSV.
Writing inefficient SQL queries can significantly impact application performance, especially as database size grows. QueryLens was built to help developers identify and understand common SQL performance issues before they become production bottlenecks.
Instead of executing complex optimizations automatically, QueryLens analyzes SQL queries using a rule-based engine, explains potential performance problems, recommends improvements, and visualizes execution statistics through an interactive desktop interface.
The application combines static SQL analysis with MySQL's EXPLAIN command to provide actionable recommendations that help developers write cleaner and more efficient SQL.
- Detects common SQL anti-patterns using a modular rule engine.
- Assigns a performance score (0β100) based on detected issues.
- Categorizes findings by severity (Low, Medium, High, Critical).
- Provides detailed optimization recommendations for each detected issue.
SELECT *detectionDELETEwithoutWHEREUPDATEwithoutWHEREORDER BYwithoutLIMITDISTINCTusage analysisSELECTwithoutWHEREorLIMIT- Multiple
ORcondition detection NOT INoptimization detectionUNIONvsUNION ALL- Leading wildcard
LIKE '%value' COUNT(*)optimization analysis- Functions applied on filtered columns
- Executes SQL queries using JDBC.
- Measures execution time for every query.
- Displays query type automatically.
- Shows rows returned.
- Generates execution plans using MySQL
EXPLAIN.
- Suggests indexes based on:
WHEREclausesJOINconditionsORDER BYGROUP BY
Example:
CREATE INDEX idx_employees_department_salary
ON employees(department, salary);Suggests safer and more efficient SQL rewrites, including:
- Replacing
SELECT *with explicit column names. - Suggesting
LIMITfor sorted result sets. - Recommending
UNION ALLwhen duplicate elimination is unnecessary. - Highlighting inefficient filtering patterns.
- Stores executed queries.
- Tracks execution time.
- Records performance score.
- Displays execution status.
- Calculates dashboard statistics.
Displays:
- Total Queries Executed
- Average Execution Time
- Average Performance Score
- Highest Score
- Lowest Score
- Export query results to CSV.
- Suitable for reporting and further analysis.
- Dark One Dark UI
- SQL syntax highlighting
- Query history
- Rounded modern interface
- Keyboard shortcut:
- Ctrl + Enter (Windows/Linux)
- β + Enter (macOS)
The primary workspace combines the SQL editor, dashboard, query results, and analyzer into a single interface.
Automatically detects inefficient SQL patterns, assigns a performance score, and provides optimization recommendations.
Generates and displays MySQL execution plans using the EXPLAIN command to help understand query execution.
Analyzes filtering and sorting operations to recommend indexes that can improve query performance.
Suggests cleaner and more efficient SQL statements following optimization best practices.
Maintains a history of executed queries along with execution time, score, and status.
QueryLens follows a layered architecture to keep the user interface, business logic, and database operations independent and maintainable.
+----------------------+
| MainFrame |
+----------+-----------+
|
+--------------------+--------------------+
| |
ConnectionPanel EditorPanel
| |
+--------------------+--------------------+
|
QueryExecutor
|
+----------------+----------------+
| |
SuggestionService HistoryService
|
+-----------+-----------+
| | |
Rule Engine Index Advisor Query Rewriter
|
Individual SQL Rules
|
+--------------------------------------+
| |
Static SQL Analysis MySQL EXPLAIN
| |
+-------------------+------------------+
|
MySQL Database
Responsible for all user interactions.
- Main application window
- SQL editor
- Result table
- Dashboard
- History dialog
- Connection manager
Implements the application's business logic.
- Executes SQL queries
- Performs SQL analysis
- Generates optimization suggestions
- Maintains query history
- Calculates dashboard statistics
Analyzes SQL statements using independent optimization rules.
Each rule is isolated into its own class, making the analyzer easy to extend without modifying existing code.
Communicates with MySQL using JDBC.
Supports:
- Query execution
- EXPLAIN plans
- Metadata retrieval
QueryLens uses a modular rule-based engine to analyze SQL queries before execution. Each optimization rule is implemented as an independent class that follows a common interface, making the analyzer easy to extend and maintain.
User SQL Query
β
βΌ
SuggestionService
β
βΌ
Iterate through all SQL Rules
β
βββββββββββββββββββΌββββββββββββββββββ
β β β
βΌ βΌ βΌ
SelectStarRule OrderByRule DeleteWithoutWhereRule
β β β
βββββββββββββββββββΌββββββββββββββββββ
β
Collect Rule Violations
β
βΌ
Calculate Performance Score
β
βΌ
Generate Suggestions
β
βΌ
Display in Analyzer
| Rule | Purpose |
|---|---|
| SelectStarRule | Detects SELECT * usage |
| DeleteWithoutWhereRule | Prevents accidental full-table deletion |
| UpdateWithoutWhereRule | Detects unsafe updates |
| OrderByWithoutLimitRule | Identifies expensive sorting |
| DistinctRule | Suggests reviewing unnecessary duplicate removal |
| SelectWithoutWhereRule | Detects unrestricted data retrieval |
| MultipleOrRule | Identifies excessive OR conditions |
| NotInRule | Suggests alternative filtering approaches |
| UnionRule | Recommends UNION ALL when appropriate |
| LeadingWildcardLikeRule | Detects non-index-friendly LIKE patterns |
| CountRule | Reviews COUNT(*) usage |
| FunctionOnColumnRule | Detects functions applied to filtered columns |
Every query starts with a score of 100.
Each detected issue deducts points based on its impact.
Example:
| Issue | Penalty |
|---|---|
| SELECT * | -15 |
| ORDER BY without LIMIT | -10 |
| Multiple OR conditions | -10 |
| Function on indexed column | -15 |
Final score:
100
-15
-10
-10
------------
65 / 100
The final score is classified into severity levels:
| Score | Severity |
|---|---|
| 90β100 | π’ Low |
| 70β89 | π‘ Medium |
| 40β69 | π High |
| 0β39 | π΄ Critical |
| Category | Technologies |
|---|---|
| Language | Java 21 |
| Desktop UI | Java Swing |
| SQL Editor | RSyntaxTextArea |
| Layout Manager | MigLayout |
| Database | MySQL 8 |
| Database Connectivity | JDBC |
| Build Tool | Maven |
| CSV Export | OpenCSV |
| Version Control | Git & GitHub |
| IDE | IntelliJ IDEA Community Edition |
QueryLens
β
βββ screenshots/ # README screenshots
β
βββ src
β βββ main
β β βββ java
β β β βββ com.rishika.sqlanalyzer
β β β βββ model
β β β βββ rules
β β β βββ service
β β β βββ database
β β β βββ ui
β β β βββ util
β β β βββ Main.java
β β β
β β βββ resources
β β βββ icons
β β βββ themes
β
βββ pom.xml
βββ README.md
βββ LICENSE
- Java 21 or later
- Maven
- MySQL Server 8+
- IntelliJ IDEA (recommended)
git clone https://github.com/<rishika150>/QueryLens.gitcd QueryLensmvn clean installmvn exec:javaOr simply open the project in IntelliJ IDEA and run:
Main.java
- Launch the application.
- Connect to a MySQL database.
- Write or paste an SQL query.
- Execute the query using the Execute button or Ctrl/β + Enter.
- Review:
- Performance Score
- Rule Violations
- Index Recommendations
- Query Rewrite Suggestions
- Execution Plan (EXPLAIN)
- Export results to CSV if required.
- View previously executed queries in the Query History dashboard.
The current version focuses on rule-based SQL analysis and query optimization. Future versions may include:
- Query formatting and beautification
- Visual execution plan graphs
- Support for PostgreSQL and SQL Server
- User-defined custom SQL rules
- AI-assisted optimization suggestions
- Query comparison and benchmarking
- Query favorites and saved workspaces
- Dashboard analytics with charts
- Export reports to PDF
- Plugin-based rule engine for third-party extensions
This project is licensed under the MIT License. See the LICENSE file for details.
Rishika Sharan
- B.Tech CSE (AI), Indira Gandhi Delhi Technical University for Women (IGDTUW)
- GitHub: https://github.com/rishika150
- LinkedIn: https://www.linkedin.com/in/rishika-sharan-9a3786292/
If you found this project useful, consider giving it a β on GitHub.





