Difference of path between primary key and a Unique Index
Hi allIs there a specific way the oracle optimizer to treat differently the Primary key and Unique index?
Oracle Version
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
SQL>
Sample data test for Index NormalSQL> create table t_test_tab(col1 number, col2 number, col3 varchar2(12));
Table created.
SQL> create sequence seq_t_test_tab start with 1 increment by 1 ;
Sequence created.
SQL> insert into t_test_tab select seq_t_test_tab.nextval, round(dbms_random.value(1,999)) , 'B'||round(dbms_random.value(1,50))||'A' from dual connect by level < 100000;
99999 rows created.
SQL> commit;
Commit complete.
SQL> exec dbms_stats.gather_table_stats(USER_OWNER','T_TEST_TAB',cascade => true);
PL/SQL procedure successfully completed.
SQL> select col1 from t_test_tab;
99999 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 1565504962
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 99999 | 488K| 74 (3)| 00:00:01 |
| 1 | TABLE ACCESS FULL| T_TEST_TAB | 99999 | 488K| 74 (3)| 00:00:01 |
--------------------------------------------------------------------------------
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
6915 consistent gets
259 physical reads
0 redo size
1829388 bytes sent via SQL*Net to client
73850 bytes received via SQL*Net from client
6668 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
99999 rows processed
SQL> create index idx_t_test_tab on t_test_tab(col1);
Index created.
SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB',cascade => true);
PL/SQL procedure successfully completed.
SQL> select col1 from t_test_tab;
99999 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 1565504962
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 99999 | 488K| 74 (3)| 00:00:01 |
| 1 | TABLE ACCESS FULL| T_TEST_TAB | 99999 | 488K| 74 (3)| 00:00:01 |
--------------------------------------------------------------------------------
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
6915 consistent gets
0 physical reads
0 redo size
1829388 bytes sent via SQL*Net to client
73850 bytes received via SQL*Net from client
6668 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
99999 rows processed
SQL>
Examples of test when using primary key dataSQL> create table t_test_tab1(col1 number, col2 number, col3 varchar2(12));
Table created.
SQL> create sequence seq_t_test_tab1 start with 1 increment by 1 ;
Sequence created.
SQL> insert into t_test_tab1 select seq_t_test_tab1.nextval, round(dbms_random.value(1,999)) , 'B'||round(dbms_random.value(1,50))||'A' from dual connect by level < 100000;
99999 rows created.
SQL> commit;
Commit complete.
SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB1',cascade => true);
PL/SQL procedure successfully completed.
SQL> select col1 from t_test_tab1;
99999 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 1727568366
---------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 99999 | 488K| 74 (3)| 00:00:01 |
| 1 | TABLE ACCESS FULL| T_TEST_TAB1 | 99999 | 488K| 74 (3)| 00:00:01 |
---------------------------------------------------------------------------------
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
6915 consistent gets
0 physical reads
0 redo size
1829388 bytes sent via SQL*Net to client
73850 bytes received via SQL*Net from client
6668 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
99999 rows processed
SQL> alter table t_test_tab1 add constraint pk_t_test_tab1 primary key (col1);
Table altered.
SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB1',cascade => true);
PL/SQL procedure successfully completed.
SQL> select col1 from t_test_tab1;
99999 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 2995826579
---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 99999 | 488K| 59 (2)| 00:00:01 |
| 1 | INDEX FAST FULL SCAN| PK_T_TEST_TAB1 | 99999 | 488K| 59 (2)| 00:00:01 |
---------------------------------------------------------------------------------------
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
6867 consistent gets
0 physical reads
0 redo size
1829388 bytes sent via SQL*Net to client
73850 bytes received via SQL*Net from client
6668 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
99999 rows processed
SQL>
If you see here the same even as the statistics were gathered,* In the 1st table T_TEST_TAB, table always use FULL table access after creating indexes.
* And in the 2nd table T_TEST_TAB1, table uses PRIMARY KEY as expected.
Any comments?
Kind regards
BPat
>
* In the 1st table T_TEST_TAB, table always use FULL table access after creating indexes.
* And in the 2nd table T_TEST_TAB1, table uses PRIMARY KEY as expected.
>
Yes - for the first table a full table scan will be used as the currently selected column is nullable and indexes do not include null values.
The index can be used for the second query, since all the data (first column) is available between the index and there may be no NULL values because of the primary key. If you check constraints, you find that the there is now a CHECK constraint to ensure that the first column cannot be null.
For a full and interesting discussion see the explanation of this and a related issue on the question I ask in this thread
What SYS tables (not seen) contain the value NULL spec /not/ column definition? and my response he posted: 23 April 2012 09:02
I ask the question is based on a question here which is similar to yours
Columns becoming nullable after a fall of primary key?
Tags: Database
Similar Questions
-
What is the difference between primary key and unique indexes with forced not null?
Primary key is = unique index + not null?
The short answer is Yes.
However, even if the primary key, applying both uniquness and not null, there is a notion of "special".
You can only have one primary key in tables, but you can have multiple unique indexes and constraints not null.
See: https://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:8743855576462
-
Primary key and unique key not Null
Hello gurus,
Asked in an interview about the difference between primary and unique keys.
I talked Unique keys can accept null values, but they are unique through should have the table. So, the next question asked me was "a Unique key NOT NULL can be treated as the primary key?
Tricky question! :)
I said yes! that it meets the requirement to be a primary key for this particular table, but since this isn't really a primary key, that it can't be covered in the foreign keys.
The interviewer wanted just a Yes or no.
Can someone please put some of this?
Thanks in advance!Two things.
1. unique can also be referenced as a foreign key. If your statement "but because this isn't really a primary key may not be seized key foreign." is not true.
2. primary key and Unique key are different (for example you can have more than one UK in a table but PK's alone) and to know the difference, read some RDBMS concepts.I'm curious to know what is the outcome of your interview? ;)
-
manually assign primary key and copy to the detailed form
Hi experts,
Oracle Apex 4.2, 11g database, using windows 7.
I created a form and created automatic product no. (not only sequence) with logic and SQL. SQL query produced good wise exercise, and exercise begin from 01 July and ends 30 June each year. This means if the 07/01/2015 start it will create a new voucher No.
The main Table name is GL_PV and the columns are:
Number of PV_No
Date of PV_Date
Number of CC_code
number amount
Remarks varchar2 (100)
Created a process to submit before the calculations and validations.
The codes are
NVL SELECT (MAX (to_number (nvl(pv_no,0))) + 1, 1) AMENDMENTS
IN: P15_pv_no
OF GL_PV
WHERE pv_date
BETWEEN to_date (' 01-07-' |) (extract (year from to_date (: P15_pv_date, "dd-mm-yyyy")))
+ case when extracted (month of to_date (: P15_pv_date, "dd-mm-yyyy")) < = end of another 0, then 6-1), "dd-mm-yyyy")
AND to_date (30 - 06-' |) (extract (year from to_date (: P15_pv_date, "dd-mm-yyyy")))
(+ case when extracted (month of to_date (: P15_pv_date, "dd-mm-yyyy")) < = 6 then 0 otherwise 1 end), "dd-mm-yyyy")
and cc_code =: P15_cc_code;
and press the button when Conditions = Generate_Button
In the form of master I put the data and click on create button is working well and generating good can result.
Now that I've created a detail of my detail table is pv_detail and the columns are
pv_voucher_no
pv_date
account_code
Remarks
amount
I want to create the relationship of the master / detail form.
I tried:
- primary key and foreign key, but does not. column GL_PV table primary key (PV_NO, PV_DATE), PV_DETAIL (pv_voucher_no, pv_date) foreign key table columns: -.
- has created one for master and 2nd 2 form for details, good master shape generates but not detail of.
I want to assign pv_no, pv_date in both value table (master / detail), in other words copy value pv_no and pv_date of main table in detail table pv_voucher_no and pv_date.
Please advise how I can solve this problem.
Thank you forum oracle to solve my problems.
error report: ORA-01790: expression must have the same type of data, matching expression
Find the solution on this forum
Solution:
Attributes and the tabular form:
Change the default type = PL/SQL Expression on the function
Default = to_date(:P15_PV_DATE,'DD-MON-YYYY')
-
The difference in performance between wins 8 and win 7.
What performance difference is there between winning 8 and win 7, or does go through whats in win 8 which is not in win 7?
What performance difference is there between winning 8 and win 7, or does go through whats in win 8 which is not in win 7?
http://www.TechSpot.com/review/561-Windows8-vs-Windows7/
http://www.askvg.com/comparison-between-Windows-7-and-Windows-8-memory-management-system/
-
Potential problems for tables without primary keys and unique keys
GoldenGate 11.2.1.0.3/Solaris 10
DB: Oracle for Oracle (Source and target is 11.2.0.3)
Topology: unidirectional
In our one-way configuration GG, little of the tables being replicated is not a primary key or a Unique key.
Last week when we have implemented GG for the test, we received warnings for these table below.
Replication seems to work very well for these tables.GGSCI > add trandata WMHS_UD.crtn_dtl 2013-01-12 11:34:33 WARNING OGG-00869 No unique key is defined for table 'CRTN_DTL'. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key. Logging of supplemental redo data enabled for table WMHS_UD.crtn_dtl.
Googling, I think that there may be performance degradation when you replicate tables without PK or the United Kingdom.
But are there other potential problems such as data of a certain kind not replicated to the lack of PK/UK?It really depends on the data.
By default, GG is combining all columns as a virtual primary key but don't no conflict control by default. So when you can be sure that the record you insert into the table is unique, then it will work.
BUT as soon as you insert the same record, which is already inserted, then you will encounter problems.Let me show what happens when you use an initial charge because it makes it easier to describe:
We start at 10:00 the capture for a table. Now, you insert a record at 10:00 in the tables. When you now start an initial charge to 10.02, then check you have inserted in the database to 10.01 will be repeated two times. During the IPL as the initial charge is made to 10.02 and it includes data of 10.01 AND it will be replicated again through the process of capture/replicate. -
Problem with the primary key and indexes
Hi all
I'm looking a mess on one of our main tables.
One of the developers here added an index on 3 columns in the table, thinking that it would speed up (not noticing that it had not a PK).
Subsequently another developer has noticed there do not have a primary on key. So they added a touch of primry on the single column.
The problem is that now the index created on 3 columns is bein used as the primary key index. As when the primary key is created a new index was not created.
Is there anyway to get rid of this index/change it correct?
This table is related to many many other tables, so when we tried to remove the index we could not due to the primary key and foreign key violations with other tables.
Thanks in advanceOracle, as you found, is quite capable to use a column enformce multi index a single column primary key, as long as the pk column is the leader in the index. This should not cause performance issues for a search of PK and if the three indexed columns are often selected only may benefit from these types of queries.
The only way to change that now, would be to drop all CF, drop and add the PK constraint and then add all the FK constraints. A long time and potentially dangerous (if you miss to add back of the FKs) endeavour. Certainly not worth the risk in my opinion.
John
-
HelloI have a unique index associated with no doubt. Unique and not unique indexes are used B tree architecture. But I want to know if I create a non-unique index on a column that contains unique data.
When I query this table using this column, it scans each sheet or times found that value it scan stops and give us the result?
00125 wrote:
In a non-unique index, scans all the leaves... so what's the difference between full table scan and index ull. I went through a few articles they mentioned that a non-unique index to check with rowid. How she treated? I have clear knowledge in it.
Please help me with this.
Thanks in advance
If you go through architecture index B-tree you could easily understand how indexing works. The picture here shows how a look of column datatype NUMBER indexed as / stored internally. You can imagine that your indexed column TST_COLA this will look like in the internal process. In the B-tree indexes, you have 3 main structures 1. 2 root. Branch 3. Leaves and the database retrieves lines by browsing through the root of index-> branch-> leaves. If the photo if we wanted to retrieve the row whose value indexed column = 25. First data goes to the root and finds that plugs is set to 25, then he Stoops to this particular branch of find what block sheet retains the value 25. More far away after finding the leaves block then goes to this block of sheets and research the special value of 25.
If the index is UNIQUE, the database knows that there must be only one value, where it performs INDEX UNIQUE SCAN. If the index is NOT UNIQUE it should check all values in this block of leaves to find who all are 25 - in this case INDEX RANGE SCAN is done - as you must check not only value, but all values in this block of sheets - given that the values are not unique. As you can see it that the sheet block contains the long side of the value of the column ROWID, using this database rowid, then goes to the table to retrieve that particular line.
Full table scan is a method of access where the database just to access the table directly (bypassing index structure) and analyze the ENTIRE table to satisfy the request.
-
Primary key and foreign key between the different schemas
Hi all;
SCOTT user have a 'rank' of table-> it contains the primary key-> users tablespace
The U1 user have a 'emp' table-> it contains the foreign key-> test tablespace
U1 > select constraint_name, constraint_type, r_owner, owner, r_constraint_name of all_constraints where table_name = 'EMP ';
OWNER CONSTRAINT_NAME C R_OWNER R_CONSTRAINT_NAME
------------ ------------------------------ - -------------------------- ----------------------- -----------------------------------------------------
U1 EMP_EMPLEV_C12_FK R SCOTT GRADE_GRL_C1_PK
If I have connection U1, no possibility to find the name of the primary key without connection scott table?
Thank you
Hello
So, you want to know what picture of the SCOTT schema has the constraint that is named "GRADE_GRL_C1_PK." Isn't it?
If so,.
SELECT table_name
Of all_constraints
Owner WHERE = 'SCOTT '.
AND the argument constraint_name = 'GRADE_GRL_C1_PK. '
;
-
View of Materlized primary key and primary key in the master tables
We use the Oracle 11 g 2 and I created a view on several paintings of master materlized. The paintings of masters all have the primary key, but I understand not all primary key columns in the query definition.
According to Oracle manual e10592
My MV created OK and works. My question is what can be the impact on my MV? Could he hit to performance. It takes 40 minutes to the MV should be created and 5 minutes to refresh the one line insert in each table of mater. I would like to see it refresh in a few seconds.Specify WITH PRIMARY KEY to create a primary key materialized view. This is the default .... The master table must contain an enabled primary key constraint, and the defining query of the materialized view must specify all of the primary key columns directly.
Retrieve the lines of the mview is purely a function of the number of lines and indexing on the mview himself. Mview refreshing at the time of the wall depends on the quality of the query used to refresh the mview. If you include the PKs of the source table in the mview matter or not, here. What matters is the execution of the refresh request path. Is it okay to indexation on the underlying tables to support the joints. Did you use mlog$ _s to allow a quick refresh - mlog$ _s are still usable for your mview. There are a number of possible causes for your problem and we do not have enough information to make an estimate of the problem.
BTW, if the mview could refresh in a few seconds without mlog$ _s, probably unnecessary a mview.
-
Updating related Records primary key and FK dependencies
(1) how can I found the name of all the tables that use my primary key as a foreign key? The primary key is of type varchar and used in many other paintings. Now PK records must be changed by the customer's request, so it will affect obviously all of my dependent tables.
(2) which corresponds to the PL/SQL script more efficient to perform this procedure?
All suggestions will be useful.
To test, I think I want a list of all tables in followed by a list of all affected records. This report must show registration PK & all records in dependence requiring an update. Is this reasonable?user10998542 wrote:
(1) how can I found the name of all the tables that use my primary key as a foreign key? The primary key is a varchar and used in many other paintings. Now PK records must be changed by the customer's request, so it will affect obviously all of my dependent tables.Discover the view USER_CONSTRAINTS. You could do something like this:
SELECT UC.OWNER , UC.TABLE_NAME , UC.R_OWNER , RUC.TABLE_NAME , UC.R_CONSTRAINT_NAME , RUC.CONSTRAINT_TYPE FROM USER_CONSTRAINTS UC , USER_CONSTRAINTS RUC WHERE UC.R_OWNER = RUC.OWNER AND UC.R_CONSTRAINT_NAME = RUC.CONSTRAINT_NAME AND UC.CONSTRAINT_TYPE = 'R'
If you need names of columns, you can use the USER_CONS_COLUMNS view also.
(2) which corresponds to the PL/SQL script more efficient to perform this procedure?
All suggestions will be useful.[Tom Kyte: package Cascade | http://tkyte.blogspot.com/2009/10/httpasktomoraclecomtkyteupdatecascade.html]
-
most unique separator between the key and the value.
Hello
I need to write some implementation of a key delimiter value, while demand will insert this value and the delimiter that is not defined in the db.
After that, I need to retrieve the key and the value, the question that this delimiter is defined by a custom code and it might be something.
My problem starts when the delimiter that defined by custom code will be part of the 'key' or\and 'value '. in this case, the index of the key and value of the analysis or split or any regex-based will give the wrong key and value.
Please advice, what is your suggestion for m searching the Internet to find any piece of information that can help.
Thanks in advance.
These examples are not relevant if your use case is not the same thing as what this code is from.
1. you now have the rules.
2. you have Java class files that implement these rules for a defined set of data types and work delimiters
3. you have the Java source code for these class files so you can see exactly how the rules are applied and how specific types of data, and the delimiters affect the process.
It is up to YOU to determine if the existing code will do what you need and, if not, to change this code (or write your own) that implements the rules for your use case.
You have all the information you need to do the work. Nobody on the forum, and certainly not me, is going to write your code for you. If you can't do the job when you have ALL the necessary information then you will need to hire a consultant to do.
Any other help is possible.
-
Hi all
I'm confused. If I create a primary key of table constraints, it willl create a unique index by default. If I create a foreign key, it also creates an index? of any kind?
Thank you very much
KinzLaughing out loud. foreign key does not have a unique index on the table.
-
Difference: Ombudsman created from a WSDL and a unique sense of mediator
Hello
What is the difference between the Ombudsman created from a WSDL and a unique sense of mediator. The two have only one way of message exchange pattern.
Kind regards
VINETWhat is the difference between the Ombudsman created from a WSDL and a unique sense of mediator. The two have only one way of message exchange pattern.
When the Ombudsman created from the WSDL.
(1) if the WSDL operation is defined as a medium, then the Ombudsman will be a way.
(2) if the WSDL operation is defined as asynchronous, then the Ombudsman will be asynchronous.
(3) if the WSDL operation is defined as synchronous, the Ombudsman will be synchronous. -
Differences in hardware between Portege M700 and M750
I have about 40 Porteges a mix between M700 and M750, I need to know the differences of hardware and driver between the two for the purpose of Ghosting.
I think the only difference is that the M700 uses the chipset Intel Santa Rosa (9xx series), and the M750 uses the newer Montevina (4 x series) chipset.
If you need to install a utility/driver Intel Chipset that supports both chipsets.
Maybe you are looking for
-
How to get off the Vista of Portege M200?
Hello I inherited Portege M200 from my boss, and he has updated using an external DVD from XP Pro to Vista Ultimate. Slow as a slow thing, very few pilots etc, meant that I am determined to go back to XP Pro.I (128, 1 Gig and 2 gig options) SD cards
-
Just made my first film on iMovie 11 to show the new apple TV. Worked well started a new project two days ago, but now when I try to open iMovie it starts with 'validation library iMovie on computer' and then seems to load the last project I worked
-
Games for Windows Live (GFWL) log: error 80131509
Problem: Unable to connect to GFWL Symptom: Immediate sign in error displaying the error code; «To connect error» Unable to connect. Please try again later. Code: 80131509 " At a couple of old OS (Windows 7 Pro x 64), with all updates. What I tried:
-
Not able to use the built-in webcam
I have a HP Pavilion dv6t - 6 c 00. I've upgraded to windows 7 ultimate which I had windows 7 Home premium that I could use the webcam, but now it displays an error when I open cyberlink youcam "warning, no webcam detected. Try connecting a webcam on
-
Download vista SP2 didn't do my dep settings are wrong.