Skip to Main Content
  • Questions
  • Poor performance using public synonyms

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Michael.

Asked: June 21, 2000 - 2:56 am UTC

Last updated: May 10, 2011 - 9:17 am UTC

Version: 8.0.5.1

Viewed 10K+ times! This question is

You Asked

Hello Tom,

A person has been giving seminars all over Australia and one of his suggestions to his audience has been 'don't use public synonyms if you have a large user base'. His argument is summarised on his webpage:

</code> http://www.ixora.com.au/q+a/2000_02.htm <code>(search for 'public synonyms')

He says that he has proven this using memory dumps.

My understanding of his argument during the seminar was that each user is allocated space in the library cache for each public synonym object referenced by code that they execute. The volume of entries is causing the poor performance.

We use public synonyms extensively and we are about to release our first 200+ user application, so an answer would be appreciated.

regards,

Michael

and Tom said...

Steve Adams is a smart guy.

Public Synonyms are not entirely evil. They are something you can avoid if you want to. They are not, in my opinion, something to be totally avoided. I use them but I do not overuse them.

I do most all of my work with packages -- end users never see the tables at all. There are relatively few "exposed" packages when compared to the total number of packages + tables and so on. So, there are a moderate number of synonyms in use.

You have to consider that thats the way the database works as well. We have dbms_output (no one calls sys.dbms_output), we have dbms_alert, dbms_pipe, utl_file, .... and so on. We have all_objects (not sys.all_objects) and so on. The database itself makes use of these public synonyms.

In the end, its a matter of sizing and testing. I for one cannot fully reproduce some of his points. The CPU parse point for example. I tried:

scott@ORA806.WORLD> declare
2 type rc is ref cursor;
3 x rc;
4 begin
5 for i in 1 .. 500 loop
6 open x for select * from tkyte.t;
7 close x;
8 end loop;
9 end;
10 /

PL/SQL procedure successfully completed.

Elapsed: 00:00:02.99
scott@ORA806.WORLD>
scott@ORA806.WORLD> declare
2 type rc is ref cursor;
3 x rc;
4 begin
5 for i in 1 .. 500 loop
6 open x for select * from t_pub_syn;
7 close x;
8 end loop;
9 end;
10 /

PL/SQL procedure successfully completed.

Elapsed: 00:00:02.60
scott@ORA806.WORLD>
scott@ORA806.WORLD> declare
2 type rc is ref cursor;
3 x rc;
4 begin
5 for i in 1 .. 500 loop
6 open x for select * from t_priv_syn;
7 close x;
8 end loop;
9 end;
10 /

PL/SQL procedure successfully completed.

Elapsed: 00:00:02.58
scott@ORA806.WORLD>


tkprof shows me:


SELECT *
FROM
TKYTE.T


call count cpu elapsed disk query
------- ------ -------- ---------- ---------- ----------
Parse 500 0.85 0.86 0 0
Execute 500 0.15 0.13 0 0
Fetch 0 0.00 0.00 0 0


SELECT *
FROM
T_PUB_SYN


call count cpu elapsed disk query
------- ------ -------- ---------- ---------- ----------
Parse 500 0.89 0.88 0 0
Execute 500 0.10 0.08 0 0
Fetch 0 0.00 0.00 0 0

SELECT *
FROM
T_PRIV_SYN


call count cpu elapsed disk query
------- ------ -------- ---------- ---------- ----------
Parse 500 1.01 1.00 0 0
Execute 500 0.11 0.09 0 0
Fetch 0 0.00 0.00 0 0


So, the public synonym did not take 4x the CPU of the fully qualified or the private synonym -- they were all pretty much "equivalent" in this case. I would need to see his test case to fully understand how the 1:2:4 ratio came about.


So, I would take into consideration what Steve says -- however, I would also look at how my system is performing. I run a system that gets about 1,000-2,000 different named users every day. We use public synonyms for lots of different top level packges (but not on other stuff). It works well. Since each of our packages are in different schemas, a simple "alter session set current_schema" would not work for us (we have about 100 application schemas -- we don't know which one of these you want to use up front).



Rating

  (4 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

How can acces by other users ?????

Emit, May 31, 2001 - 12:27 pm UTC

If i not create the public synonym others users can acces to the object, what i need to create for acces that object created without synonym ?

Tom

Akhilesh, September 18, 2001 - 2:52 am UTC

In order to beat this topic to death, why dont we ask Steve adams directly at-</code> http://www.ixora.com/contact.htm <code>



Public Synonyms

A reader, January 30, 2009 - 7:11 pm UTC

Hi Tom,

Technically:

1) What additional step Oracle has to perform with synonyms, which could lead to more usage of CPU? and
2) Though I don't work directly in oracle applications, but I came to know that Oracle applications uses synonyms quite a lot, if true, then probably that is good candidate for improving Oracle apps performance...

Regards,
Tom Kyte
January 30, 2009 - 9:12 pm UTC

1) forget performance - I give up on performance discussions as a tool to get things in the right direction.

They are wrong because they flood the namespace - making consolidation impossible.

They are a level of indirection that confuses everyone - now and especially in the future.

They allow for trojans to be injected into a system easily - you are NOT the only one with create public synonym. There is a really good practice I hadn't even thought about fully that came up recently. Here it is:

when coding plsql, do not call something like dbms_output.put_line (relying on that synonym...) - do call SYS.dbms_output.put_line - you cannot have your code get kidnapped and execute other code you did not intend accidentally - using YOUR privileges.


2) forget performance, it has come up as a security issue - Starting from now and forever - I'll be hitting on security aspects. Too many people say "performance smormance, I don't care". Turn it into a security issue and they pop their heads up and take notice.

Overused

Parthiban Nagarajan, May 10, 2011 - 8:30 am UTC

Hi Tom

We have only one application schema and let it be 'XYZ' ...
Based on the counts given below, may I have your comments on our usage of Public Synonyms? I think, we can go for execute immediate 'alter session set current_schema=''XYZ''' in an after logon trigger (because of only one application schema);
SQL> select count(*) from all_synonyms   where owner = 'PUBLIC'    and table_owner = 'XYZ';

  COUNT(*)
----------
      2324

SQL> select count(*) from all_tables     where owner = 'XYZ';

  COUNT(*)
----------
       873

SQL> select count(*) from all_views      where owner = 'XYZ';

  COUNT(*)
----------
       445

SQL> select count(distinct object_name)
  2    from all_procedures
  3   where owner = 'XYZ' and object_type = 'PACKAGE' and procedure_name is not null;

COUNT(DISTINCTOBJECT_NAME)
--------------------------
                       171

SQL> select count(*)
  2    from all_synonyms   syn
  3    join all_tables     tab
  4      on (syn.table_owner = tab.owner
  5     and  syn.table_name  = tab.table_name)
  6   where syn.owner        = 'PUBLIC'
  7     and syn.table_owner  = 'XYZ';

  COUNT(*)
----------
       859

SQL> select count(*)
  2    from all_synonyms   syn
  3    join all_views      viu
  4      on (syn.table_owner = viu.owner
  5     and  syn.table_name  = viu.view_name)
  6   where syn.owner        = 'PUBLIC'
  7     and syn.table_owner  = 'XYZ';

  COUNT(*)
----------
       428

SQL> select count(distinct object_name)
  2    from all_synonyms   syn
  3    join all_procedures prc
  4      on (syn.table_owner = prc.owner
  5     and  syn.table_name  = prc.object_name)
  6   where syn.owner        = 'PUBLIC'
  7     and syn.table_owner  = 'XYZ'
  8     and prc.object_type  = 'PACKAGE'
  9     and procedure_name is not null;

COUNT(DISTINCTOBJECT_NAME)
--------------------------
                       171

SQL> 

Though I am not sure of the performance impact, I am damn sure that the public synonyms are not wisely used here (given that we have another good alternative)
Tom Kyte
May 10, 2011 - 9:17 am UTC

it was higher than one (the count) so I personally think you used too many. I'll give you one maybe. If you can really justify the need.


More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library