Tuning query with index
hello,
i am trying to avoid full table scan in a query by creating reverse index on the name column in the where clause. but the optimizer still runs full table scan. What can I do?
Regards,
Purvi
Hi,
Reverse key indexes reverse the bytes of each indexed column with the exception of rowid.
I am not sure what you mean when you say the reverse index is supposed to index the names in reverse. When you use the reverse key index lexically adjacent keys are not stored next to each other.
Maybe, reverse index is not right in your situation.
Similar Messages
-
Error during search !!! Associate Search Query with Indexes !!!
We are trying to implement a simple index with Trex Search .
We have done the following tasks :
1. Created my index
2. Assigned data to the the indexes
3. Created taxonomies for classification indexes
4. Created my search query asociated to the index
When we try to search with the iview search , we got this error : <i><b>"Error during search occurred - com.sapportals.wcm.WcmException: A received argument has an invalid value (Errorcode 18)"</b></i> .
We think that something is missing and for that we need to know how can we
associate the search query with the index ?
After the step 4), what we have to do in order to get this implementation (search working)
Please send us any ideas ..
THANKS !!!Dear Ato
Check in IMG Path - Enterprise Structure --> Assignment --> Logistis Execution --> Assign warehouse number to plant/storage location.
Here check whether the warehouse number is assigned to your plant and storage location.
thanks
G. Lakshmipathi -
Tuning query with sdo_join in it
Hello all. I'm new to the forum, but I hope someone can help me tuning a spatial query. I have no DBA experience or education, but I'm writing SQL queries for a few years now, first in Oracle 9i (with Locator), now in Oracle 10g (10.2) and Oracle XE.
I’ve posted this in the Spatial forum as I suspect it’s mostly a spatial issue.
I have a table like:
CREATE TABLE CYCLORAMA (
DATASETID VARCHAR2(9 BYTE),
IMAGEID VARCHAR2(9 BYTE),
OPNAMEDATUM CHAR(20 BYTE),
GEOMETRIE MDSYS.SDO_GEOMETRY
)with only a standard spatial index on GEOMETRIE, and containing about 180000 records. IMAGEID is unique, but not defined as such. Geometry is SDO_POINT_TYPE for all records, like: MDSYS.SDO_GEOMETRY(2001,90112,MDSYS.SDO_POINT_TYPE(86039.572,439541.158,'null'),'null','null'). USER_SDO_GEOM_METADATA is filled with values used for all my geometries: SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X',0,300000,,001), SDO_DIM_ELEMENT('Y',300000,600000,,001)) and SRID = 90112.
What I need to do is to find (and ultimately delete) all records that have another record with a different value for DATASETID, a higher value for OPNAMEDATUM and fall within 3 meters distance. What I came up with so far is:
select /*+ all_rows */ s.imageid
, sdo_geom.sdo_distance(s.geometrie,t.geometrie,0.1) dist
from cyclorama s, cyclorama t
, table(sdo_join('CYCLORAMA','GEOMETRIE','CYCLORAMA','GEOMETRIE','distance=3')) x
-- create a crosstable with records that may be within 3 meters distance
where s.rowid = x.rowid1 and x.rowid2 = t.rowid and not x.rowid1 = x.rowid2
-- filter 'duplicate matches' sdo_join generates for a self join, and select:
and s.datasetid != t.datasetid -- if in different dataset
and s.opnamedatum < t.opnamedatum -- from a later date
and sdo_geom.sdo_distance(s.geometrie,t.geometrie,0.1) < 3 -- within 3 meters
;This is surprisingly fast (7 seconds for first 50 records), but still takes about 7 minutes (Oracle XE on a 768MB, 2.7GHz VM) for the whole query. This is acceptable, but:
* Is this solution the best approach?
* Can this be done faster or more efficient? Clever indexes, hints, smarter query, ...?
* Is it worth optimizing the SDO_DIM_ARRAY for this table, e.g. narrowing the range of coordinate values)?
* How to delete the found records most efficiently?
* Can this be done using an anti-join, to select the records to keep?
Thank you for reading this, and any answers you may have,
J-----.
Jeroen MurisJack,
Thank you for your response. It helped me to clean up the query. All the changes did not give a much better explain plan - at least not to my inexperienced eyes - but the total execution time for the query is now reduced to under two minutes. The query as it is now:
select /*+ ordered all_rows */ x.rowid1
from table(sdo_join('CYCLORAMA','GEOMETRIE','CYCLORAMA','GEOMETRIE','distance=3 mask=ANYINTERACT')) x
, cyclorama s, cyclorama t
where not x.rowid1 = x.rowid2
and s.rowid = x.rowid1 and x.rowid2 = t.rowid
and s.datasetid != t.datasetid
and s.opnamedatum < t.opnamedatum;Because the docs state that mask=FILTER is the default, I added an explicit mask=ANYINTERACT to the sdo_join parameters when I removed the sdo_distance from the query. Still, the query returns 205035 records with the sdo_distance, and 205125 without. But this may be the result of the extra 0.001 from sdo_dim. I did not investigate as the 3 meter is not crucial.
I believe I already had a mechanism in place to reduce the number of self-joins with "not x.rowid1 = x.rowid2" and "s.opnamedatum < t.opnamedatum". I can not guarantee that for all records s.opnamedatum < t.opnamedatum equals x.rowid1 < x.rowid2.
Based on the [url http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14255/sdo_operat.htm#BGEDJIBF]docs, I finally added an 'ordered' hint and reshuffled the tables in the from clause.
I'm happy with performance now, and creating a new table with the records to keep should not be a problem. Still I'm curious about the following:
<li>Is it worth optimizing the SDO_DIM_ARRAY for the original table, e.g. narrowing the range of coordinate values?
<li>How can sdo_join best be used for an anti-join, to select the records to keep?
Thank you,
J-----. -
Tuning query with inline views
Hi!
I have a performance problem with the following query. I try to combine v1 and v2 into one inline view but because of the recursive design of the tables workflow and workflow_node it didn't work.
Does anybody has an idea for tuning this query?
SELECT distinct v1.u_protocol_id
FROM ( SELECT workflow_node.workflow_id,u_protocol.u_protocol_id
FROM workflow_node,workflow,U_protocol
WHERE workflow.workflow_id=workflow_node.workflow_id
AND u_protocol.u_protocol_id = workflow_node.parameter_2
AND workflow_node.workflow_node_type_id=17
AND workflow.workflow_node_type_id=42
) v1,
( SELECT workflow_node.workflow_id,test_template.test_template_id
FROM workflow_node,test_template
WHERE test_template.test_template_id = workflow_node.template
AND workflow_node.order_number = 1
AND workflow_node.workflow_node_type_id=42
) v2,
( SELECT aliquot.aliquot_id,test_template.test_template_id
FROM aliquot,test,test_template
WHERE aliquot.aliquot_id = test.aliquot_id
AND test.test_template_id = test_template.test_template_id
) v3
WHERE v1.workflow_id = v2.workflow_id
AND v2.test_template_id= v3.test_template_idI have found a script (utlxplan.sql) for creating the plan_table so here it is
SQL> @c:\utlxplan.sql;
Table created.
SQL> EXPLAIN PLAN FOR SELECT distinct v1.u_protocol_id
2 FROM ( SELECT workflow_node.workflow_id,u_protocol.u_protocol_id
3 FROM lims_sys.workflow_node,lims_sys.workflow,lims_sys.U_protocol
4 WHERE workflow.workflow_id=workflow_node.workflow_id
5 AND u_protocol.u_protocol_id = workflow_node.parameter_2
6 AND workflow_node.workflow_node_type_id=17
7 AND workflow.workflow_node_type_id=42
8 ) v1,
9 ( SELECT workflow_node.workflow_id,test_template.test_template_id
10 FROM lims_sys.aliquot,lims_sys.test,lims_sys.workflow_node,lims_sys.test_template
11 WHERE aliquot.aliquot_id = test.aliquot_id
12 AND test.test_template_id = test_template.test_template_id
13 AND test_template.test_template_id = workflow_node.template
14 ) v2
15 WHERE v1.workflow_id = v2.workflow_id
16 /
Explained.
SQL> SELECT * FROM TABLE(dbms_xplan.display);
PLAN_TABLE_OUTPUT
| Id | Operation | Name |
Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | |
PLAN_TABLE_OUTPUT
| | |
| 1 | SORT UNIQUE | |
| | |
| 2 | FILTER | |
| | |
| 3 | NESTED LOOPS | |
| | |
PLAN_TABLE_OUTPUT
| 4 | NESTED LOOPS | |
| | |
| 5 | NESTED LOOPS | |
| | |
| 6 | NESTED LOOPS | |
| | |
| 7 | NESTED LOOPS | |
| | |
PLAN_TABLE_OUTPUT
| 8 | NESTED LOOPS | |
| | |
| 9 | TABLE ACCESS BY INDEX ROWID| WORKFLOW |
| | |
|* 10 | INDEX RANGE SCAN | FK_WORKFLOW_WORKFLOW_NODE_TYPE |
| | |
| 11 | TABLE ACCESS BY INDEX ROWID| WORKFLOW_NODE |
PLAN_TABLE_OUTPUT
| | |
| 12 | AND-EQUAL | |
| | |
|* 13 | INDEX RANGE SCAN | FK_WORKFLOW_NODE_WORKFLOW |
| | |
|* 14 | INDEX RANGE SCAN | FK_WORKFLOW_NODE_NODE_TYPE |
| | |
PLAN_TABLE_OUTPUT
| 15 | TABLE ACCESS BY INDEX ROWID | U_PROTOCOL |
| | |
|* 16 | INDEX UNIQUE SCAN | PK_U_PROTOCOL |
| | |
| 17 | TABLE ACCESS BY INDEX ROWID | WORKFLOW_NODE |
| | |
|* 18 | INDEX RANGE SCAN | FK_WORKFLOW_NODE_WORKFLOW |
| | |
PLAN_TABLE_OUTPUT
| 19 | TABLE ACCESS BY INDEX ROWID | TEST_TEMPLATE |
| | |
|* 20 | INDEX UNIQUE SCAN | PK_TEST_TEMPLATE |
| | |
| 21 | TABLE ACCESS BY INDEX ROWID | TEST |
| | |
|* 22 | INDEX RANGE SCAN | FK_TEST_TEST_TEMPLATE |
PLAN_TABLE_OUTPUT
| | |
| 23 | TABLE ACCESS BY INDEX ROWID | ALIQUOT |
| | |
|* 24 | INDEX UNIQUE SCAN | PK_ALIQUOT |
| | |
| 25 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP |
| | |
PLAN_TABLE_OUTPUT
| 26 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP |
| | |
| 27 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP |
| | |
| 28 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP |
| | |
| 29 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP |
| | |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
10 - access("SYS_ALIAS_5"."WORKFLOW_NODE_TYPE_ID"=42)
13 - access("SYS_ALIAS_5"."WORKFLOW_ID"="WORKFLOW_NODE"."WORKFLOW_ID")
14 - access("WORKFLOW_NODE"."WORKFLOW_NODE_TYPE_ID"=17)
PLAN_TABLE_OUTPUT
16 - access("SYS_ALIAS_4"."U_PROTOCOL_ID"=TO_NUMBER("WORKFLOW_NODE"."PARAMETER
_2"))
18 - access("WORKFLOW_NODE"."WORKFLOW_ID"="WORKFLOW_NODE"."WORKFLOW_ID")
20 - access("SYS_ALIAS_1"."TEST_TEMPLATE_ID"="WORKFLOW_NODE"."TEMPLATE")
22 - access("SYS_ALIAS_2"."TEST_TEMPLATE_ID"="SYS_ALIAS_1"."TEST_TEMPLATE_ID")
24 - access("SYS_ALIAS_3"."ALIQUOT_ID"="SYS_ALIAS_2"."ALIQUOT_ID")
Note: rule based optimization -
Oracle query tuning : query with Order-by clause
Hi
I am having a query in my database :
SELECT * FROM SAPR3.HRP1001 WHERE "MANDT" = 990
ORDER BY
"MANDT" , "OTYPE" , "OBJID" , "PLVAR" , "RSIGN" , "RELAT" , "ISTAT" , "PRIOX" , "BEGDA" , "ENDDA" ,"VARYF" , "SEQNR" ;
Autotrace output is :
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=4649 Card=171895 Byt
es=22862035)
1 0 SORT (ORDER BY) (Cost=4649 Card=171895 Bytes=22862035)
2 1 TABLE ACCESS (FULL) OF 'HRP1001' (Cost=1170 Card=171895
Bytes=22862035)
Statistics
0 recursive calls
5 db block gets
12157 consistent gets
11543 physical reads
0 redo size
38253080 bytes sent via SQL*Net to client
376841 bytes received via SQL*Net from client
34201 SQL*Net roundtrips to/from client
0 sorts (memory)
1 sorts (disk)
512992 rows processed
Since it is a issue with order by , it seems a PGA memory issue. there is 12GB PGA available but only 3GB gets allocated. pga_aggregate target is set in the DB. There is a index created for al the columns on order by, but it is not getting used.
pleas suggest me as I am running into major problems, i can post the output of any query u require from my side. Any help wil be highly apprciated.
Rishi> The query was alwasy spilling over to the One-Parse execution . It can be seen thru ST04N ->resource consumption-> sql work area trace.
>
> An undocumented oracle parameter smmmax_size was set which allowed for more usage of physical memory by single process and there was no spillover to the TEMP tablespaces.
>
> Also the File read time was analysed from Unix level ( From SAP thru ST04 ->filesystem wait s-> Avg rd (ms) and Ang writes (ms) which showed that reading from the File was not happening well. )
Hi Rishi,
the provided execution statistics prove the opposite:
>Statistics
>...
>0 sorts (memory)
> 1 sorts (disk)
>512992 rows processed
This indeed was a single-pass sort, which means it had to use the temp tablespace for one pass of the sorting/grouping.
Remember that Oracle distinguishes three kinds of sorts: 1. "in memory", 2. "single-pass" and 3. "multi-pass".
Only the first one won't need to spill out data to the disks. The others do this by definition.
BTW: the file read times in ST04 are aquired through Oracle V$ views and not directly from the OS - that can make a big difference sometimes.
regards,
Lars -
Hi all,
I have to tune the statement below.
UPDATE TABLE_A A
SET A.FIELD1 =
(SELECT B.FIELD1 FROM TABLE_B B WHERE B.IDENTNO IN (A.IDENTNO, A.IDENTNO||'000')
There are indexes on identno on TABLE_A and TABLE_A
The subquery returns only one row. The query works, but not fast enough.
I tried to split the where condition to join it together again with a union like this
UPDATE TABLE_A A
SET A.FIELD1 =
(SELECT B.FIELD1 FROM TABLE_B B WHERE B.IDENTNO = A.IDENTNO
UNION
SELECT B.FIELD1 FROM TABLE_B B WHERE B.IDENTNO = A.IDENTNO||'000')
But the execution plan shows a full table scan for the second part of the union.
How can I tune this part ? With function based index ?
Thanks in advance.
HenningPlease see this thread
When your query takes too long ...
You need to make sure if your statistics are up to date. If not analyze the table.
It works for me,
SQL*Plus: Release 9.2.0.6.0 - Production on Tue May 31 17:10:38 2011
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.8.0 - Production
SQL> CREATE TABLE TABLE_A AS SELECT 1 field1,'1000' IDENTNO FROM dual;
Table created.
SQL> CREATE TABLE TABLE_B AS SELECT 1 field1,'1000000' IDENTNO FROM dual;
Table created.
SQL> CREATE INDEX idx13 ON table_B(IDENTNO);
Index created.
SQL> CREATE INDEX idx12 ON table_A(IDENTNO);
Index created.
SQL> set autotrace on
SQL> UPDATE TABLE_A A
2 SET A.FIELD1 =
3 (SELECT B.FIELD1
4 FROM TABLE_B B
5 WHERE B.IDENTNO IN (A.IDENTNO, A.IDENTNO || '000'));
1 row updated.
Execution Plan
0 UPDATE STATEMENT Optimizer=CHOOSE
1 0 UPDATE OF 'TABLE_A'
2 1 TABLE ACCESS (FULL) OF 'TABLE_A'
3 1 CONCATENATION
4 3 TABLE ACCESS (BY INDEX ROWID) OF 'TABLE_B'
5 4 INDEX (RANGE SCAN) OF 'IDX13' (NON-UNIQUE)
6 3 TABLE ACCESS (BY INDEX ROWID) OF 'TABLE_B'
7 6 INDEX (RANGE SCAN) OF 'IDX13' (NON-UNIQUE)
Statistics
2 recursive calls
2 db block gets
8 consistent gets
0 physical reads
424 redo size
353 bytes sent via SQL*Net to client
432 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> -
Hi all,
My problem is the next: I have two tables, one with 2500000 rows (A) and the other (B) with 1000 rows aprox. I have to join these two tables between two fields B.pk=A.fk. These two fields are indexed. And if I extract the explain plan it doesn't have a high cost (5000 aprox), but when I execute the query it is very slow, it spends more than 2 minutes in finishing. If I drop the index the cost of the explain plan is worse but the execution time is lower, about 15 seconds. What can I do??
Thanks in advanceHi again,
Thanks for your responses. In first place, my database is 11g. In second place, yes, we have collected statistics for both tables...
The rest is going to be more complicated. We have increased the block size to 32KB, in this way we have improved the time of the execution of the queries, so the explain plan has changed. The current plan is this:
plan FOR correcto.
PLAN_TABLE_OUTPUT
Plan hash value: 166371783
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 44 | 2724 (1)| 00:00:33 |
| 1 | SORT GROUP BY | | 1 | 44 | 2724 (1)| 00:00:33 |
| 2 | NESTED LOOPS | | | | | |
| 3 | NESTED LOOPS | | 66753 | 2868K| 2717 (1)| 00:00:33 |
|* 4 | TABLE ACCESS FULL | TIEMPO_MES | 1 | 17 | 3 (0)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | CUPON_COMPLETO_VM_IDX72 | 55168 | | 31 (4)| 00:00:01 |
| 6 | MAT_VIEW ACCESS BY INDEX ROWID| CUPON_COMPLETO_VM | 55168 | 1454K| 2714 (1)| 00:00:33 |
Predicate Information (identified by operation id):
4 - filter(CAST("T46538"."ANIO" AS INTEGER )=2011)
5 - access("T46538"."MES_CODIGO"="T99940"."P_MES")
We have improved the time, but we think that we can do it better. I post here the structure of the tables (only the part affected in the join):
desc TIEMPO_MES
Nombre Nulo Tipo
MES_CODIGO NUMBER
MES_CORTO VARCHAR2(15)
ANIO_CODIGO NUMBER
ANIO NUMBER
desc CUPON_COMPLETO_VM
Nombre Nulo Tipo
P_PRODUCIDOS_KEY NUMBER
P_CUPON_ID NUMBER
P_MES NUMBER
E_ENVIADOS_KEY NUMBER
D_DISTRIBUIDOS_KEY NUMBER
R_RESULTADOS_KEY NUMBER
Thanks in advance -
Hello,
Please give me some code with using index acess ( please high light the index)SELECT carrid connid cityfrom
FROM spfli INTO (xcarrid, xconnid, xcityfrom)
WHERE carrid = 'LH ' AND cityfrom = 'FRANKFURT'
<b>%_HINTS ORACLE 'INDEX("SPFLI" "SPFLI~001")'.</b>
WRITE: / xcarrid, xconnid, xcityfrom.
ENDSELECT.
chk this
Select using Secondary Index
Message was edited by:
Chandrasekhar Jagarlamudi -
SQL query performance difference with Index Hint in Oracle 10g
Hi,
I was having a problem in SQL select query which was taking around 20 seconds to get the results. So, by hit and trail method I added Index Oracle Hint into the same query with the list of indexes of the tables and the results are retrieved with in 10 milli seconds. I am not sure to get How this is working with Indexes Hint.
The query with out Index Hint:
select /*+rule*/ FdnTab2.fdn, paramTab3.attr_name from fdnmappingtable FdnTab, fdnmappingtable FdnTab2, parametertable paramTab1 ,parametertable paramTab3 where FdnTab.id=52787 and paramTab1.id= FdnTab.id and paramTab3.id = FdnTab.id and paramTab3.attr_value = FdnTab2.fdn and paramTab1.attr_name='harqUsersMax' and paramTab1.attr_value <> 'DEFAULT' and exists ( select ParamTab2.attr_name from parametertable ParamTab2, templaterelationtable TemplateTab2 where TemplateTab2.id=FdnTab.id and ParamTab2.id=TemplateTab2.template_id and ParamTab2.id=FdnTab2.id and ParamTab2.attr_name=paramTab1.attr_name) ==> EXECUTION TIME: 20 secs
The same query with Index Hint:
select /*+INDEX(fdnmappingtable[PRIMARY_KY_FDNMAPPINGTABLE],parametertable[PRIMARY_KY_PARAMETERTABLE])*/ FdnTab2.fdn, paramTab3.attr_name from fdnmappingtable FdnTab, fdnmappingtable FdnTab2, parametertable paramTab1 ,parametertable paramTab3 where FdnTab.id=52787 and paramTab1.id= FdnTab.id and paramTab3.id = FdnTab.id and paramTab3.attr_value = FdnTab2.fdn and paramTab1.attr_name='harqUsersMax' and paramTab1.attr_value <> 'DEFAULT' and exists ( select ParamTab2.attr_name from parametertable ParamTab2, templaterelationtable TemplateTab2 where TemplateTab2.id=FdnTab.id and ParamTab2.id=TemplateTab2.template_id and ParamTab2.id=FdnTab2.id and ParamTab2.attr_name=paramTab1.attr_name) ==> EXECUTION TIME: 10 milli secs
Can any one suggest what could be the real problem?
Regards,
PurushothamSorry,
The right query and the explain plan:
select /*+rule*/ FdnTab2.fdn, paramTab3.attr_name from fdnmappingtable FdnTab, fdnmappingtable FdnTab2, parametertable paramTab1 ,parametertable paramTab3 where FdnTab.id=52787 and paramTab1.id= FdnTab.id and paramTab3.id = FdnTab.id and paramTab3.attr_value = FdnTab2.fdn and paramTab1.attr_name='harqUsersMax' and paramTab1.attr_value <> 'DEFAULT' and exists ( select ParamTab2.attr_name from parametertable ParamTab2, templaterelationtable TemplateTab2 where TemplateTab2.id=FdnTab.id and ParamTab2.id=TemplateTab2.template_id and ParamTab2.id=FdnTab2.id and ParamTab2.attr_name=paramTab1.attr_name)
SQL> @$ORACLE_HOME/rdbms/admin/utlxpls.sql
PLAN_TABLE_OUTPUT
Plan hash value: 651267974
| Id | Operation | Name |
| 0 | SELECT STATEMENT | |
|* 1 | FILTER | |
| 2 | NESTED LOOPS | |
| 3 | NESTED LOOPS | |
| 4 | NESTED LOOPS | |
|* 5 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
PLAN_TABLE_OUTPUT
|* 6 | TABLE ACCESS BY INDEX ROWID| PARAMETERTABLE |
|* 7 | INDEX UNIQUE SCAN | PRIMARY_KY_PARAMETERTABLE |
| 8 | TABLE ACCESS BY INDEX ROWID | PARAMETERTABLE |
|* 9 | INDEX RANGE SCAN | PRIMARY_KY_PARAMETERTABLE |
| 10 | TABLE ACCESS BY INDEX ROWID | FDNMAPPINGTABLE |
|* 11 | INDEX UNIQUE SCAN | SYS_C005695 |
| 12 | NESTED LOOPS | |
|* 13 | INDEX UNIQUE SCAN | PRIMARY_KY_PARAMETERTABLE |
|* 14 | INDEX UNIQUE SCAN | PRIMARY_KEY_TRTABLE |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
1 - filter( EXISTS (SELECT 0 FROM "TEMPLATERELATIONTABLE"
"TEMPLATETAB2","PARAMETERTABLE" "PARAMTAB2" WHERE
"PARAMTAB2"."ATTR_NAME"=:B1 AND "PARAMTAB2"."ID"=:B2 AND
"PARAMTAB2"."ID"="TEMPLATETAB2"."TEMPLATE_ID" AND
"TEMPLATETAB2"."ID"=:B3))
5 - access("FDNTAB"."ID"=52787)
6 - filter("PARAMTAB1"."ATTR_VALUE"<>'DEFAULT')
7 - access("PARAMTAB1"."ID"="FDNTAB"."ID" AND
PLAN_TABLE_OUTPUT
"PARAMTAB1"."ATTR_NAME"='harqUsersMax')
9 - access("PARAMTAB3"."ID"="FDNTAB"."ID")
11 - access("PARAMTAB3"."ATTR_VALUE"="FDNTAB2"."FDN")
13 - access("PARAMTAB2"."ID"=:B1 AND "PARAMTAB2"."ATTR_NAME"=:B2)
14 - access("TEMPLATETAB2"."ID"=:B1 AND
"PARAMTAB2"."ID"="TEMPLATETAB2"."TEMPLATE_ID")
Note
- rule based optimizer used (consider using cbo)
43 rows selected.
WITH INDEX HINT:
select /*+INDEX(fdnmappingtable[PRIMARY_KY_FDNMAPPINGTABLE],parametertable[PRIMARY_KY_PARAMETERTABLE])*/ FdnTab2.fdn, paramTab3.attr_name from fdnmappingtable FdnTab, fdnmappingtable FdnTab2, parametertable paramTab1 ,parametertable paramTab3 where FdnTab.id=52787 and paramTab1.id= FdnTab.id and paramTab3.id = FdnTab.id and paramTab3.attr_value = FdnTab2.fdn and paramTab1.attr_name='harqUsersMax' and paramTab1.attr_value <> 'DEFAULT' and exists ( select ParamTab2.attr_name from parametertable ParamTab2, templaterelationtable TemplateTab2 where TemplateTab2.id=FdnTab.id and ParamTab2.id=TemplateTab2.template_id and ParamTab2.id=FdnTab2.id and ParamTab2.attr_name=paramTab1.attr_name);
SQL> @$ORACLE_HOME/rdbms/admin/utlxpls.sql
PLAN_TABLE_OUTPUT
Plan hash value: 2924316070
| Id | Operation | Name | Rows | B
ytes | Cost (%CPU)| Time |
PLAN_TABLE_OUTPUT
| 0 | SELECT STATEMENT | | 1 |
916 | 6 (0)| 00:00:01 |
|* 1 | FILTER | | |
| | |
| 2 | NESTED LOOPS | | 1 |
916 | 4 (0)| 00:00:01 |
| 3 | NESTED LOOPS | | 1 |
401 | 3 (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
| 4 | NESTED LOOPS | | 1 |
207 | 2 (0)| 00:00:01 |
|* 5 | TABLE ACCESS BY INDEX ROWID| PARAMETERTABLE | 1 |
194 | 1 (0)| 00:00:01 |
|* 6 | INDEX UNIQUE SCAN | PRIMARY_KY_PARAMETERTABLE | 1 |
| 1 (0)| 00:00:01 |
|* 7 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE | 1 |
PLAN_TABLE_OUTPUT
13 | 1 (0)| 00:00:01 |
| 8 | TABLE ACCESS BY INDEX ROWID | PARAMETERTABLE | 1 |
194 | 1 (0)| 00:00:01 |
|* 9 | INDEX RANGE SCAN | PRIMARY_KY_PARAMETERTABLE | 1 |
| 1 (0)| 00:00:01 |
| 10 | TABLE ACCESS BY INDEX ROWID | FDNMAPPINGTABLE | 1 |
515 | 1 (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
|* 11 | INDEX UNIQUE SCAN | SYS_C005695 | 1 |
| 1 (0)| 00:00:01 |
| 12 | NESTED LOOPS | | 1 |
91 | 2 (0)| 00:00:01 |
|* 13 | INDEX UNIQUE SCAN | PRIMARY_KEY_TRTABLE | 1 |
26 | 1 (0)| 00:00:01 |
|* 14 | INDEX UNIQUE SCAN | PRIMARY_KY_PARAMETERTABLE | 1 |
65 | 1 (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
1 - filter( EXISTS (SELECT /*+ */ 0 FROM "TEMPLATERELATIONTABLE" "TEMPLATETAB
2","PARAMETERTABLE"
PLAN_TABLE_OUTPUT
"PARAMTAB2" WHERE "PARAMTAB2"."ATTR_NAME"=:B1 AND "PARAMTAB2"."ID"
=:B2 AND
"TEMPLATETAB2"."TEMPLATE_ID"=:B3 AND "TEMPLATETAB2"."ID"=:B4))
5 - filter("PARAMTAB1"."ATTR_VALUE"<>'DEFAULT')
6 - access("PARAMTAB1"."ID"=52787 AND "PARAMTAB1"."ATTR_NAME"='harqUsersMax')
7 - access("FDNTAB"."ID"=52787)
9 - access("PARAMTAB3"."ID"=52787)
11 - access("PARAMTAB3"."ATTR_VALUE"="FDNTAB2"."FDN")
13 - access("TEMPLATETAB2"."ID"=:B1 AND "TEMPLATETAB2"."TEMPLATE_ID"=:B2)
14 - access("PARAMTAB2"."ID"=:B1 AND "PARAMTAB2"."ATTR_NAME"=:B2)
PLAN_TABLE_OUTPUT
Note
- dynamic sampling used for this statement
39 rows selected. -
Tuning SQL query with SDO and Contains?
I'trying to optimize a query
with a sdo_filter and an intermedia_contains
on a 3.000.000 records table,
the query look like this
SELECT COUNT(*) FROM professionnel WHERE mdsys.sdo_filter(professionnel.coor_cart,mdsys.sdo_geometry(2003, null, null,mdsys.sdo_elem_info_array(1,1003,4),mdsys.sdo_ordinate_array(809990,2087279,778784,2087279,794387,2102882)),'querytype=window') = 'TRUE' AND professionnel.code_rubr ='12 3 30' AND CONTAINS(professionnel.Ctx,'PLOMBERIE within Nom and ( RUE within Adresse1 )',1)>0
and it takes 15s on a bi 750 pentium III with
1.5Go of memory running under 8.1.6 linux.
What can i do to improve this query time?
nullHi Vincent,
We have patches for Oracle 8.1.6 Spatial
on NT and Solaris.
These patches include bug fixes and
performance enhancements.
We are in the process of making these patches
avaialble in a permanent place, but until then, I will temporarily put the patches on:
ftp://oracle-ftp.oracle.com/
Log in as anonymous and use your email for
password.
The patches are in /tmp/outgoing in:
NT816-000706.zip - NT patch
libordsdo.tar - Solaris patch
I recommend doing some analysis on
individual pieces of the query.
i.e. time the following:
1)
SELECT COUNT(*)
FROM professionnel
WHERE mdsys.sdo_filter(
professionnel.coor_cart,
mdsys.sdo_geometry(
2003, null, null,
mdsys.sdo_elem_info_array(1,1003,4),
mdsys.sdo_ordinate_array(
809990,2087279,
778784,2087279,
794387,2102882)),
'querytype=window') = 'TRUE';
2)
SELECT COUNT(*)
FROM professionnel
WHERE CONTAINS(professionnel.Ctx,
'PLOMBERIE within Nom and ( RUE within Adresse1)',1) >0;
You might want to try reorganizing the entire
query as follows (no promises).
If you contact me directly, I can try to
help to further tune the SQL.
Hope this helps. Thanks.
Dan
select count(*)
FROM
(SELECT /*+ no_merge */ rowid
FROM professionnel
WHERE mdsys.sdo_filter(
professionnel.coor_cart,
mdsys.sdo_geometry(
2003, null, null,
mdsys.sdo_elem_info_array(1,1003,4),
mdsys.sdo_ordinate_array(809990,2087279,
778784,2087279,
794387,2102882)),
'querytype=window') = 'TRUE'
) a,
(SELECT /*+ no_merge */ rowid
FROM professionnel
WHERE CONTAINS(professionnel.Ctx,
'PLOMBERIE within Nom and
( RUE within Adresse1)',1) >0
) b
where a.rowid = b.rowid
and professionnel.code_rubr ='12 3 30';
**NOTE** Try this with no index on code_rubr
null -
SQL query with Bind variable with slower execution plan
I have a 'normal' sql select-insert statement (not using bind variable) and it yields the following execution plan:-
Execution Plan
0 INSERT STATEMENT Optimizer=CHOOSE (Cost=7 Card=1 Bytes=148)
1 0 HASH JOIN (Cost=7 Card=1 Bytes=148)
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'TABLEA' (Cost=4 Card=1 Bytes=100)
3 2 INDEX (RANGE SCAN) OF 'TABLEA_IDX_2' (NON-UNIQUE) (Cost=3 Card=1)
4 1 INDEX (FAST FULL SCAN) OF 'TABLEB_IDX_003' (NON-UNIQUE)
(Cost=2 Card=135 Bytes=6480)
Statistics
0 recursive calls
18 db block gets
15558 consistent gets
47 physical reads
9896 redo size
423 bytes sent via SQL*Net to client
1095 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
55 rows processed
I have the same query but instead running using bind variable (I test it with both oracle form and SQL*plus), it takes considerably longer with a different execution plan:-
Execution Plan
0 INSERT STATEMENT Optimizer=CHOOSE (Cost=407 Card=1 Bytes=148)
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'TABLEA' (Cost=3 Card=1 Bytes=100)
2 1 NESTED LOOPS (Cost=407 Card=1 Bytes=148)
3 2 INDEX (FAST FULL SCAN) OF TABLEB_IDX_003' (NON-UNIQUE) (Cost=2 Card=135 Bytes=6480)
4 2 INDEX (RANGE SCAN) OF 'TABLEA_IDX_2' (NON-UNIQUE) (Cost=2 Card=1)
Statistics
0 recursive calls
12 db block gets
3003199 consistent gets
54 physical reads
9448 redo size
423 bytes sent via SQL*Net to client
1258 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
55 rows processed
TABLEA has around 3million record while TABLEB has 300 records. Is there anyway I can improve the speed of the sql query with bind variable? I have DBA Access to the database
Regards
IvanMany thanks for your reply.
I have run the statistic already for the both tableA and tableB as well all the indexes associated with both table (using dbms_stats, I am on 9i db ) but not the indexed columns.
for table I use:-
begin
dbms_stats.gather_table_stats(ownname=> 'IVAN', tabname=> 'TABLEA', partname=> NULL);
end;
for index I use:-
begin
dbms_stats.gather_index_stats(ownname=> 'IVAN', indname=> 'TABLEB_IDX_003', partname=> NULL);
end;
Is it possible to show me a sample of how to collect statisc for INDEX columns stats?
regards
Ivan -
Hello.
I have a query with LEFT OUTER JOIN that I think returns invalid results. Here are the problem details:
CREATE TABLE DOGERR(
IdDog INTEGER,
SfPdg CHAR(1),
IdVpl INTEGER,
SfVpGot INTEGER,
SfZrr CHAR(1)
INSERT INTO DOGERR(IdDog, SfPdg, IdVpl, SfVpGot, SfZrr) VALUES (1, 'S', 1, 1, '7');
INSERT INTO DOGERR(IdDog, SfPdg, IdVpl, SfVpGot, SfZrr) VALUES (2, 'S', 1, 1, '7');
INSERT INTO DOGERR(IdDog, SfPdg, IdVpl, SfVpGot, SfZrr) VALUES (3, '$', 1, 2, 'C');
COMMIT;
CREATE UNIQUE INDEX DOGERR_PK ON DOGERR(IdDog);
And now the query:
SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGotJoin, T.SfZrr AS SfZrrJoin
FROM DOGERR D
LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S' OR SfPdg = 'S') T ON
T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
WHERE
D.IdDog = 3
AND D.SfVpGot = 2
AND D.SfZrr = 'C';
This query should (by my understanding) return only one row in wich the joined subquery columns should be NULL. And indeed query returns only one row on Oracle Database 10g Release 10.2.0.1.0 - Production and on Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production:
IDDOG = 3, SFPDG = "$", IDVPL = 1, SFVPGOT = 2, SFZRR = "C", IDVPLJOIN = NULL, SFVPGOTJOIN = NULL, SFZRRJOIN = NULL
But on Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production it returns TWO rows:
IDDOG = 3, SFPDG = "$", IDVPL = 1, SFVPGOT = 2, SFZRR = "C", IDVPLJOIN = 1, SFVPGOTJOIN = 1, SFZRRJOIN = "7"
IDDOG = 3, SFPDG = "$", IDVPL = 1, SFVPGOT = 2, SFZRR = "C", IDVPLJOIN = 1, SFVPGOTJOIN = 1, SFZRRJOIN = "7"
And now the interesting part: any of the following modified versions of query works even on Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production, although modifications should not modify the result set:
-- Removed unnecessary WHERE conditions
SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGotJoin, T.SfZrr AS SfZrrJoin
FROM DOGERR D
LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S' OR SfPdg = 'S') T ON
T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
WHERE
D.IdDog = 3;
-- Removed unnecessary OR condition in subquery
SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGotJoin, T.SfZrr AS SfZrrJoin
FROM DOGERR D
LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S') T ON
T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
WHERE
D.IdDog = 3
AND D.SfVpGot = 2
AND D.SfZrr = 'C';
-- Removed columns from joined subquery from SELECT part
SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGotJoin
FROM DOGERR D
LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S' OR SfPdg = 'S') T ON
T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
WHERE
D.IdDog = 3
AND D.SfVpGot = 2
AND D.SfZrr = 'C';
NOTE: the query itself is a little stupid but this is just to demonstrate the problem. We have faced this problem at a customer with our real-world query.
So, my question is: why different results ?
Thanks.
Davidhi,
welcome to the forum,
don't have a solution, but I thought I'd let you know that the first SQL statement only returns 1 row on 10gR2
SQL> SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGo
tJoin, T.SfZrr AS SfZrrJoin
2 FROM DOGERR D
3 LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S' OR SfPdg = 'S') T ON
4 T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
5 WHERE
6 D.IdDog = 3
7 AND D.SfVpGot = 2
8 AND D.SfZrr = 'C';
IDDOG S IDVPL SFVPGOT S IDVPLJOIN SFVPGOTJOIN S
3 $ 1 2 C
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Solaris: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production -
How can I create a query with tables in INFOSET?
Dear Gurus,
How can I create a query with tables in INFOSET?
Just tables and fields INFOSET?
Kind Regards,Hello
Check following SCN Article for your understanding/reference:
- [Using Infoset Query ,SAP Query and Quick Viewer|http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/10eab7af-0e54-2c10-28a5-87b47adbe1a5]
Regards
JP -
How can I create a query with web service data control?
I need to create a query with web service data control, in WSDL, it's query operation, there is a parameter message with the possible query criteria and a return message contains the results. I googled, but cannot find anything on the query with web service. I cannot find a "Named Criteria" in web service data control like normal data control. In Shay's blog, I saw the topics on update with web service data control. How can I create a query with web service data control? Thanks.
Hi,
This might help
*054. Search form using ADF WS Data Control and Complex input types*
http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html -
Query with subquery should return value but doesn't
When I run this SQL, it returns no value:
SELECT vfn.cat
FROM vps_fishery_ner vfn, valid_fishery vf
WHERE vfn.plan = vf.plan
AND vfn.cat = vf.cat
AND vf.permit_year = 2010
AND vf.moratorium_fishery = 'T'
AND vfn.vp_num = 211652
AND vfn.ap_year = 2010
AND vfn.plan = 'MUL'
AND vfn.date_issued = (SELECT MAX(date_issued)
FROM vps_fishery_ner
WHERE vp_num = 211652
AND ap_year = 2010);
In order to test, I take out the subquery and run it separately:
SELECT MAX(date_issued)
FROM vps_fishery_ner
WHERE vp_num = 211652
AND ap_year = 2010;
Returns 02-APR-10
Then I paste this date into the original query (using the TRUNC function, of course, since I hardcode only the DDMMYY part of the date):
SELECT vfn.cat
FROM vps_fishery_ner vfn, valid_fishery vf
WHERE vfn.plan = vf.plan
AND vfn.cat = vf.cat
AND vf.permit_year = 2010
AND vf.moratorium_fishery = 'T'
AND vfn.vp_num = 211652
AND vfn.ap_year = 2010
AND vfn.plan = 'MUL'
AND TRUNC(date_issued) = TO_DATE('02-APR-10');
And this returns the required value, 'A'.
So why doesn't the full query with subquery work, if the value that is returned by the subquery is valid and works when you just paste it in?
Thanks.Hi,
Not sure about your question.
But you say when you uss 01-apr-10 you get the expected results.
So why dont you try using trunc on botht sides
SELECT vfn.cat
FROM vps_fishery_ner vfn, valid_fishery vf
WHERE vfn.plan = vf.plan
AND vfn.cat = vf.cat
AND vf.permit_year = 2010
AND vf.moratorium_fishery = 'T'
AND vfn.vp_num = 211652
AND vfn.ap_year = 2010
AND vfn.plan = 'MUL'
AND trunc(vfn.date_issued) = (SELECT MAX(trunc(date_issued))
FROM vps_fishery_ner
WHERE vp_num = 211652
AND ap_year = 2010);Rememeber if you are couting on some Index to be used you might want to recheck.
IN answer to your question why it does not return with subquery included, because the TIME PART is not the same.
You yourself proved it by using the supplying only the date part.
Regards,
Bhushan
Maybe you are looking for
-
I have an error when I try to patch my OMS GridControl. Always at the OMS patch configuration content of configToolFailedCommands oracle.sysman.emcp.oms.OmsPatchUpgrade -configureOms oracle.sysman.emcp.aggregates.ConfigPlugIn oracle.sysman.emcp.oms.S
-
I have an email account that I am moving from one computer to a new one. It was configured as a POP account, and foolishly I configured it the same way again, on my new Yosemite machine, in Apple Mail. I realized it would be better as an IMAP accoun
-
What are the recommended CD's for my G7 laptop?
I have a g7-1365dx laptop, with an HP A DS8A5LH Cdrom Drive. I'm running Windows 7 Home Premium. I have Nero 12 installed. I went to burn an everyday music CD, and Nero only gave me one choice of writing speed. I know for sure this isn't a Nero i
-
Query Regarding File to IDOC Scenario (1:2)
Hi, I am working on a scenario like One File to Two IDOC's . In file we are getting some business functions (It's One feild in source file) , Some Business functions I need to map with One IDOC and some with other Idoc. So I need to route a file cont
-
How to get double brush mode in Photoshop?
I want to use a normal brush tool but ahve it side by side because I need to make a motorway, I want to make it on Photoshp but I need to know how to do that. Thanks