Home » SQL & PL/SQL » SQL & PL/SQL » The use of SYS_GUID() for Primary Key (11.2.0.1.0)
The use of SYS_GUID() for Primary Key [message #554600] Tue, 15 May 2012 23:14 Go to next message
OraFerro
Messages: 139
Registered: July 2011
Senior Member
Hi All,


I need a design advice.

Currently we implement Primary Key for our tables using the conventional way which is an integer Primary Key filled using a sequence and a trigger. Recently as we have a suggestion from a designer (MS SQL background) to replace all the primary keys with SYS_GUID(). Out Database is small/medium, space is not an issue but performance is extremely important. The designer who advised us says that using SYS_GUID() for Primary Key will have no impact on the performance, easier to implement and maintain, and is more secure.

Can you please give me your opinion as I read some articles that debate both points of view?
Thanks,
Re: The use of SYS_GUID() for Primary Key [message #554601 is a reply to message #554600] Tue, 15 May 2012 23:21 Go to previous messageGo to next message
BlackSwan
Messages: 20109
Registered: January 2009
Senior Member
Consider doing your own actual benchmark comparisons on your hardware with your software.
Re: The use of SYS_GUID() for Primary Key [message #554602 is a reply to message #554600] Tue, 15 May 2012 23:21 Go to previous messageGo to next message
Michel Cadot
Messages: 54236
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
More secure than what?
More secure against which threat?

Regards
Michel

[Updated on: Tue, 15 May 2012 23:29]

Report message to a moderator

Re: The use of SYS_GUID() for Primary Key [message #554605 is a reply to message #554602] Tue, 15 May 2012 23:27 Go to previous messageGo to next message
OraFerro
Messages: 139
Registered: July 2011
Senior Member
Thanks for your replies

More secure than using the conventional primary key approach when it comes to passing the key as a parameter in an application.

Generally, we have another opinion that say that using SYS_GUID() has only one advantage which is easier implementation as it doesnt need a sequence/trigger creation and maintenance.

What do you think?
Re: The use of SYS_GUID() for Primary Key [message #554607 is a reply to message #554601] Tue, 15 May 2012 23:28 Go to previous messageGo to next message
OraFerro
Messages: 139
Registered: July 2011
Senior Member
Hi BlackSwan,

We are in the design phase and we haven't implemented the Software yet.

Thanks,
Re: The use of SYS_GUID() for Primary Key [message #554608 is a reply to message #554605] Tue, 15 May 2012 23:30 Go to previous messageGo to next message
Michel Cadot
Messages: 54236
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
There is no difference regarding trigger between sequence and sys_guid.

Once again I ask "More secure against which threat?"

Regards
Michel
Re: The use of SYS_GUID() for Primary Key [message #554609 is a reply to message #554607] Tue, 15 May 2012 23:34 Go to previous messageGo to next message
BlackSwan
Messages: 20109
Registered: January 2009
Senior Member
>We are in the design phase and we haven't implemented the Software yet.

You have two choices.
Trust your design to anonymous sources who have nothing to lose should they be not correct.
You can actually test alternatives so you can have some confidence in the recommendations your reputation depends.
Re: The use of SYS_GUID() for Primary Key [message #554611 is a reply to message #554609] Tue, 15 May 2012 23:39 Go to previous messageGo to next message
OraFerro
Messages: 139
Registered: July 2011
Senior Member
Hi BlackSwan,

Or I can ask an expert who can help with a supporting or counter opinion Smile

Thanks,
Re: The use of SYS_GUID() for Primary Key [message #554612 is a reply to message #554608] Tue, 15 May 2012 23:44 Go to previous messageGo to next message
OraFerro
Messages: 139
Registered: July 2011
Senior Member
Hi Michel,

Quote:

There is no difference regarding trigger between sequence and sys_guid.


We can generate unique Ids using sys_guid() without the need to create a trigger and assign its instead action.

Quote:

Once again I ask "More secure against which threat?"

The threat of application security breach by using network package tracing. The claim of the adviser is that GUID and UUID are created to reduce this risk versus passing conventional integer key in application.

Thanks,
Re: The use of SYS_GUID() for Primary Key [message #554625 is a reply to message #554612] Wed, 16 May 2012 01:06 Go to previous messageGo to next message
Michel Cadot
Messages: 54236
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
We can generate unique Ids using sys_guid()


You can get the next sequence number using myseq.nextval -> no difference.

Quote:
The threat of application security breach by using network package tracing.


If your threat is that someone gets the key from the network than there is no difference between getting 101 or getting 57431FCA05EE4304A5C842DE69389817.
In addition, it seems you want to generate the guid key from the client and so pass it through the network to Oracle when you use a trigger to generate the sequence number which so does not go through the network. Which one is the more secure against this threat?

If your concern is packet sniffing then encrypt the network communioation.

Regards
Michel
Re: The use of SYS_GUID() for Primary Key [message #554638 is a reply to message #554600] Wed, 16 May 2012 01:32 Go to previous messageGo to next message
John Watson
Messages: 3113
Registered: January 2010
Location: Global Village
Senior Member
With regard to performance, there may be advantages to sys_guid compared to a sequence. First, the values will not be sequential. This can be important, depending on your strategy for partitioning and indexing. Second, concurrent increments to a sequence can cause latch contention, particularly in a RAC. Both these issues are avoidable, but perhaps sys_guid means that you won't have to think about them.
Ask your designer why he has made the recommendation, then maybe we can evaluate the advice.
Re: The use of SYS_GUID() for Primary Key [message #554665 is a reply to message #554638] Wed, 16 May 2012 05:37 Go to previous messageGo to next message
Solomon Yakobson
Messages: 1404
Registered: January 2010
Senior Member
John Watson wrote on Wed, 16 May 2012 02:32
With regard to performance, there may be advantages to sys_guid compared to a sequence.


And disadvantages, if sequence is created with cache (which is default):

SQL> select  *
  2    from  v$version
  3  /

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
PL/SQL Release 10.2.0.4.0 - Production
CORE    10.2.0.4.0      Production
TNS for 32-bit Windows: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production

Elapsed: 00:00:01.29

SQL> create table tbl(n number);

Table created.

Elapsed: 00:00:00.29
SQL> create sequence s;

Sequence created.

SQL> insert
  2    into tbl
  3    select  s.nextval
  4      from  dual
  5      connect by level <= 1000000
  6  /

1000000 rows created.

Elapsed: 00:00:19.71

SQL> create table tbl_guid(n raw(16))
  2  /

Table created.

Elapsed: 00:00:00.07
SQL> insert
  2    into tbl_guid
  3    select  sys_guid()
  4      from  dual
  5      connect by level <= 1000000
  6  /

1000000 rows created.

Elapsed: 00:00:40.23


And if we increase cache to 100:

SQL> create sequence s cache 100
  2  /

Sequence created.

Elapsed: 00:00:00.00
SQL> insert
  2    into tbl
  3    select  s.nextval
  4      from  dual
  5      connect by level <= 1000000
  6  /

1000000 rows created.

Elapsed: 00:00:05.40
SQL> 


SY.
Re: The use of SYS_GUID() for Primary Key [message #554686 is a reply to message #554665] Wed, 16 May 2012 09:32 Go to previous messageGo to next message
John Watson
Messages: 3113
Registered: January 2010
Location: Global Village
Senior Member
So a sequence is faster - I hadn't expected that. But in a RAC you may still have dreadful problems if the sequence is created with ORDER, which a lot of developers insist on doing.
Re: The use of SYS_GUID() for Primary Key [message #554694 is a reply to message #554686] Wed, 16 May 2012 10:30 Go to previous messageGo to next message
Michel Cadot
Messages: 54236
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
I expected this.
A sequence is just (most of the time) picking a value in memory.
SYS_GUID is a complex function getting some information from the OS.

Regards
Michel
Re: The use of SYS_GUID() for Primary Key [message #554695 is a reply to message #554686] Wed, 16 May 2012 10:33 Go to previous messageGo to next message
Solomon Yakobson
Messages: 1404
Registered: January 2010
Senior Member
John Watson wrote on Wed, 16 May 2012 10:32
So a sequence is faster - I hadn't expected that. But in a RAC you may still have dreadful problems if the sequence is created with ORDER, which a lot of developers insist on doing.


Yes, RAC is a different story. Then, especially if the sequence is created with ORDER, it is completely dependent on interconnect speed/load.

SY.
Re: The use of SYS_GUID() for Primary Key [message #554697 is a reply to message #554695] Wed, 16 May 2012 10:35 Go to previous messageGo to next message
Michel Cadot
Messages: 54236
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
And the question is why a sequence is created with ORDER?
I bet 99.999% of the time it is for bad reasons.

Regards
Michel

[Updated on: Wed, 16 May 2012 10:35]

Report message to a moderator

Re: The use of SYS_GUID() for Primary Key [message #554698 is a reply to message #554697] Wed, 16 May 2012 10:42 Go to previous messageGo to next message
Solomon Yakobson
Messages: 1404
Registered: January 2010
Senior Member
Even without ORDER in RAC sequence put some additional load on interconnect.

SY.
Re: The use of SYS_GUID() for Primary Key [message #554703 is a reply to message #554698] Wed, 16 May 2012 11:09 Go to previous messageGo to next message
Michel Cadot
Messages: 54236
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Afaik, only when local sequence cache is exhausted.

Regards
Michel
Re: The use of SYS_GUID() for Primary Key [message #554724 is a reply to message #554703] Wed, 16 May 2012 20:16 Go to previous messageGo to next message
andrew again
Messages: 2572
Registered: March 2000
Senior Member
It's worth knowing about platform specific differences in GUIDs.

SQL> select * from v$version order by 1;

BANNER
----------------------------------------------------------------
CORE    10.2.0.1.0      Production
NLSRTL Version 10.2.0.1.0 - Production
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
PL/SQL Release 10.2.0.1.0 - Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production

SQL> select dbms_utility.port_string from dual;

PORT_STRING
--------------------------------------------------------------------------------
IBMPC/WIN_NT-8.1.0

SQL> BEGIN
  2  FOR indx IN 1 .. 5
  3  LOOP
  4  DBMS_OUTPUT.put_line ( SYS_GUID );
  5  END LOOP;
  6  END;
  7  /
8295E8290E5D4A6AAE72ACB0E0099BAE
AC073A39926C46DFB487A111859C2EB8
2D90C80B0EE7431AB07EDBBD4D0393F6
9F3B8D8BCDA249648ECFB3F6707C20AE
A395082816FE4EFB9833B9EA5E163012

PL/SQL procedure successfully completed.

SQL>
SQL> select * from v$version order by 1;

BANNER
--------------------------------------------------------------------------------
CORE    11.2.0.1.0      Production
NLSRTL Version 11.2.0.1.0 - Production
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
TNS for Solaris: Version 11.2.0.1.0 - Production

SQL> select dbms_utility.port_string from dual;

PORT_STRING
--------------------------------------------------------------------------------
SVR4-be-64bit-8.1.0

SQL> BEGIN
  2  FOR indx IN 1 .. 5
  3  LOOP
  4  DBMS_OUTPUT.put_line ( SYS_GUID );
  5  END LOOP;
  6  END;
  7  /
C0319B33F73A4F63E0440003BA60882B
C0319B33F73B4F63E0440003BA60882B
C0319B33F73C4F63E0440003BA60882B
C0319B33F73D4F63E0440003BA60882B
C0319B33F73E4F63E0440003BA60882B

PL/SQL procedure successfully completed.

SQL>


I've never been tempted to use GUIDs due to the extra space they use, and the fact that sequence numbers are actually useful sometimes in determining transaction order. It's nice to be able to trace issues using somewhat human readable values. Even if you have tons of space, wider keys will use more space and that's likely to create a little more I/O. Maybe a neglegible consideration to you. If you've ever had to try merging data from 2 schemas into 1, you would likely have encountered duplicate keys. GUIDs would have avoided that issue...

Code snippet borrowed from ==> http://feuerthoughts.blogspot.com/2006/02/watch-out-for-sequential-oracle-guids.html

[Updated on: Wed, 16 May 2012 20:20]

Report message to a moderator

Re: The use of SYS_GUID() for Primary Key [message #554745 is a reply to message #554724] Thu, 17 May 2012 00:51 Go to previous messageGo to next message
Michel Cadot
Messages: 54236
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
determining transaction order


Define transation order. Time when they start? when they finish? why when they query for sequence number?

Quote:
It's nice to be able to trace issues using somewhat human readable values


What about a timestamp then?

Regards
Michel


Re: The use of SYS_GUID() for Primary Key [message #554845 is a reply to message #554745] Thu, 17 May 2012 20:20 Go to previous messageGo to next message
andrew again
Messages: 2572
Registered: March 2000
Senior Member
You are right, start and end (commit) of the transaction are different. I'm not sure what you mean about timestamps, but I dont think you're suggesting them as PKs. Neither sequences (assuming for a monent that they were sequential over time) nor timestamps would correspond to the end of the transaction.
Re: The use of SYS_GUID() for Primary Key [message #554852 is a reply to message #554845] Fri, 18 May 2012 00:30 Go to previous message
Michel Cadot
Messages: 54236
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
but I dont think you're suggesting them as PKs.


No, I mean to easily "trace issues with a human readable value".

Regards
Michel
Previous Topic: ERROR PLS-00306: Wrong number of types of arguments in call to...
Next Topic: process fails due to ORA:-01410 INVALID ROWID error
Goto Forum:
  


Current Time: Sat May 25 01:00:33 CDT 2013

Total time taken to generate the page: 0.15878 seconds