Using the Index space with joins.
So here's my dilemma...How can we (if possible) deal to join in the ranks of another table when your selection is based on a spatial query.
Oracle EE running on Iinux Oracle running on a 24 base machine, 17 TB of sas drives, 48 GB ram later everything.
The spatial query:
select
id,
length,
speed_limit,
beg_node_id,
from links
where
sdo_anyinteract(geom,
sdo_geometry(2003,8307,null,
sdo_elem_info_array(1,1003,3),
sdo_ordinate_array(-122.228065,37.848629 ,-122.161031,37.825718)
)
) = 'TRUE'
There are 69 million lines in the links table and the query runs very fast (.04 seconds) to return the 1535 lines so I guess that it is using the spatial index. Modify the above query:select * from links ...
and we are in a full table scan. change the selection to include:select * /*+ index ( links sidx_links_geom) */ from links ...
and we're back with the spatial index and fast again, things are. So now, there is a table of nodes with an ID column that is indexed. I want to join the table of the nodes in that I can get the nodes located on each end links like:select
/*+ index (links sidx_links_geom) */
l.id,
l.speed_limit,
l.length,
n.id
from links l
join nodes n on (n.id = l.beg_node_id )
where
sdo_anyinteract(l.geom,
sdo_geometry(2003,8307,null,
sdo_elem_info_array(1,1003,3),
sdo_ordinate_array(-122.228065,37.848629 ,-122.161031,37.825718)
)
) = 'TRUE'
NODES.ID is an indexed column and the exact type even in the form of LINKS. BEG_NODE_ID. So this leaves me a bit confused. The spatial query selects the right set of lines with blinding speed. But try and make a join and we are in the tank speed wise. Any suggestions?
Hello
Try you index / * + ordered * / with spatial condition as the first term?
If you look in the spatial documentation, you can find 'small' opinions about this. :)
Tags: Database
Similar Questions
-
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.
-
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
-
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 -
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
-
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
-
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 -
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 youD 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) codeBest regards
Robert
-
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
-
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.
-
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. -
Is it possible to use the Remote app with the Apple TV connected via ethernet and iPhone via WiFi? When I try this Apple TV does not appear in the list of devices on my iPhone.
Yes, I'm doing exactly this with the same put in place.
If the problem persists the next relative to the following articles might help you.
-
When I use the mail merge with excel file, after I press ok of the progress bar indicates "NaN", mail project window crashes. My file is in the correct format and small size (4-column 4 raws). I use an English version of thunderbird after accidentally, I installed one in my tongue.
I am attaching the screenshot
I solved the problem
has been st@pid excelI created a CSV file in openoffice calculator and everything went smoothly
-
Brother.
We use win7 with Mozila 31, 4.2 with Mozila Android smart phone latest google app store on 04/10/0214. Using the same account with the same email. But the phone does not get any new information of win7 with Mozila 31. PL z give useful information.Hi w3ur_team,
Thank you for your question. I understand that there are two features that are documented in the sync account. However the Android is not synchronized.There are two places we can check:
- In the Android settings, under accounts is the Firefox Sync or Firefox Sync (discouraged) joint account?
- Credentials work on accounts.firefox.com on the mobile device and are there any error messages in the synchronization of the settings menu > sync?
See also Firefox Sync troubleshooting and tips for more troubleshooting steps.
-
How to use the "Toshiba controls" with other players?
Heey
I have a Satellite with Toshiba controls. How can I change so I can use the buttons for other media players and not only Windows Media Player?
A dude sorry for the bad news, but I fear that it is not possible to use the Toshiba controls with another application as with WMP (CD) and WinDVD (DVD)
I think that the utility was already programmed and designed to use only these two applications.
Maybe you are looking for
-
FF 8.0 cannot import Safari bookmarks - no import function
I've updated to Firefox 8.0. I checked the ability to import bookmarks from Safari and I assumed the old Firefox bookmarks would be maintained. I have no bookmarks. The import of Favorites function has been deleted in the file menu and I can find als
-
I need help to connect my iPhone apps on El Captian Office
I need help to connect my iPhone apps on El Captian Office
-
In the control loop time interval and simultaneous measurement
Hello world I just started to learn labview so please do not judge my messy programming I want to constantly measure certain values (humidity, temperature, etc.) and once a certain threshold is crossed, I want to activate a device. Measure and activa
-
I am a mature student older uni which is a two-hour test at hand and I am absolutely helpless when it comes to technology. I want to keep my test on a UBS stick so that I can print to the College, but I have no idea how do. I have window 7. I have in
-
Problem with the commissioning. Cannot use any tool. The start-up test, I got the info below. Who can advise? Serial number 5CD3020SRX Starting the test Hard drive short DST: failure Q0DPLX-6ML6RC-MFPWW1 - 60S 703 failure ID Product ID D5A55EA #ABH