Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to strip literal values out of SQL to correctly identify db workload?

Does anyone know of any code or tools that can strip literal values out of SQL statements?

The reason for asking is I want to correctly judge the SQL workload in our database and I'm worried I might miss out on bad statements whose resource usage get masked because they are displayed as separate statements. When, in reality, they are pretty much the same thing except for different IDs being passed in.

I'd prefer a database independent solution if any exists. I had thought there might be a nifty Perl module for this but I haven't found any.

Thanks for your help.

like image 952
Mark S Avatar asked Oct 18 '08 20:10

Mark S


People also ask

What is SQL Server Query Optimizer?

The Query Optimizer analyzes different ways the source tables can be accessed. It then selects the series of steps that return the results fastest while using fewer resources. The query tree is updated to record this exact series of steps. The final, optimized version of the query tree is called the execution plan.

How do I find the most CPU consuming queries in SQL Server?

If you want to find the top 'n' queries that are currently in the cache, which are consuming more CPU, then you are at the right place. sys. dm_exec_query_stats DMV contains all the information about the resource (CPU, Memory, I/O) consuming queries that are currently in the cache.


2 Answers

SQL::Statement, in particular the SQL::Statement::Structure module, will let you parse and manipulate SQL statements. The subset of SQL syntax it understands can be seen here.

In a related note, there's DBI::Profile to help with your performance analysis.

like image 192
Schwern Avatar answered Oct 02 '22 10:10

Schwern


If you use JDBC or something like thar your SQL shouldn't have any literals, just '?' marking where they should be.

like image 23
John Nilsson Avatar answered Oct 02 '22 09:10

John Nilsson