IBM DB2 Query Patroller User's Guide

Using QueryEnabler

This section provides an overview of QueryEnabler and the windows that open when you submit a query. Before you can submit a query that will be routed to the DB2 Query Patroller Server, you must ensure that your administrator started the server using the dqpstart command. Only an administrator has the authority to start a DB2 Query Patroller Server. For more information, refer to the DB2 Query Patroller Administration Guide.

When you submit a query from your application, provided that it exceeds the management threshold set up for your user profile by your administrator, the query is trapped by QueryEnabler and routed to the DB2 Query Patroller Server. The DB2 Query Patroller Server will search its job table to see if this query has been submitted before and if results for this query are stored in the DB2 Query Patroller database.

If the DB2 Query Patroller Server cannot find the submitted query in its jobs table, the QueryEnabler: New Query windows opens. If the submitted query exists in the job table, the QueryEnabler: Result Sets window opens.

The following sections describe each window in detail:

Submitting a Query for the First Time

If you are submitting a query for the first time, the QueryEnabler: New Query window opens.

For example, assume that you enter the following commands to create a new query that will select all of the staff members associated with department 20:

   db2 terminate
   db2 connect to sample
   db2 "select * from paulz.staff where dept = 20"

After you enter this command, QueryEnabler will trap the query. Since this query has never been run before, the QueryEnabler: New Query window opens. For example:
Screen capture of the QueryEnabler: New Query window

The query that you submitted is shown in the SQL statement box. From the QueryEnabler: New Query window, you can define submission options for this query and submit it to run immediately or schedule it to run at a different time.

Defining Submission Options for a Query

When you submit a query, you can specify options to redirect the results of the query to a different destination, prioritize the query, or request not to have a cost analysis performed for the query (if your user profile has been given this right). You must define these options before submitting or scheduling the query to run.

If your administrator has set up alternate destinations for the result sets generated by your queries, you can click on the Results destination drop down box and select an alternative destination for the result set of this query.

If there are no alternate destinations for your queries, this field will not be available and will default to Return Results Here. This setting means that a DB2 table will be used to store the result set of your query. If you select this destination, you can grant public access to it so that all users have access to the result set by selecting the Grant PUBLIC access to result set check box.

You can optionally set the priority level of a query by clicking on the Priority drop down box and selecting the appropriate priority level. By default, there are three different priority levels: Low, Normal, and High. These priority levels are defined by the administrator of the DB2 Query Patroller Server. For more information, refer to the DB2 Query Patroller Administration Guide.

By default, the Cost analyze query check box is selected. If your administrator has set up your user profile with the right to optionally request a cost analysis, you can deselect this check box to bypass a cost analysis on the query that you are submitting. For more information, refer to the DB2 Query Patroller Administration Guide.

When a cost analysis is performed, an estimate of the query's cost is generated and compared to the User Threshold value for your user profile. Your administrator determines the user threshold level for each user in a DB2 Query Patroller environment. Only an administrator can change the user threshold defined for a user or group. For more information, refer to the DB2 Query Patroller Administration Guide.

If the estimated cost exceeds the limit set for a user, the query's status is changed to Held. If a job that you submitted is being held, you need to have an administrator or operator change the job's status using in order for the query to run. A job's status can be changed using QueryMonitor. For more information, see Introduction to QueryMonitor.

You can cancel the submission of the query by clicking on Cancel.

After you have defined all of the options for your query, you are ready to submit the query or schedule it to run at a later time. Go to the section that describes when you want to run your query:

Run the Query Immediately

You can select to run the query that you have submitted. To run the submitted query immediately, click on Run Now. The Query in Progress window opens. For example:
Query in Progress window for a query that was selected to run immediately

The query is now under the control of the DB2 Query Patroller Server. The server will run the query as long as the costs associated with the query do not exceed the threshold set by your administrator.

The Query in Progress window displays the status and the elapsed time of the query that you submitted. The status of the running query will be updated in the Query status field. It may take some time for the query to change states as the DB2 Query Patroller Server assigns resources and prioritizes the submitted query.

For example, the query's status may change from Estimating to Scheduled. In the Scheduled state, the query may be held until queries with a higher priority complete. Once the resources become available to run the query, the status will be changed to Running.

To continue running the query and return to your application, click on Release Query. Releasing the query returns control back to the application. The processing of the query still continues and the database on the DB2 Query Patroller Server will be updated with the query's result set.

You may want to release a query if it will take a long time to complete and you will not require the information contained in the result set immediately. If the same query were to be submitted at a later time, the DB2 Query Patroller Server would recognize this query and the QueryEnabler: Result Sets window would open. A user would then have the option to retrieve the result set associated with this query in a timely manner. If a user submitted the same query, a table scan would be run on the result table that was generated to satisfy this query when it was previously submitted.

Typically, an administrator may submit and select to release a number of queries that will be submitted by the users of the data warehouse at a later time. For details on submitting a query that has been previously processed by the DB2 Query Patroller Server, see Submitting a Query that Has Been Previously Submitted.

To cancel the query, click on Cancel.

When the processing of the query completes successfully, the result set is created as a table in the Query Patroller Server's database. If you did not release the query, the result set is returned to the application. For example:

   ID     NAME      DEPT   JOB   YEARS  SALARY    COMM
   ------ --------- ------ ----- ------ --------- ---------
       10 Sanders       20 Mgr        7  18357.50         -
       20 Pernal        20 Sales      8  18171.25    612.45
       80 James         20 Clerk      -  13504.60    128.20
      190 Sneider       20 Clerk      8  14252.75    126.50
 
     4 record(s) selected.

For details on how to monitor any queries that you submitted, see Introduction to QueryMonitor.

Schedule the Query to Run at a Later Time

You can schedule the query that you have submitted to run at a later time using a combination of date and time characteristics. For example, you may want to run the query weekly, every Monday at nine o'clock in the morning. To schedule a query, click on Schedule. The Schedule window opens. For example:
Schedule window for a query

To schedule a query, perform the following steps:

Step  1.

Define when you want this query to run in the Occurs box.

To define the run-time for a query, perform the following steps:

  1. Click on the Interval drop down box and select the interval for the query that you submitted.

    The interval and frequency of a query provide powerful scheduling features that allow you to define when the job is to be submitted. Depending on the interval that you select, the frequency options will change. Using a combination of the interval and frequency characteristics, you can select virtually any schedule for the query.

    Select any of the following intervals:

    One time only

    Specifies that this query is to be run only once.

    For example, the query may seek to verify a hypothesis defined for a static point of time. You may want the query to run once on July 10th, 2000.

    Hourly

    Specifies that this query is to be run on a hourly schedule, with the frequency, start date, and end date of the query.

    For example, the query may seek a relationship between the time of day and the amount of calls received in a call center. You may want to run the query every 12 hours, once in the morning and once in the evening.

    Daily

    Specifies that this query is to be run on a daily schedule, with the frequency, start date, and end date of the query.

    For example, the query may search for a correlation between past due accounts that are 3 days old and accounts that eventually get passed to a collection agency. You may want to run the query every 3 days.

    Weekly

    Specifies that this query is to be run on a weekly schedule, with the frequency, start date, and end date of the query.

    For example, the query may seek to validate the notion that the price of a stock fluctuates on a particular day more than others. You may want to run the query every Tuesday.

    Monthly (Dates)

    Specifies that this query is to be run monthly on a specific date, with the frequency, start date, and end date of the query.

    For example, the query may seek to define a relationship between consumer demand for products in a department store and the date customers receive their credit card bill. You may want to run the query on the 10th day of every month.

    Monthly (Days)

    Specifies that this query is to be run monthly on a specific sequential day in the month, with the frequency, start date, and end date of the query.

    For example, the query may look at the trade volume of a stock on the day its options expire. You may want to run the query on the third Friday of every month.

    Yearly

    Specifies that this query is to be run yearly, with the frequency, start date, and end date of the query.

    For example, the query may compare projected year end results with the actual values at the end of the year. You may want to run the query once every year.

  2. Click on the Frequency drop down box and select the appropriate frequency that will be used in conjunction with the interval level that you selected. Depending on the interval you selected in the Interval drop box, the frequency options will change.

Step  2.

Specify the date and time for which you want the query to be available for run-time, according to the interval and frequency options that you specified above. The date and time that you select is included in the set of possible times when the query can be run.

For example, you may define a query to run on the fourth Tuesday of each month, but may not want this condition to be enforced until after December 10th, 2001. If you specified the start date for this query to be on a fourth Tuesday in a month, it would be included in the schedule for the query.

To define a date, click on the Date field and enter a start date for this query. You can also click on the Date drop down box. A calendar opens that allows you to select a date. For example:
Calendar

To define a time, click on the Time field and enter a start time for this query. You can also use the Time spin button to adjust the time that you want the query to start.

Step  3.

Using the same method that you used in the previous step, specify the date and time that you no longer want the query to be available for run-time, according to the interval and frequency you specified. The date and time that you select is included in the set of possible times when the query can be run.

For example, you may define a query to run on the fourth Tuesday of each month after December 10th, 2001 , but may not want this condition to be enforced after December 10th, 2003.

Step  4.

Click on Add>>. The schedule query is moved to the Schedule list box.

To change a scheduled entry, select a query from the Schedule list box, make any desired changes, and click on Change.

To remove a query from the Schedule list box, select the query and click on Remove.

Step  5.

Click on OK. The query is scheduled to run at the interval, frequency, time, and date that you specified.

You can save a schedule that you defined for a query so that you can import the schedule at a later time and use it with the same query or a different query. This feature saves you the time of redefining often used schedules. To save a schedule, click on Save As. The schedule you defined will be saved as a schedule file, with the extension .cal. To import a defined schedule, click on Import.

Click on Cancel to cancel the scheduling of the query that you selected. You will be returned to the QueryEnabler: New Query window.

For details on how to monitor any queries that you submitted, see Introduction to QueryMonitor.

Submitting a Query that Has Been Previously Submitted

If you are submitting a query that has been submitted in the past and the query is stored in the DB2 Query Patroller Server's job table, QueryEnabler traps the query and the QueryEnabler: Result Sets window opens.

For example, assume that you enter the following commands to submit the same query that you submitted in Submitting a Query for the First Time:

   db2 terminate
   db2 connect to sample
   db2 "select * from paulz.staff where dept = 20"

After you enter this command, the query will be trapped. Since this query has been submitted before, and it exists in the job table on the DB2 Query Patroller Server, the QueryEnabler: Result Sets window opens. For example:
Screen capture of the QueryEnabler: Result Sets window

The query that you submitted is shown in the SQL statement box. From the QueryEnabler: Result Sets window, you can return the result set from a matching query that was submitted in the past, or resubmit the query and specify different submission options, or schedule it to run at a different time.

Typically, you would want to resubmit your query if the data that this query was run against has changed. For example, if you were running a query against your data warehouse to try and determine a target market for a particular product, and the data warehouse was updated with new demographic data after the original query was run, you may want to resubmit your query to leverage the updated data.

You can cancel the query that you submitted by clicking on Cancel. You can also cancel a job that is in progress. If the state of the query is Estimating, Scheduled, or Queued, you can select the job from the Select a job to return results from box, click on the right-mouse button, and select the Cancel option. Cancelling a query that has already been submitted is usually done using QueryMonitor.

To return the result set associated with this query to your application, select a job that was submitted at an acceptable time from the Select a job to return results from box and click on Return Results Now.

The Select a job to return results from box contains a list of all the jobs that contain the same query and have been submitted in the past. Jobs that completed successfully contain a time-related result set of your query based on the data in your data warehouse. Keep in mind that as the data warehouse is updated, the data in the result set may change or become out of date. When data isn't current and causes inferences that are not correct, it is often referred to as dirty. If you feel that a result set may have data that has become dirty, you can select the previously submitted job, click on the right-mouse button, and select the Drop Results option to drop the result set associated with the job.

After you click on Return Results Now, the results of your query are returned to your application. For example:

   ID     NAME      DEPT   JOB   YEARS  SALARY    COMM
   ------ --------- ------ ----- ------ --------- ---------
       10 Sanders       20 Mgr        7  18357.50         -
       20 Pernal        20 Sales      8  18171.25    612.45
       80 James         20 Clerk      -  13504.60    128.20
      190 Sneider       20 Clerk      8  14252.75    126.50
 
     4 record(s) selected.

If you want to resubmit your query, click on Submit as New Query. The QueryEnabler: New Query window opens. For more information, see Submitting a Query for the First Time.

For details on how to monitor any queries that you submitted, see Introduction to QueryMonitor.


[ Top of Page | Previous Page | Next Page ]