Using the index of multiple values
Hi guys,.Trying to assess the benefits of the addition of index of multiple values, a quick question on the index of multiple values:
Here's my content from the cache:
Key (EmpID), value [employee (age int, double salary, Department of String)]
(1, new employee (25, 35000.0, "Admin"));
(2, new employee (22, 30000.0, "Admin"));
(3, new employee (34, 40000.0, 'Communications'));
(4, new employee (36, 41000.0, "Admin"));
(5, new employee (36, 42000.0, "HR"));
(6, new employee (29, 30000.0, "HR"));
(7, new employee (51, 50000.0, "BackOffice"));
(8, new employee (36, 35000.0, "HR"));
(9, new employee (46, 45000.0, "Admin"));
(10, new employee (48, 47000.0, "HR"));
If I still want to find all employees in the 'Human resources' Department and whose salary is more than 35000.
Eventually, I would like to do the following:
ValueExtractor salExtractor = new PofExtractor (Integer.class, 2);
ValueExtractor depExtractor = new PofExtractor (String.class, 3);
cache.addIndex (salExtractor, false, null);
cache.addIndex (depExtractor, false, null);
EqualsFilter departmentFilter = new EqualsFilter (depExtractor, 'HR');
GreaterFilter salFilter = new GreaterFilter (salExtractor, 35000);
Filter allFilter = new AllFilter (new filter [] {departmentFilter, salFilter});
Employees value = cache.entrySet (allFilter));
For my usecase above how can I use the indexing of multiple values to the same query?
ValueExtractor salExtractor = new PofExtractor (Integer.class, 2);
ValueExtractor depExtractor = new PofExtractor (String.class, 3);
MultiExtractor mExtractor is new MultiExtractor (new ValueExtractor [] {salExtractor, depExtractor});.
cache.addIndex (mExtractor, false, null);
But how can I use the extractor to create multivalued filter queries for employees in the Department of human resources with greater than 35000 salary? Any ideas are much appreciated.
Thank you
D wrote:
Hi guys,.Trying to assess the benefits of the addition of index of multiple values, a quick question on the index of multiple values:
Here's my content from the cache:
Key (EmpID), value [employee (age int, double salary, Department of String)]
(1, new employee (25, 35000.0, "Admin"));
(2, new employee (22, 30000.0, "Admin"));
(3, new employee (34, 40000.0, 'Communications'));
(4, new employee (36, 41000.0, "Admin"));
(5, new employee (36, 42000.0, "HR"));
(6, new employee (29, 30000.0, "HR"));
(7, new employee (51, 50000.0, "BackOffice"));
(8, new employee (36, 35000.0, "HR"));
(9, new employee (46, 45000.0, "Admin"));
(10, new employee (48, 47000.0, "HR"));If I still want to find all employees in the 'Human resources' Department and whose salary is more than 35000.
Eventually, I would like to do the following:
ValueExtractor salExtractor = new PofExtractor (Integer.class, 2);
ValueExtractor depExtractor = new PofExtractor (String.class, 3);
cache.addIndex (salExtractor, false, null);
cache.addIndex (depExtractor, false, null);EqualsFilter departmentFilter = new EqualsFilter (depExtractor, 'HR');
GreaterFilter salFilter = new GreaterFilter (salExtractor, 35000);
Filter allFilter = new AllFilter (new filter [] {departmentFilter, salFilter});
Employees value = cache.entrySet (allFilter));For my usecase above how can I use the indexing of multiple values to the same query?
ValueExtractor salExtractor = new PofExtractor (Integer.class, 2);
ValueExtractor depExtractor = new PofExtractor (String.class, 3);
MultiExtractor mExtractor is new MultiExtractor (new ValueExtractor [] {salExtractor, depExtractor});.
cache.addIndex (mExtractor, false, null);But how can I use the extractor to create multivalued filter queries for employees in the Department of human resources with greater than 35000 salary? Any ideas are much appreciated.
Thank you
I remember, values multiple index refers to a different concept: a multivalued index means that you can retrieve a collection of values of similar role of an attribute on which you can do Contains, ContainsAll filtering, and ContainsAny.
In this case to fully the lever consistency of querying capabilities, you would
- either add a sorted index with a custom comparator that compares the tables containing a salary and a Department on a first salary so the base of the Department and add a filter custom which is able to take advantage of the index for the request for the salary and also able to filter on the element of the array of index service
-Add two independent indices (a sorted index of wages and a unsorted for the Department), in which case you can leverage all existing (GreaterThanFilter, EqualsFilter and AndFilter) code
Best regards
Robert
Tags: Fusion Middleware
Similar Questions
-
SDO_NN cannot be assessed without using the index when put inside subquery
Hi all
I met a problem when you use the function sdo_nn to find the nearest neighbor. Here is my scenario:
_ I have 2 customer and store tables.
Customer table _ a client_ID and a 2D sdo_geom point
_ Store table has store_ID and a 2D polygon sdo_geom.
In the beginning, I have this query to find the nearest store to each customer as below:
Select s.STORE_ID, c.CLIENT_ID
store customer, s c
where sdo_nn (s.MYPOLYGON, c.MYPOINT, 'sdo_num_res = 1', 1) = "TRUE";
_It works as expected when it returns a table showing the nearest store each customer.
_Now I want to count the number of customers who have the same nearest store:
Select / * + INDEX (store store_spatial_idx, client_spatial_idx client) * / count (nearest_store. CLIENT_ID)
from (select s.STORE_ID, c.CLIENT_ID
store customer, s c
where sdo_nn (s.MYPOLYGON, c.MYPOINT, 'sdo_num_res = 1', 1) = "TRUE") nearest_store
Group of nearest_store. STORE_ID;
This query generates the following error:
Error report-
SQL error: ORA-13249: SDO_NN cannot be assessed without using the index
ORA-06512: at the 'MDSYS. MD", line 1723
ORA-06512: at the 'MDSYS. MDERR", line 17
ORA-06512: at the 'MDSYS. PRVT_IDX', line 9
13249 00000 - '%s '.
I'm pretty new to spatial databases and hope get help to go further. Thank you in advance!
Hello Pinball,
Oracle space tends to be a quite complex with many variables and moving parts. We chatted about the group to a sort of FAQ or guidelines to help people like you submit questions that actually answers. First of all, you really have to tell us the version of Oracle you are using. Particularly the problems involving the optimizer, version down to the exact defined patch number is a good idea. Secondly, you took the time to submit the question so I guess you want a response. If you really want to see the answer and then providing an example is one of the most important things that you can do. I'm going to do here for you, but in general people on this forum come and go and are often pushed into lurkitude, so if you want the coax to provide you with an example of work is the key.
DROP TABLE store1 PURGE; CREATE TABLE store1( store_id INTEGER NOT NULL ,shape MDSYS.SDO_GEOMETRY ,PRIMARY KEY(store_id) ); DROP TABLE client2 PURGE; CREATE TABLE client2( client_id INTEGER NOT NULL ,shape MDSYS.SDO_GEOMETRY ,PRIMARY KEY(client_id) ); CREATE OR REPLACE PROCEDURE seeder( p_client_count IN NUMBER ,p_store_count IN NUMBER ) AS sdo_foo MDSYS.SDO_GEOMETRY; int_counter NUMBER; FUNCTION random_point RETURN MDSYS.SDO_GEOMETRY AS num_x1 NUMBER; num_y1 NUMBER; BEGIN num_x1 := dbms_random.value(-179,179); num_y1 := dbms_random.value(-89,89); RETURN MDSYS.SDO_GEOMETRY( 2001 ,8265 ,MDSYS.SDO_POINT_TYPE( num_x1 ,num_y1 ,NULL ) ,NULL ,NULL ); END random_point; BEGIN int_counter := 1; FOR i IN 1 .. p_client_count LOOP -- Create a client point sdo_foo := random_point(); INSERT INTO client2 VALUES ( int_counter ,sdo_foo ); int_counter := int_counter + 1; END LOOP; int_counter := 1; FOR i IN 1 .. p_store_count LOOP -- Create a store polygon of some kind sdo_foo := MDSYS.SDO_GEOM.SDO_ARC_DENSIFY( MDSYS.SDO_GEOM.SDO_BUFFER( random_point() ,5000 ,0.05 ) ,0.05 ,'arc_tolerance=0.05' ); INSERT INTO store1 VALUES ( int_counter ,sdo_foo ); int_counter := int_counter + 1; END LOOP; COMMIT; END seeder; / BEGIN seeder(10000,200); END; / BEGIN INSERT INTO user_sdo_geom_metadata( table_name ,column_name ,diminfo ,srid ) VALUES ( 'STORE1' ,'SHAPE' ,MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',-180,180,.05),MDSYS.SDO_DIM_ELEMENT('Y',-90,90,.05)) ,8265 ); COMMIT; EXCEPTION WHEN OTHERS THEN NULL; END; / BEGIN INSERT INTO user_sdo_geom_metadata( table_name ,column_name ,diminfo ,srid ) VALUES ( 'CLIENT2' ,'SHAPE' ,MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',-180,180,.05),MDSYS.SDO_DIM_ELEMENT('Y',-90,90,.05)) ,8265 ); COMMIT; EXCEPTION WHEN OTHERS THEN NULL; END; / CREATE INDEX store1_spx ON store1 (shape) INDEXTYPE IS MDSYS.SPATIAL_INDEX NOPARALLEL; CREATE INDEX client2_spx ON client2 (shape) INDEXTYPE IS MDSYS.SPATIAL_INDEX NOPARALLEL; /* Works as expected */ SELECT s.store_id ,c.client_id ,MDSYS.SDO_NN_DISTANCE(1) FROM store1 s ,client2 c WHERE MDSYS.SDO_NN( s.shape ,c.shape ,'sdo_num_res=1' ,1 ) = 'TRUE'; /* No worky? Works for me */ SELECT ns.store_id ,COUNT(ns.client_id) FROM ( SELECT s.store_id ,c.client_id FROM store1 s ,client2 c WHERE MDSYS.SDO_NN( s.shape ,c.shape ,'sdo_num_res=1' ,1 ) = 'TRUE' ) ns GROUP BY ns.store_id ORDER BY ns.store_id;
So I wrote this about 12 c (12.1.0.2.0) and everything works fine for me. Then I moved back from 11 GR 2 (11.2.0.4.0) and of course, there are questions. So I guess that you don't use flavor of 11g. So at this point we can look at the docs and see for 11g, have you often need to specify which table is the head and that is the one that has the spatial index to use.
http://docs.Oracle.com/CD/E11882_01/AppDev.112/e11830/sdo_operat.htm#SPATL1032Its rather interesting that the optimizer of 12 c knows what you want, when I had to squint myself at your request and to play a little with the refining. Note that SDO_NN is sensitive, because the geometry of the main table should come second in the operator. I did not know that on the top of my head.
SELECT /*+ LEADING(c) INDEX(s store1_spx) */ s.store_id ,c.client_id ,MDSYS.SDO_NN_DISTANCE(1) FROM store1 s ,client2 c WHERE MDSYS.SDO_NN( s.shape ,c.shape ,'sdo_num_res=1' ,1 ) = 'TRUE'; SELECT ns.store_id ,COUNT(ns.client_id) FROM ( SELECT /*+ LEADING(c) INDEX(s store1_spx) */ s.store_id ,c.client_id ,MDSYS.SDO_NN_DISTANCE(1) FROM store1 s ,client2 c WHERE MDSYS.SDO_NN( s.shape ,c.shape ,'sdo_num_res=1' ,1 ) = 'TRUE' ) ns GROUP BY ns.store_id ORDER BY ns.store_id;
So I think that is your answer. Give it a shot and see if this fits the Bill. Of course, moving to 12 c would be useful for such things. It would be interesting to collect more examples of this kind of space thing where 12 c is the answer. Also, would be nice if we could mark somehow this discussion as applying only to 11g and earlier versions.
See you soon,.
Paul
-
What is the right time to use the index with force?
I have an EMPLOYEE table. I join with the ROLE, and it has only about 200 distinct values on column EMPLOYEE. EMPLOYEE_TYPE_ID.
Select / * + INDEX (an i_employee_type_id) * / b.SID as EMP_NAME, b.role_cd in the ROLE
Of
EMPLOYEE,
B ROLE
where
a.EMPLOYEE_TYPE_ID = b.EMPLOYEE_TYPE_ID
AND a.EFFECTIVE_END_TS > = systimestamp;
Is it a good idea to use the index? .. Or let the full table scan.
SQL > select distinct EMPLOYEE_TYPE_ID of the EMPLOYEE;
238 selected lines.
If you don't know it will help not to use.
Personally, I found several SQLs with index finger tips (written by programmers thinking index access is ALWAYS GOOD) end up harming performance. Oracle made a reading diluvium full table scan, single index reads as follows, according to the % of the returned array it is actually faster to do a full table scan. The optimizer did a great job to determine this.
If you think there are cardinality estimation problems, and the optimizer expects a large number of lines when there are actually few being returned, in THIS case a suspicion was justified. Even so, in this case, I prefer that oracle manages the flag itself.
You can do this by running the SQL tuning advisor. In fact, it will trigger the optimizer checks that the estimates are turned off and it will create a profile for you. (A profile is actually a stored set of advice that set the execution plan for you). If at the point where the underlying data changes significantly and profile ends up hurting performance, you do not need to touch the code like you would with manually added notes, you can just disable or delete the profile and let the optimizer re - analyze the statement.
Concerning
EDIT: In case of small tables, it is preferable to just cache the whole table in the POOL to KEEP and let oracle scan if necessary.
Edit2: With the notable exception of index fast full scans, which are diluvium index readings. But they are only relevant when the request is quite satisfied by the index and has no need to visit the table.
-
I have problem with a query as follows. It does not index when I keep a function on the left side of the comparison in which the condition.
But when I remove the function is using the index.
With BLC AS Name Null? Type ----------------------------------------- -------- ---------------------------- ID NOT NULL NUMBER MASTER_VALUE NOT NULL NUMBER(8) DESC_TEXT_ID NUMBER GVM VARCHAR2(50) MASTER_LOOKUP_ID NOT NULL NUMBER WORK_SECTION_ID NUMBER AUDIT_TRAIL_NO NUMBER SQL> SELECT COUNT(*) FROM BLC; COUNT(*) ---------- 7769 SQL> SELECT COUNT(DISTINCT(GVM)) "distinct" FROM BLC; distinct ---------- 1350 SQL> SELECT COUNT(*) "nulls" FROM BLC WHERE GVM IS NULL; nulls ---------- 6419 SQL> SELECT COLUMN_NAME,INDEX_NAME FROM DBA_IND_COLUMNS WHERE TABLE_NAME='BLC'; COLUMN_NAME INDEX_NAME ---------------------------------------- ------------------------------ MASTER_LOOKUP_ID LKPCDE_MSTLKP_FK_I WORK_SECTION_ID LKPCDE_WRKSEC_FK_I GVM LKPCDE_UK MASTER_VALUE LKPCDE_MASTERID_VALUE_UK MASTER_LOOKUP_ID LKPCDE_MASTERID_VALUE_UK ID LKPCDE_PK SQL> EXPLAIN PLAN FOR SELECT ID FROM BLC WHERE UPPER ( GVM) = 'MAIN_ORG'; Explained. SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY); PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- Plan hash value: 3196655606 -------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time| -------------------------------------------------------------------------------------- PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 78 | 624 | 18 (0)| 00:00:01 | |* 1 | TABLE ACCESS FULL| BLC | 78 | 624 | 18 (0)| 00:00:01 | -------------------------------------------------------------------------------------- Predicate Information (identified by operation id): PLAN_TABLE_OUTPUT ----------------------------------------------------------------------------------------------------------------------------------- 1 - filter(UPPER("GVM")='MAIN_ORG') 13 rows selected. SQL> EXPLAIN PLAN FOR SELECT ID FROM BLC WHERE GVM = 'MAIN_ORG'; Explained. SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY); PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- Plan hash value: 1620245961 -------------------------------------------------------------------------------- ---------------- | Id | Operation | Name | Rows | Bytes | Cost (% CPU)| Time | -------------------------------------------------------------------------------- ---------------- PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 8 | 2 (0)| 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID| BLC | 1 | 8 | 2 (0)| 00:00:01 | |* 2 | INDEX UNIQUE SCAN | LKPCDE_UK | 1 | | 1 (0)| 00:00:01 | -------------------------------------------------------------------------------- ---------------- PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("GVM"='MAIN_ORG') 14 rows selected. SQL> EXPLAIN PLAN FOR SELECT /* INDEX(LKPCDE_UK) */ ID FROM BLC WHE RE UPPER ( GVM ) = 'MAIN_ORG'; Explained. SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY); PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- Plan hash value: 3196655606 -------------------------------------------------------------------------------- ------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------- ------ PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 78 | 624 | 18 (0)| 00:0 0:01 | |* 1 | TABLE ACCESS FULL| BLC | 78 | 624 | 18 (0)| 00:0 0:01 | -------------------------------------------------------------------------------- ------ Predicate Information (identified by operation id): PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- --------------------------------------------------- 1 - filter(UPPER("GVM")='MAIN_ORG') 13 rows selected.
Please let me know how I can force it to use an index as it is causing the CPU usage.
I can't change the query in the application it is used in several places.
Thank you
And/or read: ORACLE-BASE - Oracle function index
-
If the INSTR function will not use the INDEX o?
Hi all
I have a querry as
Is simple index on column Col1. If we use the index will be used or full table scan will happen in this scenario?Select * from Tab1 Where Instr(Tab1.Col1,'XX') >0 ;
Please give me explanatory answer because I have doubts
DhabasHello
You must use the index function if you want to avoid the full table scan. Check this box
SQL> create table tab1(col1 varchar(20)) 2 / Table created. SQL> insert into tab1 values ('XXAB') 2 / 1 row created. SQL> create index col1_idx on tab1(col1); Index created. SQL> explain plan for Select * from Tab1 Where Instr(Tab1.Col1,'XX') >0; Explained. SQL> set autotrace on SQL> Select * from Tab1 Where Instr(Tab1.Col1,'XX') >0; XXAB Execution Plan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=5 Card=1 Bytes=12) 1 0 TABLE ACCESS (FULL) OF 'TAB1' (TABLE) (Cost=5 Card=1 Bytes =12) Statistics ---------------------------------------------------------- 4 recursive calls 0 db block gets 32 consistent gets 0 physical reads 0 redo size 234 bytes sent via SQL*Net to client 280 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed SQL> create index col1_idx2 on tab1(Instr(Col1,'XX')); Index created. SQL> Select * from Tab1 Where Instr(Tab1.Col1,'XX') >0; XXAB Execution Plan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=2 Card=1 Bytes=12) 1 0 TABLE ACCESS (BY INDEX ROWID) OF 'TAB1' (TABLE) (Cost=2 Ca rd=1 Bytes=12) 2 1 INDEX (RANGE SCAN) OF 'COL1_IDX2' (INDEX) (Cost=1 Card=1 ) Statistics ---------------------------------------------------------- 28 recursive calls 0 db block gets 22 consistent gets 0 physical reads 0 redo size 234 bytes sent via SQL*Net to client 280 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed SQL>
Thank you
AJ -
Using the index to extract data without filter predicate
Hello
does anyone have an explanation for the following scenario:
I have a table T1 with an OID_IX index on column (object_id) - the table is a DEC dba_objects just to fill it with data.
There are no other current index. The table and index are analysed.
When I run the following query, the table is available in FULL (without using the index)
SELECT OBJECT_ID FROM T1;
SQL > select object_id from t1;
485984 selected lines.
Elapsed time: 00:00:01.76
Execution plan
----------------------------------------------------------
Hash value of plan: 3617692013
--------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | 485K | 2372K | 1528 (1) | 00:00:19 |
| 1. TABLE ACCESS FULL | T1 | 485K | 2372K | 1528 (1) | 00:00:19 |
--------------------------------------------------------------------------
Statistics
----------------------------------------------------------
1 recursive calls
0 db block Gets
7396 gets coherent
0 physical reads
0 redo size
2887158 bytes sent via SQL * Net to client
5684 bytes received via SQL * Net from client
487 SQL * Net back and forth to and from the client
0 sorts (memory)
0 sorts (disk)
485984 rows processed
But if I add a predicate (even if it is useless in this case) the index is taken and that the query runs faster:
JDBC@toekb > select object_id from t1 where object_id. = - 999;
485960 selected lines.
Elapsed time: 00:00:01.40
Execution plan
----------------------------------------------------------
Hash value of plan: 3555700789
-------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | 485K | 2372K | 242 (3) | 00:00:03 |
|* 1 | FULL RESTRICTED INDEX SCAN FAST | OID_IX | 485K | 2372K | 242 (3) | 00:00:03 |
-------------------------------------------------------------------------------
Information of predicates (identified by the operation identity card):
---------------------------------------------------
1 Filter ("OBJECT_ID" <>-(999))
Statistics
----------------------------------------------------------
1 recursive calls
0 db block Gets
1571 gets coherent
0 physical reads
0 redo size
2766124 bytes sent via SQL * Net to client
5684 bytes received via SQL * Net from client
487 SQL * Net back and forth to and from the client
0 sorts (memory)
0 sorts (disk)
485960 rows processed
Here is my setup:
SQLsql-
drop table t1 purge;
create table t1 tablespace users in select * from dba_objects;
Insert into t1 (select * from t1);
commit;
Insert into t1 (select * from t1);
commit;
Insert into t1 (select * from t1);
commit;
create index oid_ix on t1 (object_id) tablespace users;
exec dbms_stats.gather_table_stats (null, 't1', cascade = > true, estimate_percent = > 100);
SQLsql-
In my case, the Table and the Index looks like this way:
JDBC@toekb > select table_name, NUM_ROWS, BLOCKS, AVG_SPACE from user_tables;
TABLE_NAME, NUM_ROWS BLOCKS AVG_SPACE
=======================================
485984 6944 T1 0
Elapsed time: 00:00:00.11
JDBC@toekb > select INDEX_NAME, BLEVEL, LEAF_BLOCKS, DISTINCT_KEYS, NUM_ROWS user_indexes.
INDEX_NAME BLEVEL LEAF_BLOCKS DISTINCT_KEYS NUM_ROWS
===================================================
2 1074 60745 485960 OID_IX
Elapsed time: 00:00:00.07
The table contains 7 times more than the index blocks!
any answer welcome
Best regards
Published by: guenterp on August 12, 2010 14:44The column is not defined as NOT NULL, then there may be values that are not in the index (because the index does not include null values). The useless predicate implies NOT NULL, then the index may be used.
-
SDO_NN cannot be assessed without using the index
Hello
I'll try to find more close neighbours of a point using two tables (grafo_ped_links & haltestellen) and I fail miserably quiet.
Select h.desc_i, grafo_ped_links h.numpal g, haltestellen h where (g.geometry, h.geometry) sdo_nn = 'true' and g.start_node_id = 355 and rownum < = 5
*
ERROR on line 1:
ORA-13249: SDO_NN cannot be assessed without using the index
ORA-06512: at the 'MDSYS. MD", line 1723
ORA-06512: at the 'MDSYS. MDERR", line 17
ORA-06512: at the 'MDSYS. PRVT_IDX', line 49
But I am able to find the nearest neighbor on individual tables (singularly) without any problem. I'm even able to find a WITHIN_DISTANCE using two tables (below the sql statement).
Select h.numpal from grafo_ped_links g, haltestellen h where SDO_WITHIN_DISTANCE (h.geometry, g.geometry, 'DISTANCE = 0.5 UNIT = KM') = 'TRUE' and g.start_node_id = 355;
NUMPAL
----------
5122
5103
5102
5120
5100
5301
5302
5303
I even dropped the indexes of the two tables and recreated them again. I read somewhere that the problem could be due to a lack of advice, so I tried the following and I still get the same error.
Select / * + LEADING (g) INDEX (h haltestellen_ridx) * / h.desc_i, h.numpal
of grafo_ped_links g, h haltestellen
where (g.geometry, h.geometry) sdo_nn = 'true' and g.start_node_id = 355 and rownum < = 5
Select / * + INDEX (h haltestellen_ridx) NO_INDEX (g grafo_ped_links_ridx) * / h.desc_i, h.numpal
of grafo_ped_links g, h haltestellen
where (g.geometry, h.geometry) sdo_nn = 'true' and g.start_node_id = 355 and rownum < = 5
Select / * + USE_NL (h, g) VALUE * / h.desc_i, h.numpal
of grafo_ped_links g, h haltestellen
where sdo_nn (g.geometry, h.geometry, 'sdo_num_res = 5', 1) = 'true' and g.start_node_id = 355 and rownum < = 5
Anyone can please, show me the way, or give a hint. I use oracle spatial 11g.
Thank you!
Cook
Published by: user611283 on December 30, 2009 06:11It should be 'TRUE '.
Select h.desc_i, grafo_ped_links h.numpal g, haltestellen h where (h.geometry, g.geometry) sdo_nn = 'TRUE' and g.start_node_id = 355 and rownum<=>=>
-
Hi all
Version of DB: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
Here is the description of the problem:
(The statistics are up to date for all tables).
The query below does not use the index on ACCOUNTS_LIVE (ID). (Unique index)
Line 23 of the query uses accounts_live.id.SQL> explain plan for 2 select txn.account_number,to_number(txn.amount_lcy) txn_amt,to_date(booking_date,'YYYYMMDD') TXN_DATE, 3 sal.latest_sal,sal.sal_date,customer_name,employer_name, 4 decode(COMMUNICATION_TYPE_1,'MOBILE',COMMUNICATION_NO_1, 5 decode(COMMUNICATION_TYPE_2,'MOBILE',COMMUNICATION_NO_2)) mob, 6 txn.CURRENCY, CHEQUE_NUMBER,trans_dets,trans_reference,target,teller_id,acc.category,acc.inactive_marker, 7 acc.posting_restrict,cus.sector,cus.industry 8 from coreadmin.Gtxn_dtl_v1 txn, 9 (select account_number,round(to_number(nvl(amount_lcy,0)),2) latest_sal,TXN_DATE sal_date,rr 10 from 11 (select to_date(booking_date,'YYYYMMDD') TXN_DATE,batch_id,account_number,amount_lcy 12 ,row_number() over (partition by account_number 13 order by to_date(booking_date,'YYYYMMDD') desc NULLS LAST, 14 batch_id desc nulls last) rr, 15 CURRENCY, CHEQUE_NUMBER,trans_dets,trans_reference 16 from coreadmin.Gtxn_dtl_v1 17 where transaction_code in ('204','938') 18 and to_number(amount_lcy) > 0) 19 where rr = 1 20 ) sal,accounts_live acc,customers_live cus 21 where to_date(booking_date,'YYYYMMDD') between to_date('030109','DDMMRR') and to_date('020209','DDMMRR') 22 and txn.account_number = sal.account_number 23 and txn.account_number = acc.id 24 and txn.CUSTOMER_ID = cus.CUSTOMER_number 25 and target in ('30','31','32') 26 / Explained. SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------ Plan hash value: 920245766 ----------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | ----------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 363M| 121G| | 223K (4)| 00:44:47 | |* 1 | HASH JOIN | | 363M| 121G| 6232K| 223K (4)| 00:44:47 | |* 2 | VIEW | | 34453 | 5820K| | 147K (1)| 00:29:36 | |* 3 | WINDOW SORT PUSHED RANK | | 34453 | 1480K| 4072K| 147K (1)| 00:29:36 | |* 4 | FILTER | | | | | | | | 5 | INLIST ITERATOR | | | | | | | |* 6 | TABLE ACCESS BY INDEX ROWID| GTXN_DTL_V1 | 34453 | 1480K| | 147K (1)| 00:29:31 | |* 7 | INDEX RANGE SCAN | IDX_TXN5 | 707K| | | 1815 (2)| 00:00:22 | |* 8 | HASH JOIN | | 598K| 106M| 20M| 63724 (1)| 00:12:45 | |* 9 | MAT_VIEW ACCESS FULL | CUSTOMERS_LIVE | 227K| 17M| | 2239 (4)| 00:00:27 | |* 10 | HASH JOIN | | 598K| 59M| 9504K| 57157 (1)| 00:11:26 | | 11 | MAT_VIEW ACCESS FULL | ACCOUNTS_LIVE | 249K| 6577K| | 1832 (2)| 00:00:22 | |* 12 | TABLE ACCESS BY INDEX ROWID | GTXN_DTL_V1 | 597K| 43M| | 52319 (1)| 00:10:28 | |* 13 | INDEX RANGE SCAN | IDX_TXN11_V1 | 1204K| | | 3931 (2)| 00:00:48 | ----------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - access("TXN"."ACCOUNT_NUMBER"="ACCOUNT_NUMBER") 2 - filter("RR"=1) 3 - filter(ROW_NUMBER() OVER ( PARTITION BY "ACCOUNT_NUMBER" ORDER BY TO_DATE("BOOKING_DATE",'YYYYMMDD') DESC NULLS LAST,INTERNAL_FUNCTION("BATCH_ID") DESC NULLS LAST)<=1) 4 - filter(TO_DATE('030109','DDMMRR')<=TO_DATE('020209','DDMMRR')) 6 - filter(TO_NUMBER("AMOUNT_LCY")>0) 7 - access("TRANSACTION_CODE"='204' OR "TRANSACTION_CODE"='938') 8 - access("TXN"."CUSTOMER_ID"="CUS"."CUSTOMER_NUMBER") 9 - filter("TARGET"='30' OR "TARGET"='31' OR "TARGET"='32') 10 - access("TXN"."ACCOUNT_NUMBER"="ACC"."ID") 12 - filter("TXN"."CUSTOMER_ID" IS NOT NULL) 13 - access(TO_DATE("BOOKING_DATE",'YYYYMMDD')>=TO_DATE('030109','DDMMRR') AND TO_DATE("BOOKING_DATE",'YYYYMMDD')<=TO_DATE('020209','DDMMRR')) 38 rows selected. SQL> select index_name 2 from dba_ind_columns 3 where table_name = 'ACCOUNTS_LIVE' 4 and column_name = 'ID'; INDEX_NAME ------------------------------ IDX_ACCLIVE
11 the order ID explain plan shows that the index does not use.
Please suggest.
Thanks in advance,
JacWhat happens when you force the index by using hint and use the hash between txn and acc join?
See you soon
Sarma. -
Using the index function in where clause of Exchange.
Hello friends,
I need your help with a problem.
I have a query that uses two table Say T1 and T2, where C1 is common column with which both are joined.
C1 is the primary key in T1, but no index available in Q2 for the C1. T1C2 is the column that we want to select.
(Note that table may be a Master table)
Now let's see the query:
Select T1C2
From T1, T2
where T2. C1 = T1. C1
Here where the clause may have other conditions and From clause can have other tables as needed.
I want to know that if I have change the query as continuation of leave my query to use the index available of T1. C1.
Select T1C2
from T1, T2
where T1. C1 = T2.C1
Then, the query uses the index available of T1. and I get better performance. Even a small improvement of performance help me much because this type of query is used in a loop where clause (so it will be run several times).
Please advise on this...
Kind regards
Lifexisxnotxsoxbeautiful...Hello
18:43:17 rel15_real_p>create table t1(c1 number primary key, c2 number); Table created. 18:43:26 rel15_real_p>create table t2(c1 number, c2 number); 18:45:08 rel15_real_p> 18:45:09 rel15_real_p>begin 18:45:09 2 for i in 1..100 18:45:09 3 loop 18:45:09 4 insert into t1(c1,c2) values (i,i+100); 18:45:09 5 end loop; 18:45:09 6 commit; 18:45:09 7 end; 18:45:09 8 / PL/SQL procedure successfully completed. 18:45:09 rel15_real_p> 18:45:09 rel15_real_p> 18:45:09 rel15_real_p>begin 18:45:09 2 for i in 1..100 18:45:09 3 loop 18:45:09 4 insert into t2(c1,c2) values (i,i+200); 18:45:09 5 end loop; 18:45:09 6 commit; 18:45:09 7 end; 18:45:09 8 / 18:45:23 rel15_real_p>select count(*) from t1; COUNT(*) ---------- 100 18:45:30 rel15_real_p>select count(*) from t2; COUNT(*) ---------- 100 18:45:49 rel15_real_p>select index_name,index_type from user_indexes where table _name='T1'; INDEX_NAME INDEX_TYPE ------------------------------ --------------------------- SYS_C0013059 NORMAL 18:48:21 rel15_real_p>set autotrace on 18:52:25 rel15_real_p>Select T1.C2 18:52:29 2 From T1, T2 18:52:29 3 where T2.C1 = T1.C1 18:52:29 4 / C2 ---------- 101 102 103 104 105 ..... ...... C2 ---------- 200 100 rows selected. Execution Plan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=7 Card=100 Bytes= 900) 1 0 HASH JOIN (Cost=7 Card=100 Bytes=3900) 2 1 TABLE ACCESS (FULL) OF 'T1' (TABLE) (Cost=3 Card=100 By es=2600) 3 1 TABLE ACCESS (FULL) OF 'T2' (TABLE) (Cost=3 Card=100 By es=1300) Statistics ---------------------------------------------------------- 0 recursive calls 0 db block gets 21 consistent gets 0 physical reads 0 redo size 1393 bytes sent via SQL*Net to client 562 bytes received via SQL*Net from client 8 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 100 rows processed 18:52:31 rel15_real_p>analyze table t1 compute statistics; Table analyzed. 18:55:35 rel15_real_p>analyze table t2 compute statistics; 18:55:38 rel15_real_p>set autotrace on 18:55:42 rel15_real_p>Select T1.C2 18:55:43 2 From T1, T2 18:55:45 3 where T2.C1 = T1.C1 18:55:46 4 / C2 ---------- 101 102 103 104 105 ..... ...... C2 ---------- 200 100 rows selected. Execution Plan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=100 Bytes=7 00) 1 0 MERGE JOIN (Cost=6 Card=100 Bytes=700) 2 1 TABLE ACCESS (BY INDEX ROWID) OF 'T1' (TABLE) (Cost=2 Ca rd=100 Bytes=500) 3 2 INDEX (FULL SCAN) OF 'SYS_C0013059' (INDEX (UNIQUE)) ( Cost=1 Card=100) 4 1 SORT (JOIN) (Cost=4 Card=100 Bytes=200) 5 4 TABLE ACCESS (FULL) OF 'T2' (TABLE) (Cost=3 Card=100 B ytes=200) Statistics ---------------------------------------------------------- 1 recursive calls 0 db block gets 23 consistent gets 0 physical reads 0 redo size 1393 bytes sent via SQL*Net to client 562 bytes received via SQL*Net from client 8 SQL*Net roundtrips to/from client 1 sorts (memory) 0 sorts (disk) 100 rows processed 18:56:56 rel15_real_p>Select T1.C2 18:56:56 2 From T1, T2 18:56:56 3 where T1.C1 = T2.C1 18:56:58 4 / C2 ---------- 101 102 103 104 105 ..... ...... C2 ---------- 200 100 rows selected. Execution Plan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=100 Bytes=7 00) 1 0 MERGE JOIN (Cost=6 Card=100 Bytes=700) 2 1 TABLE ACCESS (BY INDEX ROWID) OF 'T1' (TABLE) (Cost=2 Ca rd=100 Bytes=500) 3 2 INDEX (FULL SCAN) OF 'SYS_C0013059' (INDEX (UNIQUE)) ( Cost=1 Card=100) 4 1 SORT (JOIN) (Cost=4 Card=100 Bytes=200) 5 4 TABLE ACCESS (FULL) OF 'T2' (TABLE) (Cost=3 Card=100 B ytes=200) Statistics ---------------------------------------------------------- 1 recursive calls 0 db block gets 23 consistent gets 0 physical reads 0 redo size 1393 bytes sent via SQL*Net to client 562 bytes received via SQL*Net from client 8 SQL*Net roundtrips to/from client 1 sorts (memory) 0 sorts (disk) 100 rows processed
-Pavan Kumar N
-
SDO_NN giving ORA-13249: SDO_NN cannot be assessed without using the index
Hi people,
I do not understand why the SDO_NN gives ORA-13249 in circumstances.
SQL > SELECT SlavaTest WHERE SDO_NN s s.title (s.geometry, SDO_GEOMETRY (2001, 4326, SDO_POINT (14.0, 49.0, NULL), null, null)) = 'TRUE' and title like '%' and rownum < 10;
TITLE
--------------------------------------------------------------------------------
MultiPoint_305199
LineString_691779
MultiPolygon_180478
MultiPolygon_358113
MultiPolygon_53008
MultiPolygon_249905
MultiPolygon_204076
MultiPolygon_636994
MultiPoint_464514
9 selected lines.
SQL > SELECT SlavaTest WHERE SDO_NN s s.title (s.geometry, SDO_GEOMETRY (2001, 4326, SDO_POINT (14.0, 49.0, NULL), null, null)) = 'TRUE' and timestamp > = to_timestamp (January 6, 2011 ', ' dd/mm/yyyy') and rownum < 10;
SELECT SlavaTest WHERE SDO_NN s s.title (s.geometry, SDO_GEOMETRY (2001, 4326, SDO_POINT (14.0, 49.0, NULL), null, null)) = 'TRUE' and timestamp > = to_timestamp (January 6, 2011 ', ' dd/mm/yyyy') and rownum < 10
*
ERROR on line 1:
ORA-13249: SDO_NN cannot be assessed without using the index
ORA-06512: at the 'MDSYS. MD", line 1723
ORA-06512: at the 'MDSYS. MDERR", line 17
ORA-06512: at the 'MDSYS. PRVT_IDX', line 49
The spatial index is created with:
CREATE the INDEX SlavaTest_geometry_idx_spatial ON SlavaTest (geometry) INDEXTYPE IS mdsys.spatial_index;
'Title' and 'timestamp' columns have an index.
Note the query comes from Hibernate and I can't change it's arbitrary.Slava2 wrote:
What this means - there is a bug in Oracle?Well, it could probably be considered a, but [url http://docs.oracle.com/cd/E11882_01/appdev.112/e11830/sdo_operat.htm#i78067] documentation on SDO_NN warns you:
Documentation says:
However, if the column in the WHERE clause predicate specifies a non-space column in the table for geometry1 with an associated index, make sure that this index is not used by specifying the NO_INDEX indicator for this index.See you soon,.
Stefan -
SELECT on a table in the INSERT statement uses the INDEX
Hello world
I have a strange problem with EA Oracle 10 g (64-bit) running on a Linux system. The situation is, I developed a Java program to migrate one client system to another. One of the steps in the migration fills a new table with the data from the old system. Given that the data on the old system structure is fundamentally different from that new, I have to check each time I read a line from the old system, if I have already created an entity on the new table, and if so, update certain attributes. The WHERE clause of this audit uses a key of the company indexed on the new table. The problem is now, that Oracle does not use the index on the key attribute of the company, but it makes table scans complete to select the line. As you can imagine, the lines first thousand or so go fast, but the amount increases, the program becomes slower and slower.
If I do a "scan" when executing the migration program, Oracle change the execution plan and use the index on the attribute key and everything works fast and smooth. However, if I do the analysis on the empty table first, nothing changes (which I understand it perfectly, since there is nothing to analyze, at this point). By integrating a hint of 'INDEX' (table) in the statement SELECT does not change the full implementation plan (also table scans).
Is it possible to change this behavior, in order to SELECT it uses the index of key business from the beginning?
Greetings from Cologne,
Thorsten.
Published by: thkitz on 13.03.2012 18:27thkitz wrote:
SELECT STATEMENT ALL_ROWSCost: 2 Bytes: 76 Cardinality: 2 7 TABLE ACCESS BY INDEX ROWID TABLE AIDATINT.PRVVSSCHADENKORRESPONDENZ Cost: 2 Bytes: 76 Cardinality: 2 6 BITMAP CONVERSION TO ROWIDS 5 BITMAP OR 2 BITMAP CONVERSION FROM ROWIDS 1 INDEX RANGE SCAN INDEX AIDATINT.I_PRVVSSCHADENKORRESPONDENZ_1 Cost: 1 4 BITMAP CONVERSION FROM ROWIDS 3 INDEX RANGE SCAN INDEX AIDATINT.I_PRVVSSCHADENKORRESPONDENZ_2 Cost: 1
I would have thought that as a plan as possible. It is not a concatenation, is a btree/bitmap conversion.
Allude to this plan you need / * + index_combine (table_alias index1 index2) * /.
For 10g and later the index can be specified by name or by descriptionI'm a bit puzzled why the plan changes after truncate - but maybe my comment about not cleared statistics is no longer true. It is easy enough to check if I'm right or wrong on your version of Oracle.
Concerning
Jonathan Lewis
http://jonathanlewis.WordPress.com
Author: core Oracle -
How to monitor the SQL perticuler using the INDEX or not?
I'm running on a long-term quary and the output is coming very late. So, I want to know that the quary sql uses the index or not? How do I know that?Hello
You have not provided your db version?
You can check v $ object_usage in a simple way. Try to check the explanation of your query if you current sql is by using your existing index or not.
Check with dbms_xplan.displayRequest to go through the links of Ask tom and jonathan lewis
http://jonathanlewis.WordPress.com/2007/02/15/index-not-used-10G/
http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:736825544526HTH
-Pounet N
-
How oracle decide whetehr to use the index or full analysis (statistics)
Hi guys,.
Let's say I have an index on a column.
Tables and index statistics were collected. (without the histograms).
Let's say I have run a select * from table where a = 5;
Oracle will perform a complete analysis.
But what statistics, it will be able to know indeed the greater part of the column = 5? (histograms do not used)
After analysis, we get the following:
Statistical table:
(NUM_ROWS)
(BLOCKS)
(EMPTY_BLOCKS)
(AVG_SPACE)
(CHAIN_COUNT)
(AVG_ROW_LEN)
Index statistics:
(BLEVEL)
(LEAF_BLOCKS)
(DISTINCT_KEYS)
(AVG_LEAF_BLOCKS_PER_KEY)
(AVG_DATA_BLOCKS_PER_KEY)
(CLUSTERING_FACTOR)
Thank you
Index of column (A)
======
1
1
2
2
5
5
5
5
5
5I have prepared a few explanations and did not notice that the topic has been marked as answer.
My sentence is not quite true.
A column "without histograms' means that the column has only a bucket.
More correct: even without the histogram there are data in dba_tab_histograms which can be considered a bucket for the whole column. In fact, these data are extracted from hist_head$, not from $ histgrm as usual buckets.
Technically there are no buckets without combined histograms.Let's create a table with the asymmetric data distribution.
SQL> create table t as 2 select least(rownum,3) as val, '*' as pad 3 from dual 4 connect by level <= 1000000; Table created SQL> create index idx on t(val); Index created SQL> select val, count(*) 2 from t 3 group by val; VAL COUNT(*) ---------- ---------- 1 1 2 1 3 999998
So, we have table with the very uneven distribution of the data.
We collect statistics without histograms.SQL> exec dbms_stats.gather_table_stats( user, 'T', estimate_percent => 100, method_opt => 'for all columns size 1', cascade => true); PL/SQL procedure successfully completed SQL> select blocks, num_rows from dba_tab_statistics 2 where table_name = 'T'; BLOCKS NUM_ROWS ---------- ---------- 3106 1000000 SQL> select blevel, leaf_blocks, clustering_factor 2 from dba_ind_statistics t 3 where table_name = 'T' 4 and index_name = 'IDX'; BLEVEL LEAF_BLOCKS CLUSTERING_FACTOR ---------- ----------- ----------------- 2 4017 3107 SQL> select column_name, 2 num_distinct, 3 density, 4 num_nulls, 5 low_value, 6 high_value 7 from dba_tab_col_statistics 8 where table_name = 'T' 9 and column_name = 'VAL'; COLUMN_NAME NUM_DISTINCT DENSITY NUM_NULLS LOW_VALUE HIGH_VALUE ------------ ------------ ---------- ---------- -------------- --------------- VAL 3 0,33333333 0 C102 C104
Therefore, Oracle suggests that the values between 1 and 3 (raw C102 C104) are distributed uniform and the density of the distribution is 0.33.
We will try to explain the planSQL> explain plan for 2 select --+ no_cpu_costing 3 * 4 from t 5 where val = 1 6 ; Explained SQL> @plan -------------------------------------------------- | Id | Operation | Name | Rows | Cost | -------------------------------------------------- | 0 | SELECT STATEMENT | | 333K| 300 | |* 1 | TABLE ACCESS FULL| T | 333K| 300 | -------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("VAL"=1) Note ----- - cpu costing is off (consider enabling it)
An excerpt from trace 10053
BASE STATISTICAL INFORMATION *********************** Table Stats:: Table: T Alias: T #Rows: 1000000 #Blks: 3106 AvgRowLen: 5.00 Index Stats:: Index: IDX Col#: 1 LVLS: 2 #LB: 4017 #DK: 3 LB/K: 1339.00 DB/K: 1035.00 CLUF: 3107.00 *************************************** SINGLE TABLE ACCESS PATH ----------------------------------------- BEGIN Single Table Cardinality Estimation ----------------------------------------- Column (#1): VAL(NUMBER) AvgLen: 3.00 NDV: 3 Nulls: 0 Density: 0.33333 Min: 1 Max: 3 Table: T Alias: T Card: Original: 1000000 Rounded: 333333 Computed: 333333.33 Non Adjusted: 333333.33 ----------------------------------------- END Single Table Cardinality Estimation ----------------------------------------- Access Path: TableScan Cost: 300.00 Resp: 300.00 Degree: 0 Cost_io: 300.00 Cost_cpu: 0 Resp_io: 300.00 Resp_cpu: 0 Access Path: index (AllEqRange) Index: IDX resc_io: 2377.00 resc_cpu: 0 ix_sel: 0.33333 ix_sel_with_filters: 0.33333 Cost: 2377.00 Resp: 2377.00 Degree: 1 Best:: AccessPath: TableScan Cost: 300.00 Degree: 1 Resp: 300.00 Card: 333333.33 Bytes: 0
FTS here costs 300 and Index Range Scan here costs 2377.
I disabled cpu cost, so the selectivity does not affect the cost of FTS.
cost of the Index Range Scan is calculated as
blevel + (leaf_blocks * selectivity + clustering_factor * selecivity) = 2 + (4017 * 0.33333 + 3107 * 0.33333) = 2377.
Oracle believes that he must read 2 blocks root/branch index, 1339 the index leaf blocks and 1036 blocks in the table.
Pay attention that the selectivity is the main component of the cost of the Index Range Scan.We will try to collect histograms:
SQL> exec dbms_stats.gather_table_stats( user, 'T', estimate_percent => 100, method_opt => 'for columns val size 3', cascade => true); PL/SQL procedure successfully completed
If you look at dba_tab_histograms you can see more
SQL> select endpoint_value, 2 endpoint_number 3 from dba_tab_histograms 4 where table_name = 'T' 5 and column_name = 'VAL' 6 ; ENDPOINT_VALUE ENDPOINT_NUMBER -------------- --------------- 1 1 2 2 3 1000000
ENDPOINT_VALUE is the value of the column (in number for any type of data) and ENDPOINT_NUMBER is the cumulative number of lines.
Number of lines for any ENDPOINT_VALUE = ENDPOINT_NUMBER for this ENDPOINT_VALUE - ENDPOINT_NUMBER to the previous ENDPOINT_VALUE.explain the plan and track 10053 the same query:
------------------------------------------------------------ | Id | Operation | Name | Rows | Cost | ------------------------------------------------------------ | 0 | SELECT STATEMENT | | 1 | 4 | | 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 4 | |* 2 | INDEX RANGE SCAN | IDX | 1 | 3 | ------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("VAL"=1) Note ----- - cpu costing is off (consider enabling it)
*************************************** BASE STATISTICAL INFORMATION *********************** Table Stats:: Table: T Alias: T #Rows: 1000000 #Blks: 3106 AvgRowLen: 5.00 Index Stats:: Index: IDX Col#: 1 LVLS: 2 #LB: 4017 #DK: 3 LB/K: 1339.00 DB/K: 1035.00 CLUF: 3107.00 *************************************** SINGLE TABLE ACCESS PATH ----------------------------------------- BEGIN Single Table Cardinality Estimation ----------------------------------------- Column (#1): VAL(NUMBER) AvgLen: 3.00 NDV: 3 Nulls: 0 Density: 5.0000e-07 Min: 1 Max: 3 Histogram: Freq #Bkts: 3 UncompBkts: 1000000 EndPtVals: 3 Table: T Alias: T Card: Original: 1000000 Rounded: 1 Computed: 1.00 Non Adjusted: 1.00 ----------------------------------------- END Single Table Cardinality Estimation ----------------------------------------- Access Path: TableScan Cost: 300.00 Resp: 300.00 Degree: 0 Cost_io: 300.00 Cost_cpu: 0 Resp_io: 300.00 Resp_cpu: 0 Access Path: index (AllEqRange) Index: IDX resc_io: 4.00 resc_cpu: 0 ix_sel: 1.0000e-06 ix_sel_with_filters: 1.0000e-06 Cost: 4.00 Resp: 4.00 Degree: 1 Best:: AccessPath: IndexRange Index: IDX Cost: 4.00 Degree: 1 Resp: 4.00 Card: 1.00 Bytes: 0
Be careful on selectivity, ix_sel: 1.0000e - 06
Cost of the FTS is always the same = 300,
but the cost of the Index Range Scan is now 4: 2 blocks from root/branch + block 1 sheet + 1 table blocks.So, conclusion: histograms to calculate more accurate selectivity. The goal is to have more efficient execution plans.
Alexander Anokhin
http://alexanderanokhin.WordPress.com/ -
Display performance of resources by using the index of area XDBHI_IDX
Hi all
We have an application XMLDB home grown to make the validation of diagram against incoming messages. Enforcement issues several queries like below. I know, it analyzes the hard, which is very bad, but it's not where the real problem is at the moment. The problem is with the index of XDBHI_IDX field against xdb resource table $. We use a very specific way of results in the rows returned 0 or 1, but as you can see that the domain index has an intermediate result of 48041 lines, so the index is not effective here. Statistics are up to date, the index has been rebuild. Does anyone know what we can do with the index of the field to do what he must do: identify an xml document in this way?
Kind regardsSELECT 0 FROM resource_view WHERE any_path= '/home/app/incoming/ARCH_IN/2012/01/592174' call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 2 0.02 0.02 0 1041 0 0 Execute 2 0.00 0.00 0 0 0 0 Fetch 2 81.26 85.43 0 202556 576158 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 6 81.28 85.45 0 203597 576158 0 Misses in library cache during parse: 1 Optimizer mode: ALL_ROWS Parsing user id: 67 (app) (recursive depth: 3) Rows Row Source Operation ------- --------------------------------------------------- 0 TABLE ACCESS BY INDEX ROWID XDB$RESOURCE (cr=341531 pr=0 pw=0 time=60883725 us) 48041 DOMAIN INDEX XDBHI_IDX (cr=311030 pr=0 pw=0 time=1548774 us)
Rob.
PS: The database version is 10.2.0.3.0Hi Rob,
See EQUALS_PATH (and UNDER_PATH) conditions: http://docs.oracle.com/cd/B19306_01/server.102/b14200/conditions010.htm#i1051094
SQL> select * 2 from resource_view v 3 where equals_path(v.res, '/office/excel/docs') = 1 4 ; Execution Plan ---------------------------------------------------------- Plan hash value: 3007404872 -------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 81 | 17172 | 32 (0)| 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID| XDB$RESOURCE | 81 | 17172 | 32 (0)| 00:00:01 | |* 2 | DOMAIN INDEX | XDBHI_IDX | | | | | -------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("XDB"."EQUALS_PATH"(SYS_MAKEXML('8758D485E6004793E034080020B242C6',734 ,"XMLEXTRA","XMLDATA"),'/office/excel/docs',8888)=1)
-
query not using the index for some user
Hello
I have a query that is running in less than a second for sys, system, or schema owner. However, another user (test_user) take 30 seconds to run the same query.
I certainly dba and privileges identical to test_user as schmea_user, but the result is the same.
I checked
Select * from V$ SYS_OPTIMIZER_ENV;
Both are the same for both users.
I have check the plan to explain to both users. I noticed that for sys/system/schema_owner, the query uses an index, but not the test_user.
All have experience the issue where a user uses an index, but not the other?
Thank you for any assistance.Thank you for the display of formatting output, this output is much easier to read.
One of the first things you notice about the execution plans that is for the owner non-schema "SQL_ID, 0wcs85uywn72m, number of children 1" appears in the output of DBMS_XPLAN, while "SQL_ID 0wcs85uywn72m, child number 0" (the same SQL_ID but a different number of child) appears for the schema owner. "" Whereas the SQL_ID is the same, which indicates that the client requires exactly the same SQL statement, so it's a good start.
Then, note that in the predicate for the nonschema owner information section the following appears (sometimes with the order of the two conditions switched in position) as a condition placed on each table that is available in the schema:
filter(("SEAL_FLAG" IS NULL OR "SEAL_FLAG"'Y'))
The above suggests the presence of the virtual private database (or a superset of private database virtual) generated the predicates. You should be able to confirm that this is the case by querying V$ VPD_POLICY using the SQL_ID which was displayed in the DBMS_XPLAN output:
SELECT * FROM V$VPD_POLICY WHERE SQL_ID='0wcs85uywn72m';
As a test, I made a few minor adjustments to the example on this page:
http://Antognini.ch/2011/09/optimizer_secure_view_merging-and-VPD/
I changed the name of T to T12 and TESTUSER table specified for the schema names. I then created the function S of this page as follows:CREATE OR REPLACE FUNCTION s (schema IN VARCHAR2, tab IN VARCHAR2) RETURN VARCHAR2 AS BEGIN RETURN 'ID < 10'; END; /
I then added a couple of lines in the T12 test table:
INSERT INTO T12 VALUES (1,1,NULL); INSERT INTO T12 VALUES (4,1,NULL); INSERT INTO T12 VALUES (10,1,NULL); INSERT INTO T12 VALUES (12,1,NULL); COMMIT;
With an active 10053 trace, I executed the following SQL statement:
SELECT id, pad FROM t12 WHERE spy(id, pad) = 1
The SQL_ID (in my case, found in the 10053 trace file) was 6hqw5p9d8g8wf, so I checked V$ VPD_POLICY to this SQL_ID:
SELECT * FROM V$VPD_POLICY WHERE SQL_ID='6hqw5p9d8g8wf'; ADDRESS PARADDR SQL_HASH SQL_ID CHILD_NUMBER OBJECT_OWNER OBJECT_NAME POLICY_GROUP POLICY POLICY_FUNCTION_OWNER PREDICATE ---------------- ---------------- ---------- ------------- ------------ ------------ ------------------------------ ------------------------------ ---------------------- ------------------------------ ------------------------------------------------------------------------------------ 000007FFB7701608 000007FFB7743350 1518838670 6hqw5p9d8g8wf 0 TESTUSER T12 SYS_DEFAULT T_SEC TESTUSER ID < 10
As noted above, the VPD test function named S added the predicate "ID".< 10"="" to="" the="" sql="">
There are not many clues in the 10053 trace file in my test VPD generated additional predicates. Trace the following was found shortly after the beginning of the file (this is the SQL statement initially presented):
----- Current SQL Statement for this session (sql_id=6hqw5p9d8g8wf) ----- SELECT id, pad FROM t12 WHERE spy(id, pad) = 1
I searched then down in the trace for final after changes query file (to be noted that this sentence could be slightly different in different versions of database Oracle). That's what I found:
Final query after transformations: ******* UNPARSED QUERY IS ******* SELECT "T12"."ID" "ID","T12"."PAD" "PAD" FROM "TESTUSER"."T12" "T12" WHERE "TESTUSER"."SPY"("T12"."ID","T12"."PAD")=1 AND "T12"."ID"<10 kkoqbc: optimizing query block SEL$F5BB74E1 (#0)
Note that the final query after transformation shows how the final version of the query that has been rewritten by the query optimizer before the SQL statement has been executed and this version of the query includes AND "T12". "" IDENTITY CARD ".<10. if="" i="" was="" attempting="" to="" determine="" how="" that="">10.><10 predicate="" was="" added="" to="" the="" sql="" statement,="" i="" would="" start="" at="" the="" "current="" sql="" statement="" for"="" line="" in="" the="" trace="" file="" and="" search="" down="" the="" trace="" file="" for="">10><10* -="" in="" this="" case,="" the="" following="" is="" what="" i="" found="" as="" the="" first="" search="" result,="" very="" close="" to="" the="" "current="" sql="" statement="" for"="" line="" in="" the="" trace="">10*>
************************** Predicate Move-Around (PM) ************************** PM: PM bypassed: Outer query contains no views. PM: PM bypassed: Outer query contains no views. query block SEL$F5BB74E1 (#0) unchanged FPD: Considering simple filter push in query block SEL$F5BB74E1 (#0) "TESTUSER"."SPY"("T12"."ID","T12"."PAD")=1 AND "T12"."ID"<10 try to generate transitive predicate from check constraints for query block SEL$F5BB74E1 (#0) finally: "TESTUSER"."SPY"("T12"."ID","T12"."PAD")=1 AND "T12"."ID"<10
As can be seen from the above (because the predicate again appeared before and after the line containing the word "Finally: '), the AND"T12 ". "" IDENTITY CARD ".<10 predicate="" was="" already="" added="" to="" the="" original="" sql="" statement="" by="" the="" time="" the="" predicate="" move-around="" section="" of="" the="" trace="" file="" was="" written,="" and="" that="" is="" the="" first="" mention="" of="">10><10 in="" the="" trace="" file.="" in="" your="" case,="" you="" would="" search="" the="" 10053="" trace="" file="">10>
"SEAL_FLAG" IS NULL
If V$ VPD_POLICY revealed that there are virtual private database (VPD) generated predicates applied to the SQL statement, take a look at the following article in the Oracle documentation library:
http://docs.Oracle.com/CD/B28359_01/network.111/B28531/VPD.htmThis article lists the different points of view, who can be interviewed to learn more about the VPD rules which are in force in the schema. For example, with my SPV test:
SELECT * FROM ALL_POLICIES; OBJECT_OWNER OBJECT_NAME POLICY_GROUP POLICY_NAME PF_OWNER PACKAGE FUNCTION SEL INS UPD DEL IDX CHK ENA STA POLICY_TYPE LON ------------------------------ ------------------------------ ----------------------------- ------------------------------ ------------------------------ ----------------------------- ------------------------------ --- --- --- --- --- --- --- --- ------------------------ --- TESTUSER T12 SYS_DEFAULT T_SEC TESTUSER S YES YES YES YES NO NO YES NO DYNAMIC NO
He knows performance issues related to the use of VPD, some of which are Oracle Database version-dependent, and some have been fixed in recent versions. Take a look at the following articles if you have access to My Oracle Support:
MetaLink (MOS) Doc ID 728292.1 ' known performance problems when you use transparent encryption data and indexes on the encrypted columns.
MetaLink (MOS) Doc ID 967042.1 "How to investigate Query Performance regressions Caused by VPD (FGAC) predicates?"You might find working through the second of the above that the problem is caused by a bug in database Oracle.
On a side note. Execution plans you have published include the 0 value in the column starts many of the operations in the execution plan. 0 indicates that the operation never actually executed. A 0 is included in the column starts on the line that includes the FULL ACCESS of TABLE of PEOPLE_TRANSACTIONS at least to the OPC. Value 123, a full table of PEOPLE_TRANSACTIONS table scan PROPERTY_CONTAINER_ID was not actually performed.
Charles Hooper
http://hoopercharles.WordPress.com/
IT Manager/Oracle DBA
K & M-making Machine, Inc.
Maybe you are looking for
-
I tried several times to attach a file to a message and every time T-bird crashes. I tried to run T-bird as an administrator and when I did I could attach files.
-
they simply do not work.Click the icon - no new tabCTRL-T - no new tabfile-> new tab - no new tab FireFox 3.6.20--Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; RV:1.9.2.20) Gecko/20110803 AskTbTRL2/3.12.5.17640 NET_mmhpset (.NET CLR 3.5.30729) Win/
-
How can I restore ibooks third point manual?
Hey,. I received a few books of third party in iBooks, I backup them and I need to restore the clear system which is THE captain now and I'm not able to use the Migration Wizard because the system is broken... and I did not Time Machine... so please
-
Intelepoint 8.2 will not install
I tried to install Microsoft Intelepoint 8.2, but it will not be installed. I get the error code 1603. I tried the steps to solve the problem, but they have no wok. So I installed Intelepoint version 7.0 with NO problems. It works very well. Can you
-
I need to know how to turn on my pc
someone put a new hard drive on my pc it crashed they then sent me a disc that is not authentic microsoft, I still have the original product key a microsoft say its bad and I still have all the documents that I bought with the pc.all I want to is put