Slow Response in INNER query
Posted in 2013
On Informix 10 (AIX 5.3), a COUNT(*) on table1 filtered by UID > (SELECT MAX(UID) FROM table2) took 4 minutes, while the same query with a hard-coded literal UID value ran in half a second. Suggestions: fetch MAX(UID) separately into a variable (tried in an SPL procedure, but it got worse — 10+ minutes), note that UID is a CHAR column, and run SET EXPLAIN ON to compare query plans plus proper UPDATE STATISTICS/distributions on both tables (table2 had none; MEDIUM alone on table1 may be insufficient), e.g. via dostats. The poster said he would try this; no resolution is recorded in the thread.
Auto-generated by DrWatson from the posts below — may be imperfect; read the full thread.
Topics: Platform-Specific Issues
Hello everyone,
We are using Informix 10 UC5 on AIX 5.3 and facing following issue:
################################################################################
###############
## QUERY-1 - BELOW QUERY TAKES 4 MINUTES TO EXECUTES WHEN TABLE2 CONTAINS ONLY
SINGLE RECORD
################################################################################
###############
select count(*) from table1
where UID>(select max(UID) from table2)
and response='00'
and txntype in ('FT', 'Bal')
and card like '123456%';
###############################################################
## QUERY-2 - BELOW QUERY TAKES HALF OF A SECOND TO EXECUTES
###############################################################
select count(*) from table1
where UID>'123456789012'
and response='00'
and txntype in ('FT', 'Bal')
and card like '123456%';
We need to tune QUERY-1 as my production deployment is dependent on this. I
would be thankful if anyone can help me on this.
Thanks in advance.
Regards,
Navaid Arif
Hi Navaid,
How long it takes to run "select max(UID) from table2" ?
My suggestion is, you should first run the "select max(UID) from table2) "
separately and
then use the value of MAX(UID) in your another query i.e. UID > ??????????????.
This could be a variable or a temp table..
The reason I suggest this is, the "MAX(UID) will be the same as there is no
other
WHERE clause in your INNER query...and you should be running the MAX for every
row fetched from outer SELECT ...
Regards,
Dharmendra
> To: ids@iiug.org
> From: navaid.arif@access.net.pk
> Subject: Slow Response in INNER query [31547]
> Date: Mon, 30 Sep 2013 12:02:38 -0400
>
> Hello everyone,
> We are using Informix 10 UC5 on AIX 5.3 and facing following issue:
>
>
>
################################################################################
###############
> ## QUERY-1 - BELOW QUERY TAKES 4 MINUTES TO EXECUTES WHEN TABLE2 CONTAINS
ONLY
> SINGLE RECORD
>
>
################################################################################
###############
> select count(*) from table1
> where UID>(select max(UID) from table2)
> and response='00'
> and txntype in ('FT', 'Bal')
> and card like '123456%';>
> ###############################################################
> ## QUERY-2 - BELOW QUERY TAKES HALF OF A SECOND TO EXECUTES
> ###############################################################
> select count(*) from table1
> where UID>'123456789012'
> and response='00'
> and txntype in ('FT', 'Bal')
> and card like '123456%';>
> We need to tune QUERY-1 as my production deployment is dependent on this. I
> would be thankful if anyone can help me on this.
>
> Thanks in advance.
>
> Regards,
> Navaid Arif
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
Questions:
- Have you run the two queries under SET EXPLAIN ON to see the
differences in the query plans?
- What indexes are there on table1 and table2?
- Are the data distributions (UPDATE STATISTICS MEDIUM/HIGH) up-to-date
on both tables?
Art
Art S. Kagel, Principal Consultant
Advanced DataTools (www.advancedatatools.com)
Blog: http://informix-myview.blogspot.com/
Disclaimer: Please keep in mind that my own opinions are my own opinions
and do not reflect on my employer, Advanced DataTools, the IIUG, nor any
other organization with which I am associated either explicitly,
implicitly, or by inference. Neither do those opinions reflect those of
other individuals affiliated with any entity with which I am affiliated nor
those of the entities themselves.
On Mon, Sep 30, 2013 at 12:02 PM, NAVAID ARIF <navaid.arif@access.net.pk>wrote:
> Hello everyone,
> We are using Informix 10 UC5 on AIX 5.3 and facing following issue:
>
>
>
>
################################################################################
###############
> ## QUERY-1 - BELOW QUERY TAKES 4 MINUTES TO EXECUTES WHEN TABLE2 CONTAINS
> ONLY
> SINGLE RECORD
>
>
>
################################################################################
###############
> select count(*) from table1
> where UID>(select max(UID) from table2)
> and response='00'
> and txntype in ('FT', 'Bal')
> and card like '123456%';>
> ###############################################################
> ## QUERY-2 - BELOW QUERY TAKES HALF OF A SECOND TO EXECUTES
> ###############################################################
> select count(*) from table1
> where UID>'123456789012'
> and response='00'
> and txntype in ('FT', 'Bal')
> and card like '123456%';>
> We need to tune QUERY-1 as my production deployment is dependent on this. I
> would be thankful if anyone can help me on this.
>
> Thanks in advance.
>
> Regards,
> Navaid Arif
>
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
--089e0158b8781795e704e79c32a6
Hi Art,
No, I have not used SET EXPLAIN ON option. I do not know how to use it.
On table1, we have INDEXES on two columns i.e. UID and CARD.
UPDATE STATISTICS is MEDIUM on table1. I have not used UPDATE STATISTICS on
table2 (if it is using it internally, I am not sure about it)
Regards,
Navaid Arif
-----Original Message-----
From: ids-bounces@iiug.org [mailto:ids-bounces@iiug.org] On Behalf Of Art
Kagel
Sent: Monday, 30 September, 2013 9:19 PM
To: ids@iiug.org
Subject: Re: Slow Response in INNER query [31549]
Questions:
- Have you run the two queries under SET EXPLAIN ON to see the
differences in the query plans?
- What indexes are there on table1 and table2?
- Are the data distributions (UPDATE STATISTICS MEDIUM/HIGH) up-to-date
on both tables?
Art
Art S. Kagel, Principal Consultant
Advanced DataTools (www.advancedatatools.com)
Blog: http://informix-myview.blogspot.com/
Disclaimer: Please keep in mind that my own opinions are my own opinions
and do not reflect on my employer, Advanced DataTools, the IIUG, nor any
other organization with which I am associated either explicitly,
implicitly, or by inference. Neither do those opinions reflect those of
other individuals affiliated with any entity with which I am affiliated nor
those of the entities themselves.
On Mon, Sep 30, 2013 at 12:02 PM, NAVAID ARIF
<navaid.arif@access.net.pk>wrote:
> Hello everyone,
> We are using Informix 10 UC5 on AIX 5.3 and facing following issue:
>
>
>
>
############################################################################
###################
> ## QUERY-1 - BELOW QUERY TAKES 4 MINUTES TO EXECUTES WHEN TABLE2 CONTAINS
> ONLY
> SINGLE RECORD
>
>
>
############################################################################
###################
> select count(*) from table1
> where UID>(select max(UID) from table2)
> and response='00'
> and txntype in ('FT', 'Bal')
> and card like '123456%';>
> ###############################################################
> ## QUERY-2 - BELOW QUERY TAKES HALF OF A SECOND TO EXECUTES
> ###############################################################
> select count(*) from table1
> where UID>'123456789012'
> and response='00'
> and txntype in ('FT', 'Bal')
> and card like '123456%';>
> We need to tune QUERY-1 as my production deployment is dependent on this.
I
> would be thankful if anyone can help me on this.
>
> Thanks in advance.
>
> Regards,
> Navaid Arif
>
>
>
>
****************************************************************************
***
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
--089e0158b8781795e704e79c32a6
****************************************************************************
***
Forum Note: Use "Reply" to post a response in the discussion forum.
Not sure why my last email didn't go through....resending...
From: dharmendrasharma@hotmail.com
To: ids@iiug.org
Subject: RE: Slow Response in INNER query [31547]
Date: Mon, 30 Sep 2013 09:16:17 -0700
Hi Navaid,
How long it takes to run "select max(UID) from table2" ?
My suggestion is, you should first run the "select max(UID) from table2) "
separately and
then use the value of MAX(UID) in your another query i.e. UID > ??????????????.
This could be a variable or a temp table..
The reason I suggest this is, the "MAX(UID) will be the same as there is no
other
WHERE clause in your INNER query...and you should be running the MAX for every
row fetched from outer SELECT ...
Regards,
Dharmendra
> To: ids@iiug.org
> From: navaid.arif@access.net.pk
> Subject: Slow Response in INNER query [31547]
> Date: Mon, 30 Sep 2013 12:02:38 -0400
>
> Hello everyone,
> We are using Informix 10 UC5 on AIX 5.3 and facing following issue:
>
>
>
################################################################################
###############
> ## QUERY-1 - BELOW QUERY TAKES 4 MINUTES TO EXECUTES WHEN TABLE2 CONTAINS
ONLY
> SINGLE RECORD
>
>
################################################################################
###############
> select count(*) from table1
> where UID>(select max(UID) from table2)
> and response='00'
> and txntype in ('FT', 'Bal')
> and card like '123456%';>
> ###############################################################
> ## QUERY-2 - BELOW QUERY TAKES HALF OF A SECOND TO EXECUTES
> ###############################################################
> select count(*) from table1
> where UID>'123456789012'
> and response='00'
> and txntype in ('FT', 'Bal')
> and card like '123456%';>
> We need to tune QUERY-1 as my production deployment is dependent on this. I
> would be thankful if anyone can help me on this.
>
> Thanks in advance.
>
> Regards,
> Navaid Arif
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
So, you use SET EXPLAIN to get a query plan. Just run the following in
dbaccess:
SET EXPLAIN ON;<your query or queries>
SET EXPLAIN OFF:
You will find a file named sqexplain.out (NOT sqlexplain.out!) either in
your current directory if you are logged into the server or in your home
directory on the server if you are connected to the server remotely. In
there will be an description of the query plans for the two versions of the
query you presumably ran (with and without the sub-query). It might also
be good to also run the sub-query separately to see if the query plan for
it is different as a stand-alone select. If you post the output here to
the forum, someone will help you if you can't interpret it yourself.
As far as the statistics, just running MEDIUM on the whole table isn't
usually good enough. Look at the Informix Performance Guide discussion of
the recommended update statistics protocols to use to get sufficiently
detailed data distributions for a table with minimal work. As to table #2,
if you have not run stats yourself, then Informix version 10.00 will not
run them for you (that wasn't included until v11.10 and later with the
introduction of Auto Update Statistics - AUS).
Without well detailed data distributions the optimizer will often make poor
choices for its query plans. You can either run the suite of commands
recommended in the performance guide yourself, or download my package
utils2_ak from the IIUG Software Repository and compile and use the
dostats.ec utility in that package which implements the recommended
protocol along with many useful options. Dostats has become the standard
bearer of how to run update statistics properly.
Art
Art S. Kagel, Principal Consultant
Advanced DataTools (www.advancedatatools.com)
Blog: http://informix-myview.blogspot.com/
Disclaimer: Please keep in mind that my own opinions are my own opinions
and do not reflect on my employer, Advanced DataTools, the IIUG, nor any
other organization with which I am associated either explicitly,
implicitly, or by inference. Neither do those opinions reflect those of
other individuals affiliated with any entity with which I am affiliated nor
those of the entities themselves.
On Mon, Sep 30, 2013 at 1:46 PM, Navaid Arif <navaid.arif@access.net.pk>wrote:
> Hi Art,
> No, I have not used SET EXPLAIN ON option. I do not know how to use it.
>
> On table1, we have INDEXES on two columns i.e. UID and CARD.
>
> UPDATE STATISTICS is MEDIUM on table1. I have not used UPDATE STATISTICS on
> table2 (if it is using it internally, I am not sure about it)>
> Regards,
> Navaid Arif
>
> -----Original Message-----
> From: ids-bounces@iiug.org [mailto:ids-bounces@iiug.org] On Behalf Of Art
> Kagel
> Sent: Monday, 30 September, 2013 9:19 PM
> To: ids@iiug.org
> Subject: Re: Slow Response in INNER query [31549]
>
> Questions:
>
> - Have you run the two queries under SET EXPLAIN ON to see the
>
> differences in the query plans?
>
> - What indexes are there on table1 and table2?
>
> - Are the data distributions (UPDATE STATISTICS MEDIUM/HIGH) up-to-date
>
> on both tables?
>
> Art
>
> Art S. Kagel, Principal Consultant
>
> Advanced DataTools (www.advancedatatools.com)
> Blog: http://informix-myview.blogspot.com/
>
> Disclaimer: Please keep in mind that my own opinions are my own opinions
> and do not reflect on my employer, Advanced DataTools, the IIUG, nor any
> other organization with which I am associated either explicitly,
> implicitly, or by inference. Neither do those opinions reflect those of
> other individuals affiliated with any entity with which I am affiliated nor
> those of the entities themselves.
>
> On Mon, Sep 30, 2013 at 12:02 PM, NAVAID ARIF
> <navaid.arif@access.net.pk>wrote:
>
> > Hello everyone,
> > We are using Informix 10 UC5 on AIX 5.3 and facing following issue:
> >
> >
> >
> >
>
> ############################################################################
> ###################
> > ## QUERY-1 - BELOW QUERY TAKES 4 MINUTES TO EXECUTES WHEN TABLE2 CONTAINS
> > ONLY
> > SINGLE RECORD
> >
> >
> >
>
> ############################################################################
> ###################
> > select count(*) from table1
> > where UID>(select max(UID) from table2)
> > and response='00'
> > and txntype in ('FT', 'Bal')
> > and card like '123456%';> >
> > ###############################################################
> > ## QUERY-2 - BELOW QUERY TAKES HALF OF A SECOND TO EXECUTES
> > ###############################################################
> > select count(*) from table1
> > where UID>'123456789012'
> > and response='00'
> > and txntype in ('FT', 'Bal')
> > and card like '123456%';> >
> > We need to tune QUERY-1 as my production deployment is dependent on this.
> I
> > would be thankful if anyone can help me on this.
> >
> > Thanks in advance.
> >
> > Regards,
> > Navaid Arif
> >
> >
> >
> >
>
> ****************************************************************************
> ***
> > Forum Note: Use "Reply" to post a response in the discussion forum.
> >
> >
>
> --089e0158b8781795e704e79c32a6
>
>
> ****************************************************************************
> ***
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
--001a11c29b44ec755204e79db0a8
Hi Dharmendra,
We tried this but it became more bad by taking 10+ minutes rather than
becoming faster.
CREATE PROCEDURE proc_ tst()
DEFINE myUID CHAR(14);
SELECT UID into myUID from table2;
INSERT INTO table3
SELECT * from table1
where UID > myUID
and response='00'
and txntype in ('FT', 'Bal')
and card like '123456%';
END PROCEDURE;
Regards,
Navaid Arif
-----Original Message-----
From: ids-bounces@iiug.org [mailto:ids-bounces@iiug.org] On Behalf Of
Dharmendra Sharma
Sent: Monday, 30 September, 2013 10:57 PM
To: ids@iiug.org
Subject: RE: Slow Response in INNER query [31551]
Not sure why my last email didn't go through....resending...
From: dharmendrasharma@hotmail.com
To: ids@iiug.org
Subject: RE: Slow Response in INNER query [31547]
Date: Mon, 30 Sep 2013 09:16:17 -0700
Hi Navaid,
How long it takes to run "select max(UID) from table2" ?
My suggestion is, you should first run the "select max(UID) from table2) "
separately and
then use the value of MAX(UID) in your another query i.e. UID >
??????????????.
This could be a variable or a temp table..
The reason I suggest this is, the "MAX(UID) will be the same as there is no
other
WHERE clause in your INNER query...and you should be running the MAX for
every
row fetched from outer SELECT ...
Regards,
Dharmendra
> To: ids@iiug.org
> From: navaid.arif@access.net.pk
> Subject: Slow Response in INNER query [31547]
> Date: Mon, 30 Sep 2013 12:02:38 -0400
>
> Hello everyone,
> We are using Informix 10 UC5 on AIX 5.3 and facing following issue:
>
>
>
############################################################################
###################
> ## QUERY-1 - BELOW QUERY TAKES 4 MINUTES TO EXECUTES WHEN TABLE2 CONTAINS
ONLY
> SINGLE RECORD
>
>
############################################################################
###################
> select count(*) from table1
> where UID>(select max(UID) from table2)
> and response='00'
> and txntype in ('FT', 'Bal')
> and card like '123456%';
>
> ###############################################################
> ## QUERY-2 - BELOW QUERY TAKES HALF OF A SECOND TO EXECUTES
> ###############################################################
> select count(*) from table1
> where UID>'123456789012'
> and response='00'
> and txntype in ('FT', 'Bal')
> and card like '123456%';
>
> We need to tune QUERY-1 as my production deployment is dependent on this.
I
> would be thankful if anyone can help me on this.
>
> Thanks in advance.
>
> Regards,
> Navaid Arif
>
>
>
****************************************************************************
***
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
****************************************************************************
***
Forum Note: Use "Reply" to post a response in the discussion forum.
Hi Navaid,
It looks like the UID is a character column ...Wow!! that might be causing an
issue i.e. running MAX on char column.
I never tried this and therefore can't say for sure..
May be you need to explore other options, like use another integer field from
table2 to detect the max of that
record and then get and use that value..I would suggest to break your queries
and find out which one is taking
a long time..i.e. the one running on table2 (MAX) or the one running on table1
UID > ????..
Regards,
Dharmendra
> To: ids@iiug.org
> From: navaid.arif@access.net.pk
> Subject: RE: Slow Response in INNER query [31554]
> Date: Mon, 30 Sep 2013 14:16:47 -0400
>
> Hi Dharmendra,
>
> We tried this but it became more bad by taking 10+ minutes rather than
> becoming faster.
>
> CREATE PROCEDURE proc_ tst()>
> DEFINE myUID CHAR(14);
>
> SELECT UID into myUID from table2;
>
> INSERT INTO table3>
> SELECT * from table1>
> where UID > myUID
>
> and response='00'
>
> and txntype in ('FT', 'Bal')
>
> and card like '123456%';
>
> END PROCEDURE;
>
> Regards,
>
> Navaid Arif
>
> -----Original Message-----
> From: ids-bounces@iiug.org [mailto:ids-bounces@iiug.org] On Behalf Of
> Dharmendra Sharma
> Sent: Monday, 30 September, 2013 10:57 PM
> To: ids@iiug.org
> Subject: RE: Slow Response in INNER query [31551]
>
> Not sure why my last email didn't go through....resending...
>
> From: dharmendrasharma@hotmail.com
>
> To: ids@iiug.org
>
> Subject: RE: Slow Response in INNER query [31547]
>
> Date: Mon, 30 Sep 2013 09:16:17 -0700
>
> Hi Navaid,
>
> How long it takes to run "select max(UID) from table2" ?
>
> My suggestion is, you should first run the "select max(UID) from table2) "
>
> separately and
>
> then use the value of MAX(UID) in your another query i.e. UID >
>
> ??????????????.
>
> This could be a variable or a temp table..
>
> The reason I suggest this is, the "MAX(UID) will be the same as there is no
>
> other
>
> WHERE clause in your INNER query...and you should be running the MAX for
> every
>
> row fetched from outer SELECT ...
>
> Regards,
>
> Dharmendra
>
> > To: ids@iiug.org
>
> > From: navaid.arif@access.net.pk
>
> > Subject: Slow Response in INNER query [31547]
>
> > Date: Mon, 30 Sep 2013 12:02:38 -0400
>
> >
>
> > Hello everyone,
>
> > We are using Informix 10 UC5 on AIX 5.3 and facing following issue:
>
> >
>
> >
>
> >
>
> ############################################################################
> ###################
>
> > ## QUERY-1 - BELOW QUERY TAKES 4 MINUTES TO EXECUTES WHEN TABLE2 CONTAINS
>
> ONLY
>
> > SINGLE RECORD
>
> >
>
> >
>
> ############################################################################
> ###################
>
> > select count(*) from table1>
> > where UID>(select max(UID) from table2)
>
> > and response='00'
>
> > and txntype in ('FT', 'Bal')
>
> > and card like '123456%';
>
> >
>
> > ###############################################################
>
> > ## QUERY-2 - BELOW QUERY TAKES HALF OF A SECOND TO EXECUTES
>
> > ###############################################################
>
> > select count(*) from table1>
> > where UID>'123456789012'
>
> > and response='00'
>
> > and txntype in ('FT', 'Bal')
>
> > and card like '123456%';
>
> >
>
> > We need to tune QUERY-1 as my production deployment is dependent on this.
> I
>
> > would be thankful if anyone can help me on this.
>
> >
>
> > Thanks in advance.
>
> >
>
> > Regards,
>
> > Navaid Arif
>
> >
>
> >
>
> >
>
> ****************************************************************************
> ***
>
> > Forum Note: Use "Reply" to post a response in the discussion forum.
>
> >
>
> ****************************************************************************
> ***
>
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
Hi Dharmendra,
Yes, you are absolutely correct, UID is a character column. Please note that
we are not using max(UID) in the PROCEDURE and using it like "select UID
from table2" but still the results are same.
Query running on table1 is taking more time.
Regards,
Navaid Arif
-----Original Message-----
From: ids-bounces@iiug.org [mailto:ids-bounces@iiug.org] On Behalf Of
Dharmendra Sharma
Sent: Monday, 30 September, 2013 11:53 PM
To: ids@iiug.org
Subject: RE: Slow Response in INNER query [31555]
Hi Navaid,
It looks like the UID is a character column ...Wow!! that might be causing
an
issue i.e. running MAX on char column.
I never tried this and therefore can't say for sure..
May be you need to explore other options, like use another integer field
from
table2 to detect the max of that
record and then get and use that value..I would suggest to break your
queries
and find out which one is taking
a long time..i.e. the one running on table2 (MAX) or the one running on
table1
UID > ????..
Regards,
Dharmendra
> To: ids@iiug.org
> From: navaid.arif@access.net.pk
> Subject: RE: Slow Response in INNER query [31554]
> Date: Mon, 30 Sep 2013 14:16:47 -0400
>
> Hi Dharmendra,
>
> We tried this but it became more bad by taking 10+ minutes rather than
> becoming faster.
>
> CREATE PROCEDURE proc_ tst()
>
> DEFINE myUID CHAR(14);
>
> SELECT UID into myUID from table2;
>
> INSERT INTO table3
>
> SELECT * from table1
>
> where UID > myUID
>
> and response='00'
>
> and txntype in ('FT', 'Bal')
>
> and card like '123456%';
>
> END PROCEDURE;
>
> Regards,
>
> Navaid Arif
>
> -----Original Message-----
> From: ids-bounces@iiug.org [mailto:ids-bounces@iiug.org] On Behalf Of
> Dharmendra Sharma
> Sent: Monday, 30 September, 2013 10:57 PM
> To: ids@iiug.org
> Subject: RE: Slow Response in INNER query [31551]
>
> Not sure why my last email didn't go through....resending...
>
> From: dharmendrasharma@hotmail.com
>
> To: ids@iiug.org
>
> Subject: RE: Slow Response in INNER query [31547]
>
> Date: Mon, 30 Sep 2013 09:16:17 -0700
>
> Hi Navaid,
>
> How long it takes to run "select max(UID) from table2" ?
>
> My suggestion is, you should first run the "select max(UID) from table2) "
>
> separately and
>
> then use the value of MAX(UID) in your another query i.e. UID >
>
> ??????????????.
>
> This could be a variable or a temp table..
>
> The reason I suggest this is, the "MAX(UID) will be the same as there is
no
>
> other
>
> WHERE clause in your INNER query...and you should be running the MAX for
> every
>
> row fetched from outer SELECT ...
>
> Regards,
>
> Dharmendra
>
> > To: ids@iiug.org
>
> > From: navaid.arif@access.net.pk
>
> > Subject: Slow Response in INNER query [31547]
>
> > Date: Mon, 30 Sep 2013 12:02:38 -0400
>
> >
>
> > Hello everyone,
>
> > We are using Informix 10 UC5 on AIX 5.3 and facing following issue:
>
> >
>
> >
>
> >
>
>
############################################################################
> ###################
>
> > ## QUERY-1 - BELOW QUERY TAKES 4 MINUTES TO EXECUTES WHEN TABLE2
CONTAINS
>
> ONLY
>
> > SINGLE RECORD
>
> >
>
> >
>
>
############################################################################
> ###################
>
> > select count(*) from table1
>
> > where UID>(select max(UID) from table2)
>
> > and response='00'
>
> > and txntype in ('FT', 'Bal')
>
> > and card like '123456%';
>
> >
>
> > ###############################################################
>
> > ## QUERY-2 - BELOW QUERY TAKES HALF OF A SECOND TO EXECUTES
>
> > ###############################################################
>
> > select count(*) from table1
>
> > where UID>'123456789012'
>
> > and response='00'
>
> > and txntype in ('FT', 'Bal')
>
> > and card like '123456%';
>
> >
>
> > We need to tune QUERY-1 as my production deployment is dependent on
this.
> I
>
> > would be thankful if anyone can help me on this.
>
> >
>
> > Thanks in advance.
>
> >
>
> > Regards,
>
> > Navaid Arif
>
> >
>
> >
>
> >
>
>
****************************************************************************
> ***
>
> > Forum Note: Use "Reply" to post a response in the discussion forum.
>
> >
>
>
****************************************************************************
> ***
>
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
>
****************************************************************************
***
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
****************************************************************************
***
Forum Note: Use "Reply" to post a response in the discussion forum.
Thank you Art, I will try it shortly and let you know. :)
Regards,
Navaid Arif
-----Original Message-----
From: ids-bounces@iiug.org [mailto:ids-bounces@iiug.org] On Behalf Of Art
Kagel
Sent: Monday, 30 September, 2013 11:06 PM
To: ids@iiug.org
Subject: Re: Slow Response in INNER query [31553]
So, you use SET EXPLAIN to get a query plan. Just run the following in
dbaccess:
SET EXPLAIN ON;<your query or queries>
SET EXPLAIN OFF:
You will find a file named sqexplain.out (NOT sqlexplain.out!) either in
your current directory if you are logged into the server or in your home
directory on the server if you are connected to the server remotely. In
there will be an description of the query plans for the two versions of the
query you presumably ran (with and without the sub-query). It might also
be good to also run the sub-query separately to see if the query plan for
it is different as a stand-alone select. If you post the output here to
the forum, someone will help you if you can't interpret it yourself.
As far as the statistics, just running MEDIUM on the whole table isn't
usually good enough. Look at the Informix Performance Guide discussion of
the recommended update statistics protocols to use to get sufficiently
detailed data distributions for a table with minimal work. As to table #2,
if you have not run stats yourself, then Informix version 10.00 will not
run them for you (that wasn't included until v11.10 and later with the
introduction of Auto Update Statistics - AUS).
Without well detailed data distributions the optimizer will often make poor
choices for its query plans. You can either run the suite of commands
recommended in the performance guide yourself, or download my package
utils2_ak from the IIUG Software Repository and compile and use the
dostats.ec utility in that package which implements the recommended
protocol along with many useful options. Dostats has become the standard
bearer of how to run update statistics properly.
Art
Art S. Kagel, Principal Consultant
Advanced DataTools (www.advancedatatools.com)
Blog: http://informix-myview.blogspot.com/
Disclaimer: Please keep in mind that my own opinions are my own opinions
and do not reflect on my employer, Advanced DataTools, the IIUG, nor any
other organization with which I am associated either explicitly,
implicitly, or by inference. Neither do those opinions reflect those of
other individuals affiliated with any entity with which I am affiliated nor
those of the entities themselves.
On Mon, Sep 30, 2013 at 1:46 PM, Navaid Arif
<navaid.arif@access.net.pk>wrote:
> Hi Art,
> No, I have not used SET EXPLAIN ON option. I do not know how to use it.
>
> On table1, we have INDEXES on two columns i.e. UID and CARD.
>
> UPDATE STATISTICS is MEDIUM on table1. I have not used UPDATE STATISTICS
on
> table2 (if it is using it internally, I am not sure about it)>
> Regards,
> Navaid Arif
>
> -----Original Message-----
> From: ids-bounces@iiug.org [mailto:ids-bounces@iiug.org] On Behalf Of Art
> Kagel
> Sent: Monday, 30 September, 2013 9:19 PM
> To: ids@iiug.org
> Subject: Re: Slow Response in INNER query [31549]
>
> Questions:
>
> - Have you run the two queries under SET EXPLAIN ON to see the
>
> differences in the query plans?
>
> - What indexes are there on table1 and table2?
>
> - Are the data distributions (UPDATE STATISTICS MEDIUM/HIGH) up-to-date
>
> on both tables?
>
> Art
>
> Art S. Kagel, Principal Consultant
>
> Advanced DataTools (www.advancedatatools.com)
> Blog: http://informix-myview.blogspot.com/
>
> Disclaimer: Please keep in mind that my own opinions are my own opinions
> and do not reflect on my employer, Advanced DataTools, the IIUG, nor any
> other organization with which I am associated either explicitly,
> implicitly, or by inference. Neither do those opinions reflect those of
> other individuals affiliated with any entity with which I am affiliated
nor
> those of the entities themselves.
>
> On Mon, Sep 30, 2013 at 12:02 PM, NAVAID ARIF
> <navaid.arif@access.net.pk>wrote:
>
> > Hello everyone,
> > We are using Informix 10 UC5 on AIX 5.3 and facing following issue:
> >
> >
> >
> >
>
>
############################################################################
> ###################
> > ## QUERY-1 - BELOW QUERY TAKES 4 MINUTES TO EXECUTES WHEN TABLE2
CONTAINS
> > ONLY
> > SINGLE RECORD
> >
> >
> >
>
>
############################################################################
> ###################
> > select count(*) from table1
> > where UID>(select max(UID) from table2)
> > and response='00'
> > and txntype in ('FT', 'Bal')
> > and card like '123456%';> >
> > ###############################################################
> > ## QUERY-2 - BELOW QUERY TAKES HALF OF A SECOND TO EXECUTES
> > ###############################################################
> > select count(*) from table1
> > where UID>'123456789012'
> > and response='00'
> > and txntype in ('FT', 'Bal')
> > and card like '123456%';> >
> > We need to tune QUERY-1 as my production deployment is dependent on
this.
> I
> > would be thankful if anyone can help me on this.
> >
> > Thanks in advance.
> >
> > Regards,
> > Navaid Arif
> >
> >
> >
> >
>
>
****************************************************************************
> ***
> > Forum Note: Use "Reply" to post a response in the discussion forum.
> >
> >
>
> --089e0158b8781795e704e79c32a6
>
>
>
****************************************************************************
> ***
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
>
>
****************************************************************************
***
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
--001a11c29b44ec755204e79db0a8
****************************************************************************
***
Forum Note: Use "Reply" to post a response in the discussion forum.