Use of Index, Histograms, etc
Hi all,
We're using Oracle 9.2.04.
I have a table with 500000 rows.
So I have a query that returns only 30242 for a month, like:
SELECT * FROM T1
WHERE TO_CHAR(DT, 'MM/YYYY') = TO_CHAR(ADD_MONTHS(SYSDATE, -1), 'MM/YYYY')
I have a index for this column:
CREATE INDEX IND_T1_DT_FMT ON T1 (TO_CHAR(DT, 'MM/YYYY'))
TABLESPACE TBS_SOME_USER;
There are statistics for this table.
Looking the table data, I have the following distribution:
Qty MON/YY %
1 Feb-09 0.000219142
99 Apr-09 0.021695016
38439 May-09 8.42358314
98231 Jun-09 21.52649641
1 Jul-06 0.000219142
139959 Jul-09 30.6708362
1 Aug-02 0.000219142
1 Aug-07 0.000219142
141362 Aug-09 30.97829184
30242 Sep-09 6.62727962
7990 1.750941213But when a perform the query (that returns 30242 rows - 6.63% of table):
SELECT * FROM T1
WHERE TO_CHAR(DT, 'MM/YYYY') = TO_CHAR(ADD_MONTHS(SYSDATE, -1), 'MM/YYYY')
Oracle uses FTS:
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=432 Card=45633 Bytes
=3011778)
1 0 TABLE ACCESS (FULL) OF 'T1' (Cost=432 Card=45633 Bytes
=3011778)
So, Oracle should not use the index in this case?
Is there any way to gather statistics for this table with a index based function?
Something like this:
EXECUTE DBMS_STATS.GATHER_TABLE_STATS(ownname => 'U1',
tabname => 'T1', method_opt => 'FOR COLUMNS TO_CHAR(DT, ''MM/YYYY'')',
cascade => true, degree => 4);
How can I create histograms for this case?
Or other solution, like Partition?
thank you very much!!!!
Always treat dates like dates.
This
SELECT * FROM T1
WHERE TO_CHAR(DT, 'MM/YYYY') = TO_CHAR(ADD_MONTHS(SYSDATE, -1), 'MM/YYYY')Should be more like this:
SELECT * FROM T1
WHERE DT BETWEEN TRUNC(ADD_MONTHS(SYSDATE,-1),'MM') AND TRUNC(SYSDATE,'MM')-1 ;Then you should index DT.
But, should this query use the index?
Touch and go at 6.63%.
Give it a go using dates as dates and see if it makes a difference.
Is there a problem with the performance of the FTS?
Similar Messages
-
Can I refactor this query to use an index more efficiently?
I have a members table with fields such as id, last name, first name, address, join date, etc.
I have a unique index defined on (last_name, join_date, id).
This query will use the index for a range scan, no sort required since the index will be in order for that range ('Smith'):
SELECT members.*
FROM members
WHERE last_name = 'Smith'
ORDER BY joindate, idIs there any way I can get something like the following to use the index (with no sort) as well:
SELECT members.*
FROM members
WHERE last_name like 'S%'
ORDER BY joindate, idI understand the difficulty is probably; even if it does a range scan on every last name 'S%' (assuming it can?), they're not necessarily in order. Case in point:
Last_Name: JoinDate:
Smith 2/5/2010
Smuckers 1/10/2010An index range scan of 'S%' would return them in the above order, which is not ordered by joindate.
So is there any way I can refactor this (query or index) such that the index can be range scanned (using LIKE 'x%') and return rows in the correct order without performing a sort? Or is that simply not possible?xaeryan wrote:
I have a members table with fields such as id, last name, first name, address, join date, etc.
I have a unique index defined on (last_name, join_date, id).
This query will use the index for a range scan, no sort required since the index will be in order for that range ('Smith'):
SELECT members.*
FROM members
WHERE last_name = 'Smith'
ORDER BY joindate, idIs there any way I can get something like the following to use the index (with no sort) as well:
SELECT members.*
FROM members
WHERE last_name like 'S%'
ORDER BY joindate, idI understand the difficulty is probably; even if it does a range scan on every last name 'S%' (assuming it can?), they're not necessarily in order. Case in point:
Last_Name: JoinDate:
Smith 2/5/2010
Smuckers 1/10/2010An index range scan of 'S%' would return them in the above order, which is not ordered by joindate.
So is there any way I can refactor this (query or index) such that the index can be range scanned (using LIKE 'x%') and return rows in the correct order without performing a sort? Or is that simply not possible?Come on. Index column order does matter. "LIKE 'x%'" actually is full table scan. The db engine accesses contiguous index entries and then uses the ROWID values in the index to retrieve the table rows. -
Why is this query not using the index?
check out this query:-
SELECT CUST_PO_NUMBER, HEADER_ID, ORDER_TYPE, PO_DATE
FROM TABLE1
WHERE STATUS = 'N'
and here's the explain plan:-
1
2 -------------------------------------------------------------------------------------
3 | Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
4 -------------------------------------------------------------------------------------
5 | 0 | SELECT STATEMENT | | 2735K| 140M| 81036 (2)|
6 |* 1 | TABLE ACCESS FULL| TABLE1 | 2735K| 140M| 81036 (2)|
7 -------------------------------------------------------------------------------------
8
9 Predicate Information (identified by operation id):
10 ---------------------------------------------------
11
12 1 - filter("STATUS"='N')
There is already an index on this column, as is shown below:-
INDEX_NAME INDEX_TYPE UNIQUENESS TABLE_NAME COLUMN_NAME COLUMN_POSITION
1 TABLE1_IDX2 NORMAL NONUNIQUE TABLE1 STATUS 1
2 TABLE1_IDX NORMAL NONUNIQUE TABLE1 HEADER_ID 1
So why is this query not using the index on the 'STATUS' Column?
I've already tried using optimizer hints and regathering the stats on the table, but the execution plan still remains the same, i.e. it still uses a FTS.
I have tried this command also:-
exec dbms_stats.gather_table_stats('GECS','GEPS_CS_SALES_ORDER_HEADER',method_opt=>'for all indexed columns size auto',cascade=>true,degree=>4);
inspite of this, the query is still using a full table scan.
The table has around 55 Lakh records, across 60 columns. And because of the FTS, the query is taking a long time to execute. How do i make it use the index?
Please help.
Edited by: user10047779 on Mar 16, 2010 6:55 AMIf the cardinality is really as skewed as that, you may want to look at putting a histogram on the column (sounds like it would be in order, and that you don't have one).
create table skewed_a_lot
as
select
case when mod(level, 1000) = 0 then 'N' else 'Y' end as Flag,
level as col1
from dual connect by level <= 1000000;
create index skewed_a_lot_i01 on skewed_a_lot (flag);
exec dbms_stats.gather_table_stats(user, 'SKEWED_A_LOT', cascade => true, method_opt => 'for all indexed columns size auto');Is an example. -
Simple SQL Query is not using Bitmap index
Hello to All,
We are having Oracle9i Database and using it for the datawarehouse purpose.
I have created the bitmap index on calledinfo column and I am running the following simple query which takes serveral hours to complete:
select * from ssp.ssp_2006_q4 where calledinfo='799992515f'
OR
select calledinfo from ssp.ssp_2006_q4 where calledinfo='799992515f'
I don't know why it is not using the bitmap index: Can anybody help me here?
Thanks in Advance
HashimI know why and everyone that has read Jonathan Lewis' book on the CBO knows why.
Why? Because the CBO thinks the cost of using your index will be higher than the cost of ignoring it.
To see what Oracle is thinking run an explain plan using DBMS_XPLAN for create the output and then rerun it with a hint forcing index usage.
It is a mistake to believe that an index will always make things better. Issues of cardinality, clustering factor, etc. are very important.
Post the explain plans if you have any questions about what they show:
http://www.psoug.org/reference/explain_plan.html -
How can i know if my query is using the index ?
Hello...
How can i know if my query is using the index of the table or not?
im using set autotrace on...but is there another way to do it?
thanks!
Alessandro Falanque.Hi,
You can use Explain Plan for checking that your query is using proper index or not. First you need to check that Plan_table is installed in your database or not. If it is not there THEN THE SCRIPT WILL BE LIKE THIS:
CREATE TABLE PLAN_TABLE (
STATEMENT_ID VARCHAR2 (30),
TIMESTAMP DATE,
REMARKS VARCHAR2 (80),
OPERATION VARCHAR2 (30),
OPTIONS VARCHAR2 (30),
OBJECT_NODE VARCHAR2 (128),
OBJECT_OWNER VARCHAR2 (30),
OBJECT_NAME VARCHAR2 (30),
OBJECT_INSTANCE NUMBER,
OBJECT_TYPE VARCHAR2 (30),
OPTIMIZER VARCHAR2 (255),
SEARCH_COLUMNS NUMBER,
ID NUMBER,
PARENT_ID NUMBER,
POSITION NUMBER,
COST NUMBER,
CARDINALITY NUMBER,
BYTES NUMBER,
OTHER_TAG VARCHAR2 (255),
PARTITION_START VARCHAR2 (255),
PARTITION_STOP VARCHAR2 (255),
PARTITION_ID NUMBER,
OTHER LONG,
DISTRIBUTION VARCHAR2 (30))
TABLESPACE SYSTEM NOLOGGING
PCTFREE 10
PCTUSED 40
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 10240
NEXT 10240
PCTINCREASE 50
MINEXTENTS 1
MAXEXTENTS 121
FREELISTS 1 FREELIST GROUPS 1 )
NOCACHE;
After that write the following command in the SQL prompt.
Explain plan for (Select statement);
Select level, SubStr( lpad(' ',2*(Level-1)) || operation || ' ' ||
object_name || ' ' || options || ' ' ||
decode(id, null , ' ', decode(position, null,' ', 'Cost = ' || position) ),1,100)
|| ' ' || nvl(other_tag, ' ') Operation
from PLAN_TABLE
start with id = 0
connect by
prior id = parent_id;
This will show how the query is getting executed . What are all the indexes it is using etc.
Cheers.
Samujjwal Basu -
How to import tables, indexes, tablespace, etc from a DMP.
Hello,
I like to know how to import tables, indexes, tablespace, etc from an DMP export of a Oracle 10.2.0.1 to be apply on a Oracle 11.2.0. When I import the DMP file all the data is going to one single Tablespace, for example, Users tablespace.
On the original database we have various tablespace's each separated with different content (tables, indexes) and I like to know if it posible to import the same schema,tables, indexes, tablespace all made with one single DMP Export. I can't use DBUA because the software of the database on the 10.2 is missing, I have only a DMP file (24GB) of DMP!.
Thanks for the reply,
Sorry for my english :).
Regards.thanks for that but is not what Im looking for.
Look, on my ORCL directory of the oracle 10.2 I have for example this:
CONTROL01.CTL
EXAMPLE01.DBF
REDO01-1.LOG
REDO01.LOG
REDO02-2.LOG
REDO02.LOG
REDO03-3.LOG
REDO03.LOG
RMAN.DBF
SYSAUX01.DBF
SYSTEM01.DBF
TEMP01.DBF
UNDOTBS01.DBF
USERS01.DBF
TABLESPACE1.ORA
TABLESPACE2.ORA
TABLESPACE3.ORA
TABLESPACE4.ORA
TABLESPACE5.ORA
I make a full export to a DMP. Then in my 11.2 version first I created the user then when import the DMP file none of the tablespace (TABLESPACE1, TABLESPACE2, ETC...) is created, all is going to the USERS tablespace, SO, im looking a way to tell imp command that generates the exactly tablespace structure that i was have on the 10.2.
Hope this can explain more my problem.
Thanks again!. -
How to use cfloop index value as part of another variable
Hello,
I have a RATE form that first asks "how many rates will you
be adding?" that answer generates a series of form elements based
on the answer. You then have a form grid to populate, 3 values for
each rate (price, code, name).
This part works fine. The issue is now I need to INSERT the
values into the table, so I need to use the INDEX value of the
cfloop to recreate the amount (and names) of the fields in the
INSERT statement. How do I escape, or re-create the evaluated form
elements ( in which their count is #i# as the loop goes) when I
need to evaluate for #i# AND evaluate for #form.sku_i_name# at the
same pass?
I am passing, for example, #form.sku_2_Name# where that might
equal "Half Page". The number 2 in that variable was assigned
during the form creation by the current index of a cfloop. Since my
action (insert) page does not know how many (out of 50 possible)
sku's are coming, how do I use the skuCount (another hidden value
passed as well) to create a proper INSERT SQL command when I need
to eval the form element and the index at the same time?
Obviously #sku_#i#_Name# does not work, and #sku_i_Name# does
not either... I know this can be done, and that I am just doing it
wrong.
Thanks for any help!bigbrain28 wrote:
> Thank You, cfsearching! I don't quite understand 100%
how it works
As all three of us indicated you use array notation for this
type of
requirement. In ColdFusion you can use array notation or dot
notation
to access structure data. Almost all data in ColdFusion is
now some
type of structure.
I.E. #Form['myField']# is the same as #Form.myField#.
The advantage is that with array notation you can do things
you can not
do with dot notation. You can reference elements that have
keys that
are illegal variable names such as one with a space.
I.E. #url['my field'] is allowed, #url.my field# would fail
or course.
And you can concatenate the key string as we did with your
example.
I.E. #Form['aString' & aVariable]#
There are many powerful things one can do with this
knowledge. One can
access record sets with array notations. This can allow for
very
sophisticated parsing of a record set.
I.E. #myQuery['column'][row]#
You can dynamical call a variable. Thus creating dynamic code
that does
not even need to know what variables exist until run time.
I.E. #variables[anyName]#
This just scratches the surface. -
Why cant we use sy-index in loop and endloop?where exactly we used sy-index
hi
can u help me for thisHi...
Genereally Sy-index is used in iterative cases like
while....endwhile
and
Do.... Enddo
In LOOP ..... Endloop.... We should use SY-TABIX....
It would be more consistent we use sy-tabix as we loop at internal table so this SY-TABIX points to the current record its reading...
we can use sy-index but rarely depends on condition.....
SY-INDEX and SY-TABIX will not be same always in LOOP and ENDLOOP
Rewards points if satisfied..
Regards
Narin Nandivada -
Use of index based on an attribute when doing an order by
Hi,
I create a table and its indexes like this:
create table poc_wip2 of xmltype
xmlschema "http://www.derwent.co.uk/wpi.xsd" element "WPI"
alter table poc_wip2
add constraint poc_wip2_pk primary key
(XMLDATA."BibPt"."PDOC_COUNTRY",
XMLDATA."BibPt".pdoc_serial, XMLDATA."BibPt".pdoc_kind)
create index pan_index on poc_wip2 t
(extractvalue(value(t),'/WPI/BibPt/@pan'))
Now when I run the query:
select extractvalue(value(t),'/WPI/BibPt/@pan')
from poc_wip2 t
order by extractvalue(value(t),'/WPI/BibPt/@pan')
I can see that a full table scan occurs. I cannot get the query to use the index built on the pan attribute.
I tried adding a INDEX_FFS hint, but this does not work when I name the pan_index, it only works with
INDEX_FFS(t), in which case the query then uses the primary key index.
Is it possible to get the query to use the pan_index index?
Thanks
PeteHi
Create a restricted key figure with the ZSE_BPNV1 and mention the values of the attribute and display the values
Here you can mention your charecteristic and attrribute value both with the key figure
Assign points if useful
Regards
N Ganesh -
Use of Index although a great number of rows is returned....
Hi ,
I have created the following table:
create table all_obj select * from all_objects;
Then i created some indexes:
create index idx_obj on all_obj (object_name)
create index idx_owner on all_obj (owner)
Then i issued the sql statement:
SQL> select count(object_name),owner from all_obj group by owner;
COUNT(OBJECT_NAME) OWNER
719 MDSYS
266 SCOTT_BI
266 INFO_BI
2 TSMSYS
118 DMSYS
20146 PUBLIC
6 OUTLN
171 CTXSYS
612 OLAPSYS
400 SYSTEM
168 EXFSYS
43 SCOTT
32 DBSNMP
1638 ORDSYS
5 ORDPLUGINS
866 SYSMAN
284 XDB
20993 SYS
264 INFORMATICS
212 WMSYS
COUNT(OBJECT_NAME) OWNER
8 SI_INFORMTN_SCHEMA
21 rows selectedand...:
SQL> analyze table all_obj compute statistics;
Table analyzedAt last , i issued the following pair of sql statements:
SQL> select object_name,owner from scott.all_obj where owner='SCOTT'
2 /
43 ãñáììÝò åðéëÝ÷èçêáí.
Ðñüãñáììá åêôÝëåóçò
Plan hash value: 2272571446
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| T
ime |
| 0 | SELECT STATEMENT | | 2249 | 65221 | 68 (0)| 0
0:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| ALL_OBJ | 2249 | 65221 | 68 (0)| 0
0:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_OWNER | 2249 | | 6 (0)| 0
0:00:01 |
Predicate Information (identified by operation id):
2 - access("OWNER"='SCOTT')
ÓôáôéóôéêÜ
0 recursive calls
0 db block gets
12 consistent gets
0 physical reads
0 redo size
1692 bytes sent via SQL*Net to client
407 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
43 rows processedand
SQL> select object_name,owner from scott.all_obj where owner='SYS';
20993 ãñáììÝò åðéëÝ÷èçêáí.
Ðñüãñáììá åêôÝëåóçò
Plan hash value: 2272571446
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| T
ime |
| 0 | SELECT STATEMENT | | 2249 | 65221 | 68 (0)| 0
0:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| ALL_OBJ | 2249 | 65221 | 68 (0)| 0
0:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_OWNER | 2249 | | 6 (0)| 0
0:00:01 |
Predicate Information (identified by operation id):
2 - access("OWNER"='SYS')
ÓôáôéóôéêÜ
0 recursive calls
0 db block gets
3345 consistent gets
0 physical reads
0 redo size
801069 bytes sent via SQL*Net to client
15774 bytes received via SQL*Net from client
1401 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
20993 rows processed
The question is: why the second query uses the index since a great number of records is returned......????
I use Oracle10g.v.2
Thanks...
SimYou were right.....
using:
SQL> EXEC DBMS_STATS.gather_schema_stats(ownname => 'SCOTT');
the optimizer does follow the 'waited' access path....for the 'PUBLIC' records.....
It seems that using the analyze table statement does not permit to gather all the necessary statistics.....(that's why it is depreciated)...!!!!
Thanks.....
Sim -
Restrict the use of index while quering
Hi All
I have a simple emp table with columns empid, name, sal. Empid has a primary key imposed.
Now when i write a statement like this,
select * from emp where empid = <value>;
the optimizer will make use of index.
The question is........... is there anyway to make oracle bypass the use of index without change in above query.Why do you worry of performance issues when the table size is small , when it is huge and the column you r trying use in the query is also indexed the oracle finds the Best execution method to do the execution whether index exists or not , Oracle has a very intelligent Optimizer and no need to use hints unless and until it is really mandatory or when u r using a very complex query where Oracle is not able to deduce the best Execution plan . But by all means you should look at the execution plan how a cerain query Oracle knows of doing it or when u have a diferering opinion then only at that point you force a Optomizer Hint . For other normal cases like the one you are asking it is best to get the results how Oracle executes it and no forcing is required .
-
What is use of index by binaary_integer
Hi All,
I have created to program of collection where we use index by binaary_integer in one program and not use index by binaary_integer in second program, but result is same, any body help me what is use of index by binaary_integer here
1- Declare
Type emp_table_type is table of
emp%rowtype index by binary_integer;
my_emp_table emp_table_type;
Begin
select * bulk collect into my_emp_table from emp;
for i in my_emp_table.first..my_emp_table.last
loop
dbms_output.put_line(my_emp_table(i).ename);
end loop;
end;
2- Declare
Type emp_table_type is table of
emp%rowtype;
my_emp_table emp_table_type;
Begin
select * bulk collect into my_emp_table from emp;
for i in my_emp_table.first..my_emp_table.last
loop
dbms_output.put_line(my_emp_table(i).ename);
end loop;
end;
your suggestion would be greatly appreciated.here is one for you.
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17126/composites.htm#CHDEIDIC -
Amount of temporary tablespace size used for index rebuild
Hi All,
I want to know approximate amount of temporary tablespace size used for index rebuild. I need this information to avoid the insufficient temporary tablespace error during the huge index rebuild.
Is there a query or procedure to find it out.
Thank you.Hi,
While creating the index, the temporary segment is created in the permanent tablespace. So permanent tablespace must have sufficient space.
http://www.oracle-base.com/articles/10g/SpaceObjectTransactionManagement10g.php
http://aprakash.wordpress.com/2010/01/05/numeric-segment-name/
Anand -
2 New Ipads (Retina and Mini)(New to Apple) How do I share purchased apps, but others have each act independently? Mini is for the Wife the Ipad4? is for me. I want to use mine at work, etc. She's home with the kids. Can we set them up seperate, but share
--break--
So we are entirely new to Apple products. I'm an IT guy, but have always been a windows user.
So the Ipad with Retina Display is to be mine (and will use it at work for notes, organization, etc)
The MINI is for the wife.
But, are we allowed and can we.. buy an app and share that app between both devices? IE. Can I buy a copy of Angry Birds for the House and both Ipad's use that single purchase? and if so, can we still run the Ipads seperate other than to share the apps purchased. IE my facebook and email set up on mine and hers on her ipad mini?
When I finally find a note taking app I like, can I share it on her ipad, without her having all my work files, etc?
Thanks for helping out the apple noob. Hoping for a great experience, and anticipate droping $100 in apps the first day.. just don't want to do that twice. If this is against the usage policy, thats unfortunate but good to know. (I mean we can share stuff on PC as long as its in the same household)
thanks again (explanations or links are fine)There are a number of Apple services: iMessage, FaceTime, iCloud, Game center, Find My iPad, etc.
Now, to share apps, music and books you need to have the same Apple ID:
iPad's Settings > iTunes & App Stores > Apple ID > Your purchasing Apple ID.
For the other service, your wife should have her own Apple ID.
All she needs is a valid e-mail address, apply Apple ID below:
https://appleid.apple.com
Here's a limk with useful tips: Note: It's also valid in IOS 6
iOS 5 & iCloud Tips: Sharing an Apple ID With Your Family -
Hi,
I have apple account/password on laptop but can't use the same ID etc on new Ipad. On my account it says ID is only for 1 system. I really want only one ID for both Ipad and laptop.
ThanksIt seems that you have used the AppleIDs to "Purchase" your devices, which marries the two for all time and eternity.
For info - Using your Apple ID for Apple services
For Account security issues - Apple ID: Contacting Apple for help with Apple ID account security
regards
CCC
Maybe you are looking for
-
Getting ClassCastException while calling a method in webservice
I wrote small webservice using axis. It is returning array of object(of xyz type) where an object is a Value object. I created stubs and place at client side as a jar file. xyz.class is also there in stubs list. While calling that webservice im getti
-
Changing terms of payment on an order
Hello Everyone, There is a big issue at my company and I am hoping someone can help me out with this. There are occasions when a customer will come into one of our branches and place an order on their account that has the terms of payment set to cash
-
Ocrfile is not being written to. open file issues. Help please.
I've been troubleshooting an open file issue on our Test environment for quite a while now. Oracle has had me update to latest CRS bundle for 10.2.0.3, then upgrade to 10.2.0.4, then two more patches via OPatch to bring 10.2.0.4 RAC to it's most rece
-
Is there a Terminal command that will pick up DNS numbers?
Hello all, Is there a Terminal command that will pick up the DNS numbers utilized by a router? The router options don't show any, though the router is set to use PPPoA to pick them up. I kindly TIA, Eme '~[ )♥♪
-
Bluetooth not working in lenovo g580 windows 8 pc
I have a problem with my bluetooth in lenovo g580,windows 8. It wasn't working properly,so I tried to update the drivers....now bluetooth is not working at all... I can see the bluetooth icon and it is turned on,but I am not able to use bluetooth.Th