Creating Primary Key Index
Hi,
Iam trying to create a Primary Index on Large table and Iam using the Parallelism to make it fast. I have used the following script to create a Primary key Index.
CREATE UNIQUE INDEX FLX_ARCH.FUND_SEC_RESULT_STAT_ARCH_PK
ON FLX_ARCH.FUND_SEC_RESULT_STAT_ARCH
(FUND_SEC_RESULT_MAP_INST,RATES_RULE_ID,BASE_LOCAL_FLAG,EFFECTIVE_DATE)
TABLESPACE FLX_PERF_I
parallel;
Index created.
Elapsed: 01:43:37.37
Index got created in 1 hour 43 minutes. But when Iam adding constarint to those columns, it is taking almost 12hours with or without parallelism.
ALTER TABLE FLX_ARCH.FUND_SEC_RESULT_STAT_ARCH
ADD CONSTRAINT FUND_SEC_RESULT_STAT_ARCH_PK
PRIMARY KEY
(FUND_SEC_RESULT_MAP_INST,RATES_RULE_ID,BASE_LOCAL_FLAG,EFFECTIVE_DATE)
parallel
Would you please let me know what could be the problem and how can we add the Primary constraint fast.
Your early response is much appreciated.
Thanks and Regards
Suresh. D
Would you please let me know what could be the problem and You have presented no details that indicate any problem exists.
how can we add the Primary constraint fast. Fast is relative.
If I asked you to make my snail fast, could you do so?
ALTER SESSION SET SQL_TRACE=TRUE;
ALTER TABLE FLX_ARCH.FUND_SEC_RESULT_STAT_ARCH
ADD CONSTRAINT FUND_SEC_RESULT_STAT_ARCH_PK
PRIMARY KEY
(FUND_SEC_RESULT_MAP_INST,RATES_RULE_ID,BASE_LOCAL_FLAG,EFFECTIVE_DATE)
parallel
ALTER SESSION SET SQL_TRACE=FALSE;
now find the trace file within ./udump folder
tkprof <trace_file.trc> trace_results.txt explain=<username>/<password>
By inspecting the trace file you will be able to see where time is being spent.
With this knowledge, you may or may not be able to determine the bottleneck & therefore improve it
Similar Messages
-
Creating Primary key Index as Local Partitioned Index.
CREATE TABLE T1(
x NUMBER,
y NUMBER
)PARTITION BY LIST(x)
PARTITION P1 VALUES (1),
PARTITION P2 VALUES (2),
PARTITION Pmax VALUES (default)
ALTER TABLE T1 ADD CONSTRAINT T1_PK PRIMARY KEY(Y) LOCAL;
Error starting at line 1 in command:
ALTER TABLE T1 ADD CONSTRAINT T1_PK PRIMARY KEY(Y) LOCAL
Error report:
SQL Error: ORA-01735: invalid ALTER TABLE option
01735. 00000 - "invalid ALTER TABLE option"
*Cause:
*Action:
Can you please help me how to achieve this in Oracle 10g R2?LOCAL keyword is invalid with ALTER TABLEDepends:
SQL> create table t1 (x number, y number)
partition by list (x)
(partition p1
values (1),
partition p2
values (2),
partition pmax
values (default))
Table created.
SQL> alter table t1 add constraint t1_pk primary key(x, y) using index local
Table altered. -
How to Create primary key index with duplicate rows.
Hi All,
While rebuilding an index on a table , I am getting error that there are duplicate rows in a table.
Searching out the reason led me to an interesting observation.
Please follow.
SELECT * FROM user_ind_columns WHERE table_name='SERVICE_STATUS';
INDEX_NAME TABLE_NAME COLUMN_NAME COLUMN_POSITION COLUMN_LENGTH CHAR_LENGTH DESCEND
SERVICE_STATUS_PK SERVICE_STATUS SUBSCR_NO_RESETS 2 22 0 ASC
SERVICE_STATUS_PK SERVICE_STATUS STATUS_TYPE_ID 3 22 0 ASC
SERVICE_STATUS_PK SERVICE_STATUS ACTIVE_DT 4 7 0 ASC
SERVICE_STATUS_PK SERVICE_STATUS SUBSCR_NO 1 22 0 ASC
SELECT index_name,index_type,table_name,table_type,uniqueness, status,partitioned FROM user_indexes WHERE index_name='SERVICE_STATUS_PK';
INDEX_NAME INDEX_TYPE TABLE_NAME TABLE_TYPE UNIQUENESS STATUS PARTITIONED
SERVICE_STATUS_PK NORMAL SERVICE_STATUS TABLE UNIQUE VALID NO
SELECT constraint_name ,constraint_type,table_name,status,DEFERRABLE,DEFERRED,validated,index_name
FROM user_constraints WHERE constraint_name='SERVICE_STATUS_PK';
CONSTRAINT_NAME CONSTRAINT_TYPE TABLE_NAME STATUS DEFERRABLE DEFERRED VALIDATED INDEX_NAME
SERVICE_STATUS_PK P SERVICE_STATUS ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED SERVICE_STATUS_PK
1. Using index scan:
SELECT COUNT (*)
FROM (SELECT subscr_no, active_dt, status_type_id, subscr_no_resets
FROM service_status
GROUP BY subscr_no, active_dt, status_type_id, subscr_no_resets
HAVING COUNT (*) > 1) ;
no rows returned
Explain plan:
Operation OBJECT Name ROWS Bytes Cost OBJECT Node IN/OUT PStart PStop
SELECT STATEMENT Optimizer MODE=CHOOSE 519 K 14756
FILTER
SORT GROUP BY NOSORT 519 K 7 M 14756
INDEX FULL SCAN ARBOR.SERVICE_STATUS_PK 10 M 158 M 49184
2. Using Full scan:
SELECT COUNT (*)
FROM (SELECT /*+ full(s) */ subscr_no, active_dt, status_type_id, subscr_no_resets
FROM service_status s
GROUP BY subscr_no, active_dt, status_type_id, subscr_no_resets
HAVING COUNT (*) > 1) ;
71054 rows returned.
Explain Plan:
Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
SELECT STATEMENT Optimizer Mode=CHOOSE 1 24123
SORT AGGREGATE 1
VIEW 519 K 24123
FILTER
SORT GROUP BY 519 K 7 M 24123
TABLE ACCESS FULL ARBOR.SERVICE_STATUS 10 M 158 M 4234
Index SERVICE_STATUS_PK is a unique and composite primary key VALID index. And the constraint is ENABLED and VALIDATED still having duplicate rows in table.
How it is possible?
Is it an Oracle soft Bug??
Regards,
Saket Bansalsaket bansal wrote:
Values are inserted as single rows inserts through an GUI interface.And you still claim to have over 71K duplicate records, without the GUI getting any kind of errors?
That does not add up and can only be explained by a "bug".
I tried inserting a duplicate record but failed.
SQL> insert into service_status (select * from service_status where rownum <2);
insert into service_status (select * from service_status where rownum <2)
ERROR at line 1:
ORA-00001: unique constraint (ARBOR.SERVICE_STATUS_PK) violatedAre you really sure there is no other way data in this table is populated/manipulated in bulk? -
Creating an unique index instaed of using primary key index
Hi ,
I heard in a debate sometimes it's better to create a unique index on a column and using it instaed of using primary key index in oracle.I couldn't understand what the reason propely.
Can anyone please help me in thsi topic if it is a valid one .
Thanks in advanceHi,
They are exactly NOT identical.
1. Unique key can have NULL values where primary keys can't.
2. Primary key is fundamentally those keys which do not change. I mean updating a primary key is not a good idea.
SQL> drop table test;
Table dropped.
SQL> create table test ( a number(2));
Table created.
SQL> ed
Wrote file afiedt.buf
1* create unique index test_idx on test(a)
SQL> /
Index created.
SQL> ed
Wrote file afiedt.buf
1* insert into test values(NULL)
SQL> /
1 row created.
SQL> drop table test;
Table dropped.
SQL>
SQL> create table test ( a number(2) primary key);
Table created.
SQL> insert into test values(NULL);
insert into test values(NULL)
ERROR at line 1:
ORA-01400: cannot insert NULL into ("HR"."TEST"."A")
SQL>Cheers,
Edited by: Avinash Tripathi on Nov 24, 2009 11:17 AM -
Concept about Primary Key index
I have a partitioned table as follow:
CREATE TABLE TEST
(TEST_KEY NUMBER(10,0) NOT NULL
,FOREIGN_KEY NUMBER(10,0) NOT NULL
,PARAM_ID NUMBER(10,0)
,PARAM_VALUE VARCHAR2(256)
PARTITION BY HASH (operation_key) PARTITIONS 15
STORE IN (TEST_R1_TS, TEST_R2_TS, TEST_R3_TS, TEST_R4_TS, TEST_R5_TS)
CACHE
I also created a partitioned index for the TEST_KEY to be used as primary key index.
CREATE INDEX TEST_PK_IDX ON PARAMETER_1(TEST_KEY) LOCAL
STORE IN (TEST_i1_ts, TEST_i2_ts, TEST_i3_ts, TEST_i4_ts, TEST_i5_ts);
When I try to run alter table to add primary key, I got index not exist error?
SQL> alter table TEST add (constraint test_pk primary key (test_key) using index test_pk_idx);
alter table parameter_1 add (constraint pa1_pk primary key (parameter_key) using index pa_pk_idx)
ERROR at line 1:
ORA-01418: specified index does not exist
BUT, I could find my index in the USER_INDEXES table...
SQL> select index_name from user_indexes where index_name like '%TEST_PK%';
INDEX_NAME
TEST_PK_IDX
Why? Help is very appreciated.
Thank you in advanced.check the names of the tables in the script you give ... they are different for the table and the index. When you add the constraint the table name and column name mysteriously change in the error message, so I think that you aren't showing us what actually happened.
-
Primary key index not working in a select statment
Hi ,
I'm doing a :
select *
from my_table
where B = v1 and
A = v2 ;
where A and B are the primary key of the table, in that table the primary key index is there and the order of the primary key definition is A first and then B.
While testing this statment in my database the Explain Plan shows that it is using the index ok but when
runninng in client database it is not using it becasue of the order (i think), is this something configurable that I need to ask to my DBA ?
The solution I found was to do the select with a hint wich fix the problem , but I'm curious about why is working in my dadabase and not in the client database
thanks in advance .
oracle version 11gThis is the forum for SQL Developer (Not for general SQL/PLSQL questions). Your question would be better asked in the SQL and PL/SQL forum.
Short answer: The execution plan used will depend on optimizer settings and table/index statistics. For example if the table has very few rows it may not bother using the index. -
What is the best practice for creating primary key on fact table?
what is the best practice for primary key on fact table?
1. Using composite key
2. Create a surrogate key
3. No primary key
In document, i can only find "From a modeling standpoint, the primary key of the fact table is usually a composite key that is made up of all of its foreign keys."
http://download.oracle.com/docs/cd/E11882_01/server.112/e16579/logical.htm#i1006423
I also found a relevant thread states that primary key on fact table is necessary.
Primary Key on Fact Table.
But, if no business requires the uniqueness of the records and there is no materilized view, do we still need primary key? is there any other bad affect if there is no primary key on fact table? and any benifits from not creating primary key?Well, natural combination of dimensions connected to the fact would be a natural primary key and it would be composite.
Having an artificial PK might simplify things a bit.
Having no PK leads to a major mess. Fact should represent a business transaction, or some general event. If you're loading data you want to be able to identify the records that are processed. Also without PK if you forget to make an unique key the access to this fact table will be slow. Plus, having no PK will mean that if you want to used different tools, like Data Modeller in Jbuilder or OWB insert / update functionality it won't function, since there's no PK. Defining a PK for every table is a good practice. Not defining PK is asking for a load of problems, from performance to functionality and data quality.
Edited by: Cortanamo on 16.12.2010 07:12 -
How to see wether the index is a primary key index or not
hi,
can anybody let me know how to get wether the index is made on the primary key (i.e primary key index)
can we do by querying the user_constriants table.
plz let me know..Maran.Viswarayar wrote:
Vijay,
Was that different from Anurag's reply?Yes it was. Anurag didn't include the index_name in his query.
It is possible for the index name to be different from the constraint_name, so if you listed just the primary key constraint names you might decide that a given index was not a "primary key" index because you couldn't find a constraint with the matching name.
Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk
To post code, statspack/AWR report, execution plans or trace files, start and end the section with the tag {noformat}{noformat} (lowercase, curly brackets, no spaces) so that the text appears in fixed format.
"Science is more than a body of knowledge; it is a way of thinking"
Carl Sagan -
Problem with capturing Primary Key Index
Hi
I am capturing certain tables and in the mean process i observed that all the indexes are getting captured except the primary key index.
Any Suggestions on this?
Thanx,
SujiHi,
I was unable to reproduce this behavior on OWM 10.1.0.8. It appears that you have a SR open for this issue, so I would suggest to continue with that process.
Regards,
Ben -
Drop/recreate primary key index
Any suggestions for dropping/recreating a primary key index? The index has to be dropped/recreated and not rebuilt due to ORA-600s.
Do I simply disable/re-enable the primary key constraint? The database is 10g.
Edited by: nickw2 on Apr 1, 2009 5:06 PMORA-600 errors are a handful, I usually check metalink or ask ORacle support for help.
Anyways, If you want to recreate the primary key index, have you tried dropping the primary key constraint and adding it back?
ALTER TABLE tablename
DROP CONSTRAINT pk_name;
ALTER TABLE tablenames
ADD CONSTRAINT pk_name PRIMARY KEY (column_name); -
Do I need to Create Primary Key Class for Entity beans with Local interface
Do I need to Create Primary Key Class for Entity beans with Local interface?
I have created my entity bean with the wizard in Sun One Studio and it does not create a primary key class for you.
I thought that the primary key class was required. My key is made up of only one field.
Anyone know the answer.
Jimu dont need to create a primary key class for a entity bean.if ur table's primary key feild(int ,float) is a built in or primitive data type,then u dont need one.But if ur table has a primary key field which is non primitive (for example StudentID,ItemID etc)then u have to create a primary key class.
hope this helps :-) -
The primary key index to be created in a different tablespace.
Hi,
I have a user PROD. It has been assigned a default tablespace PROD_TBS.
There is a seperate table space for all the indexes in the schema , PROD_IDX.
I wish to create a table TEST as follows,
CREATE TABLE TEST
(TEST_ID NUMBER(1),
NAME VARCHAR2 (10) );
There should be a primary key on column test_id but such that the corresponding unique index created by default because of the primary key should be created in tablespace PROD_IDX.
How to do this ?Alternative solution:
CREATE TABLE TEST
(TEST_ID NUMBER(1),
NAME VARCHAR2 (10),
constraint test_pk primary key (test_id)
using index tablespace prod_idx
);Cheers, APC
blog: http://radiofreetooting.blogspot.com -
Problems creating a partitioned primary key index.
I am creating a partitioned table and I noticed that when I use the constraint option of the create table the primary key is not partitioned. I then tried using the using index clause and specifying the create index local and that is giving errors. Here is my current syntax that is causing the errors:
create table redef_temp (
USER_ID VARCHAR2(32),
GROUP_ID VARCHAR2(32),
JOIN_DATE DATE DEFAULT SYSDATE NOT NULL,
constraint primary key
using index (create index pk_redef_temp
on redef_temp (USER_ID, GROUP_ID)
LOCAL STORE IN (IDX)))
tablespace data
partition by hash (user_id)
(PARTITION ic_x_user_group_part_p1 tablespace DATA,
PARTITION ic_x_user_group_part_p2 tablespace DATA,
PARTITION ic_x_user_group_part_p3 tablespace DATA,
PARTITION ic_x_user_group_part_p4 tablespace DATA)
PARALLEL ENABLE ROW MOVEMENT;
ThanksThe following works on 9.2.0.8 and 10.2.0.3:
create table redef_temp (
USER_ID VARCHAR2(32),
GROUP_ID VARCHAR2(32),
JOIN_DATE DATE DEFAULT SYSDATE NOT NULL,
constraint pk_redef_temp primary key (user_id, group_id)
using index (
create index pk_redef_temp
on redef_temp (USER_ID, GROUP_ID)
LOCAL tablespace test_8k
tablespace test_8k
partition by hash (user_id) (
PARTITION ic_x_user_group_part_p1 tablespace test_8k,
PARTITION ic_x_user_group_part_p2 tablespace test_8k,
PARTITION ic_x_user_group_part_p3 tablespace test_8k,
PARTITION ic_x_user_group_part_p4 tablespace test_8k
PARALLEL ENABLE ROW MOVEMENT
/Your syntax for the constraint definition was wrong, and your use of 'store in' for the index tablespace was wrong. I've had to change all tablespace names to 'test_8k'.
Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk -
Oh.. Primary key index is missing!
Database: 10.2.0.4.0
Platform : Linux
SQL> SELECT CONSTRAINT_NAME,CONSTRAINT_TYPE,INDEX_NAME FROM DBA_CONSTRAINTS WHER
E TABLE_NAME='ISSUE_COMMENTS';
CONSTRAINT_NAME C STATUS VALIDATED
SYS_C0031516 C ENABLED VALIDATED
SYS_C0031517 C ENABLED VALIDATED
SYS_C0031519 P ENABLED VALIDATED
SQL> SELECT INDEX_NAME,TABLE_NAME FROM DBA_INDEXES WHERE TABLE_NAME='ISSUE_COMMENTS';
INDEX_NAME TABLE_NAME
INDEX_ISSUE_COMMENTS ISSUE_COMMENTS
SQL> select distinct index_name,column_name,table_name from dba_ind_columns wher
e table_name in ('ISSUE_COMMENTS');
INDEX_NAME COLUMN_NAME TABLE_NAME
INDEX_ISSUE_COMMENTS IDX ISSUE_COMMENTS
INDEX_ISSUE_COMMENTS ISSUE_ID ISSUE_COMMENTS
INDEX_ISSUE_COMMENTS PARENT_ID ISSUE_COMMENTS
Where is the index for the primary key 'SYS_C0031519'?
SQL>
After droping and recreating the primary key also,just primary constrainy is created but there is no corresponding index.
SQL> ALTER TABLE ISSUE_COMMENTS DROP CONSTRAINT SYS_C0031519;
Table altered.
SQL> ALTER TABLE ISSUE_COMMENTS ADD PRIMARY KEY (IDX)
2 USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
3 STORAGE(INITIAL 32768 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
4 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
5 TABLESPACE "TABLE_DATA" ENABLE;
Table altered.
SQL> SELECT CONSTRAINT_NAME,CONSTRAINT_TYPE,status,validated FROM DBA_CONSTRAINT
S WHERE TABLE_NAME='ISSUE_COMMENTS';
CONSTRAINT_NAME C STATUS VALIDATED
SYS_C0031516 C ENABLED VALIDATED
SYS_C0031517 C ENABLED VALIDATED
SYS_C0034310 P ENABLED VALIDATED
SQL> SELECT INDEX_NAME,TABLE_NAME FROM DBA_INDEXES WHERE TABLE_NAME='ISSUE_COMMENTS';
INDEX_NAME TABLE_NAME
INDEX_ISSUE_COMMENTS ISSUE_COMMENTS
SQL> select distinct index_name,column_name,table_name from dba_ind_columns wher
e table_name in ('ISSUE_COMMENTS');
INDEX_NAME COLUMN_NAME TABLE_NAME
INDEX_ISSUE_COMMENTS IDX ISSUE_COMMENTS
INDEX_ISSUE_COMMENTS ISSUE_ID ISSUE_COMMENTS
INDEX_ISSUE_COMMENTS PARENT_ID ISSUE_COMMENTS
Here also, the primary key constraint SYS_C0034310 is available but there is no index for that primary key.
Where the primary index has gone?MohanaKrishnan wrote:
Database: 10.2.0.4.0
Platform : Linux
SQL> SELECT CONSTRAINT_NAME,CONSTRAINT_TYPE,INDEX_NAME FROM DBA_CONSTRAINTS WHER
E TABLE_NAME='ISSUE_COMMENTS';
CONSTRAINT_NAME C STATUS VALIDATED
SYS_C0031516 C ENABLED VALIDATED
SYS_C0031517 C ENABLED VALIDATED
SYS_C0031519 P ENABLED VALIDATED
Your first query is not consistent with the first set of results you have displayed.
Your later query for index columns is also not very helpful as it won't list the column names in the right order.
The probably answer to your question is that the index you have is non-unique and starts with the column you've used for the primary key, which means Oracle can use it to support the primary key constraint. Here's a quick cut-n-paste from a SQL*Plus session to demonstrate the point:
SQL> create table t1 (n1 number, v1 varchar2(10));
Table created.
SQL> create index t1_n1 on t1(n1);
Index created.
SQL> alter table t1 add primary key(n1);
Table altered.
SQL> select index_name from user_indexes where table_name = 'T1';
INDEX_NAME
T1_N1
1 row selected.
SQL> select constraint_name, constraint_type, index_name from user_constraints
2 where table_name = 'T1';
CONSTRAINT_NAME C INDEX_NAME
SYS_C0033465 P T1_N1
1 row selected.
SQL> spool offNote how I've added a primary key with no name, and Oracle has decided to use the t1_n1 index to support it.
Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk
"Science is more than a body of knowledge; it is a way of thinking" Carl Sagan
Edited by: Jonathan Lewis on Dec 31, 2008 2:16 PM
Apologies to Satish - I didn't see either prior post -
SQL Data Modeler 3.0 EA1 trying to create primary key on OT
Hi,
I'm trying to modify a primary key of an object table that was reversed (imported) from an Oracle 11.2.x RDBMS and am getting the error message "Incomplete Index definition". It is showing in the window "Index Columns Assignment". I get to the 'Primary Key Properties' window by pressing the 'Properties' button on the 'Table Properties' -> 'Primary Key'. If I try to edit the expression and then press the Ok or Apply buttons I get the error. With this be fixed in the production version? Will we be able to create a model in SQL Developer Data Modeler that generates a SQL statement similar to the following:
ALTER TABLE x_flags
ADD (CONSTRAINT x_flags_pk PRIMARY KEY (flags.id))
Thanks,
Scott KHi Scott,
I'm trying to modify a primary key of an object table that was reversed (imported) from an Oracle 11.2.x RDBMS and am getting the error message "Incomplete Index definition"... With this be fixed in the production version?yes
Will we be able to create a model in SQL Developer Data Modeler that generates a SQL statement similar to the following:
ALTER TABLE x_flags
ADD (CONSTRAINT x_flags_pk PRIMARY KEY (flags.id))I assume "flags" is column of object type and "id" is attribute of that type. I logged bug for that, so there will be support however not for 3.0.
Philip
Maybe you are looking for
-
How to insert a picture into excel file using ALE AUTOMATION
Hi every body, I have to write report that export data from abap to exel the data contain a logo but I don't know how to insert picture to excel using ALE AUTOMATION. Please help me! Thank you!
-
I lost my Contacts icon, how do I get it back?
While I was dragging the Contacts icon out of the folder that it initially comes in, it exapanded really quickly and I accidentally dropped it over the Phone icon. When I search for it, it still shows up and I still have all my contacts, but I can't
-
Fotomagico boards are rare and very few topics on FCP integration so I thought I'd try here. Here's the problem. I've made a slideshow of 18 slides. When I import into FCP and drop in the timeline I first off have to drag the clip on both ends to res
-
How can I print my purchase history or get an invoice emailed again I deleted by mistake
How can I get an invoice emailed again or print it via purchase history
-
Time Constraint Type T for IT0380
Currently we have the Time Constraint on IT0380 set to 3, but that results in Infotypes getting created as shown below with the second Infotype with the same BEGDA but a different subtype and different ENDDA getting SEQNR = 1. Because of this if so