DATABASE

Using MySQL Enterprise (part 3) - Query Analyzer

12/20/2011 5:43:44 PM

4. Query Analyzer

The newest feature of MySQL Enterprise is the Query Analyzer. Savvy administrators have long known of the standalone Query Analyzer for MySQL, but until recently it was not integrated into the Enterprise tools.

The Query Analyzer works by intercepting SQL commands using MySQL Proxy and processing them, then passing them on to the local server for execution. This allows it to record statistics so that you can view them at any time. The Query Analyzer also supports advisors that fire alerts for slow queries. Figure 10 shows a conceptual drawing of how MySQL Proxy intercepts queries and reports the statistics to the MEM.

Figure 10. Using MySQL Proxy to collect data for Query Analyzer



Note:

The Query Analyzer runs over the user-defined port 6446 (by default) and can introduce some performance delay. Thus, you should enable it only when you are searching for problems.


To collect data for the Query Analyzer, you must direct your client to connect to the MySQL Proxy port and configure the agent to use port 6446. Be sure you can connect to this port if you do not see any queries reported in the Enterprise Dashboard.

While it is possible for MySQL Proxy to introduce some minor delays in query execution throughput times, the benefits of analyzing poorly running queries more than pay for the delays. You may want to use the Query Analyzer only on certain development or experimental machines rather than on your live production servers. One nice thing about the Query Analyzer and the Enterprise Dashboard is the tight integration among the tools. If you have an alert about a slow query or drill down into a CPU utilization report or other MySQL-based statistic, you will see the Query Analyzer page (which you can also access directly by clicking the Query Analyzer tab). Figure 11 shows an example of the Query Analyzer page on the Enterprise Dashboard.

Figure 11. Query Analyzer display


The Query Analyzer page displays a list of servers on the left. You can click a specific server to see a list of queries executed on that server, sorted by longest running query. You can also use the chart at the top to narrow the time window to see queries during a specific time period.

You can sort the list on any column by clicking the column heading. This makes it a bit easier to see repetitive queries and diagnostics by sorting the rows with the longest-running queries at the top, showing the query statement, the amount of data manipulated, etc.

You can click any row to get a more detailed report on the query. Figure 12 shows a sample canonical query report. As with the other reports, you can get more detailed information, including the actual query on the Example Query tab, the output of the EXPLAIN command on the Explain Query tab (if you enabled that option), and graphs for execution time, number of executions, and number of rows returned on the Graphs tab.

Figure 12. Canonical query report


This report presents details of the query captured, including the canonical form of the query (a pictorial representation of the query as it was written), details of its execution including time taken, and rows returned or affected.

Once again, we see a monitoring tool that will save you a considerable amount of time diagnosing problems with MySQL. The Query Analyzer component of the MySQL Enterprise tools is a vital monitoring tool that will help you keep your servers running well and your queries executing efficiently.

MySQL Enterprise and Cloud Computing

The MySQL Enterprise tools can also function well in a cloud computing environment. The same rules apply, however, regarding the persistence of the data and server instances. Just be sure to request a persistent IP address for your MEM server. Repeatedly starting and stopping your instances will cause no ill effects, but changing hostnames and some types of reconfiguration can cause the monitoring agents to stop reporting. Typically, truncating the mysql.inventory table solves this, but it is best to use the same hostnames and IP addresses for all of your servers.

There is one excellent benefit of running MySQL Enterprise tools in a commercial provider’s cloud: you pay only for computation and storage space. Data transfer within the cloud is usually free or much less than shipping data in and out of the cloud.


Other  
  •  Using MySQL Enterprise (part 2) - Monitoring
  •  Using MySQL Enterprise (part 1) - Installation & Fixing Monitoring Agent Problems
  •  Getting Started with MySQL Enterprise & MySQL Enterprise Components
  •  Transact-SQL in SQL Server 2008 : Table-Valued Parameters
  •  Transact-SQL in SQL Server 2008 : New date and time Data Types and Functions
  •  Defensive Database Programming with SQL Server : When Snapshot Isolation Breaks Code
  •  Protecting SQL Server Data : SCHEMA ARCHITECTURE STRATEGIES - Using Views
  •  Creating and Managing Views in SQL Server 2008 : Indexed Views
  •  Transact-SQL in SQL Server 2008 : Row Constructors
  •  Transact-SQL in SQL Server 2008 : GROUP BY Clause Enhancements
  •  Creating and Managing Views in SQL Server 2008 : Partitioned Views
  •  Creating and Managing Views in SQL Server 2008 : Managing Views, Data Modifications and Views
  •  Creating and Managing Views in SQL Server 2008 : Creating Views
  •  Creating and Managing Views in SQL Server 2008 : Definition of Views & Using Views
  •  Transact-SQL in SQL Server 2008 : Insert over DML
  •  Transact-SQL in SQL Server 2008 : MERGE Statement
  •  SQL Server 2008 : Transact-SQL Programming - The TABLESAMPLE Clause
  •  SQL Server 2008 : Transact-SQL Programming - TRY...CATCH Logic for Error Handling
  •  SQL Server 2008 : Transact-SQL Programming - The APPLY Operator
  •  SQL Server 2008 : Transact-SQL Programming - PIVOT and UNPIVOT
  •  
    Top 10
    The ASP.NET AJAX Infrastructure
    C# 4.0 : Add a Constructor
    Preparing Multimedia Data for Silverlight
    SQL Azure : Managing a Shard (part 1) - Managing Exceptions & Managing Performance
    Exchange Server 2010 server roles (part 3) - Edge Transport Server role
    Identifying the Technical Goals and Objectives to Implement Windows Server 2008 R2
    Configuring Windows 7 NIC Devices (part 2) - Configuring Wireless NIC Devices
    Monitoring a SharePoint 2010 Environment : Using SharePoint’s Native Reporting Capabilities
    Implementing Client Access and Hub Transport Servers : Installing the Client Access Server
    Web Server Access Control Permissions in IIS 7
    Most View
    Leveraging and Optimizing Search in SharePoint 2010 : Federating Search
    iPhone Application Development : Building a Multi-View Tab Bar Application (part 1)
    Exchange Server 2010 : Administering Mailbox Content - Monitor and Restrict Communication (part 2) - Apply Common Monitoring and Restriction Scenarios
    Managing Installed and Running Programs in Vista
    Sharepoint 2010 : Deploying Transport-Level Security for SharePoint
    Examining Exchange Server 2010 Performance Improvements
    iPhone Application Development : Creating and Managing Image Animations and Sliders (part 3) - Finishing the Interface
    Understanding Active Directory Certificate Services (AD CS) in Windows Server 2008 R2
    .NET security : Isolated Storage Explained
    Programming Excel with VBA and .NET : Variables (part 4) - User-Defined Types & Objects
    Windows Phone 7 Development : Building a Phone Client to Access a Cloud Service (part 1) - Building the User Interface
    Programming with DirectX : Textures in Direct3D 10 (part 2)
    C# 4.0 : Add a Static Constructor and Initialization
    Windows Server 2003 : Managing User Profiles
    SQL Server 2008 : Working with DML Queries - Using the MERGE Statement
    Windows Server 2003 : Working with Resultant Set of Policy (part 2)
    Windows Phone 7 Development : Push Notifications - Implementing Cloud Service to Track Push Notifications
    Windows 7 : Managing Security
    Xen Virtualization : Installing Xen from Binary Packages
    Design and Deploy High Availability for Exchange 2007 : Create Bookmark Create Note or Tag Implement Standby Continuous Replication (SCR)