Your SlideShare is downloading. ×
Contiguous
Contiguous
Contiguous
Contiguous
Contiguous
Contiguous
Contiguous
Contiguous
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Contiguous

78

Published on

oracle foreign key primary key constraints performance tuning MTS IOT 9i block size backup rman corrupted column drop rename recovery controlfile backup clone architecture database archives export …

oracle foreign key primary key constraints performance tuning MTS IOT 9i block size backup rman corrupted column drop rename recovery controlfile backup clone architecture database archives export dump dmp duplicate rows extents segments fragmentation hot cold blobs migration tablespace locally managed redo undo new features rollback ora-1555 shrink free space user password link TNS tnsnames.ora listener java shutdown sequence

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
78
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. The Contiguousness of Extents Administration TipsDo Extents need to be next to each other in the Tablespace?A lot of people often ask whether the fact that a segment’s extents are scatteredthroughout a tablespace and interspersed with the extents from other segments makes adifference to the performance of queries and DML on that segment.For example, if Tables A, B and C have their extents arranged within a tablespace like this:AAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCC…we would say that Table A’s extents were contiguous one with another. Likewise, TableB’s extents are contiguous, and so are Table C’s.On the other hand, it is rather more likely in a production system that you.d see a randomarrangements of extents, like this:ABCBCBCAABCBACBCBCBCAABCBAABCBCBCABCBBABCBCBCAABCBACBAABCBCBCABC…and so on. Arranged like this, we say that Table A’s (and B’s and C’s) extents arediscontiguous. The question is therefore whether the discontiguousness of a table’sextents matter for the speed with which Oracle can perform selects, inserts, updates anddeletes on that segment.At the end of this paper is a simple test you can run to demonstrate the truth of this foryourself. It’s a script which will create a procedure called ‘CONTEST’. That procedurecreates a number of tables (you decide how many when you call the procedure) with theirextents beautifully contiguous to each other… and then repeats the process, but this timemaking sure that the extents are totally discontiguous. It loads each table with aroundhalf a million rows, and then monitors the time it takes to select and delete all thoserecords.The nice thing about the procedure is that you can run it easily several times –making itcreate the tables in a variety of different tablespaces. Given this ability, it is now trivialto compare the performance for tables with large extents versus ones with lots of smallextents –you just make sure you create tablespaces that allocate differently-sized extentsto segments housed within them. It’s also easy to compare dictionary-managedtablespaces with locally managed tablespaces: just run the procedure first on a dictionary-managed tablespace, and then repeat the run specifying a locally managed one.For the test to be fair, it’s important that you run it against a freshly-created tablespace.If you use an existing one, there’s no guarantee that what the procedure seeks to create ascontiguous actually will be contiguous.Copyright © Howard Rogers 2002 3/11/2002 Page 1 of 8
  • 2. The Contiguousness of Extents Administration TipsIt’s also important that the account used to run the tests should be freshly-created,owning no other objects in the database. This User needs execute rights on thedbms_utility package, and an unlimited quota on the tablespace you’ve created to run thetest against. So, you might do the following preparatory work:create tablespace CONTEST1 datafile d:somewherefilename1.dbfsize 500m autoextend on next 500m minimum extent 64k default storage (maxextents2000 initial 64k next 64k pctincrease 0) extent management dictionary;Create user howard identified by password;Grant create session, create procedure to howard;Grant execute on dbms_utility to howard;Grant select any table,create any table,delete any table,drop any table to howard;Alter user howard quota unlimited on contest1;Obviously, if you want to test the performance of locally managed tablespaces, that firstcommand would be replaced with something rather more like this:create tablespace CONTEST1 datafile d:somewherefilename1.dbf size 500mautoextend on next 500m extent management local uniform size 64k;Next you need to create the procedure in the schema of the user just created. If you savethe script as a text file, called “contig.txt”, you just do this:SQL>@c:somewherecontig.txtIncidentally, the script is downloadable in its own right from www.hjrdba.com/scripts/contig.sqlOnce you’ve done that, you’re ready to execute the procedure. It accepts fourparameters: how many tables do you want to test with, the tablespace in which theyshould be created (enclosed in quotation marks), the number of records you want topopulate them with, and the directory on the server itself where the test results should bewritten to (again in quotation marks):SQL> execute contest(5,’CONTEST1’,500000,’C:TEMP’)That last parameter must match your init.ora’s UTL_FILE_DIR parameter exactly. If youhaven’t got it set in your init.ora, you will need to set it and re-start the Instanceafterwards. The results are output in a file called contest.txt. For good measure, thetest runs with the same settings three times.If you then want to repeat the test on a differently-sized or differently-managedtablespace, just create the new tablespace, and re-execute the procedure, specifying thenew tablespace name. The new results will replace the old ones, though –so you mightwant to re-name the original contest.txt file first.Obviously, the real fun with this procedure is testing it out for yourself, in your ownenvironment. But here are the results of a few runs I performed on a rather patheticCeleron 1GHz machine with all datafiles on a single hard disk:Copyright © Howard Rogers 2002 3/11/2002 Page 2 of 8
  • 3. The Contiguousness of Extents Administration TipsRUN 1:------------------------------------------------------ ------------------------------------------------------760 CONTIGUOUS EXTENTS 12 CONTIGUOUS EXTENTS------------------------------------------------------ ------------------------------------------------------503994 records for Table CON1 selected in 2.39 seconds 503994 records for Table CON1 selected in 2.21 seconds504108 records for Table CON2 selected in 2.45 seconds 504108 records for Table CON2 selected in 2.37 seconds504222 records for Table CON3 selected in 2.45 seconds 504222 records for Table CON3 selected in 2.23 seconds504336 records for Table CON4 selected in 2.45 seconds 504336 records for Table CON4 selected in 2.19 seconds504450 records for Table CON5 selected in 1.52 seconds 504450 records for Table CON5 selected in 1.76 secondsAverage select time for all tables: 2.252 seconds. Average select time for all tables: 2.152 seconds.504450 records for Table CON1 deleted in 49.42 seconds 504450 records for Table CON1 deleted in 44.64 seconds504450 records for Table CON2 deleted in 45.75 seconds 504450 records for Table CON2 deleted in 52.46 seconds504450 records for Table CON3 deleted in 49.3 seconds 504450 records for Table CON3 deleted in 58.41 seconds504450 records for Table CON4 deleted in 47.59 seconds 504450 records for Table CON4 deleted in 56.64 seconds504450 records for Table CON5 deleted in 48.86 seconds 504450 records for Table CON5 deleted in 57.09 secondsAverage delete time for all tables: 48.186 seconds. Average delete time for all tables: 53.848 seconds.------------------------------------------------------ ------------------------------------------------------760 DISCONTIGUOUS EXTENTS 12 DISCONTIGUOUS EXTENTS------------------------------------------------------ ------------------------------------------------------504446 records for Table CON1 selected in 3.05 seconds 504446 records for Table CON1 selected in 2.39 seconds504447 records for Table CON2 selected in 2.9 seconds 504447 records for Table CON2 selected in 2.12 seconds504448 records for Table CON3 selected in 3.08 seconds 504448 records for Table CON3 selected in 2.15 seconds504449 records for Table CON4 selected in 2.9 seconds 504449 records for Table CON4 selected in 2.5 seconds504450 records for Table CON5 selected in 3.03 seconds 504450 records for Table CON5 selected in 2.23 secondsAverage select time for all tables: 2.992 seconds. Average select time for all tables: 2.278 seconds.504450 records for Table CON1 deleted in 50.27 seconds 504450 records for Table CON1 deleted in 56.66 seconds504450 records for Table CON2 deleted in 50.15 seconds 504450 records for Table CON2 deleted in 49.53 seconds504450 records for Table CON3 deleted in 50.14 seconds 504450 records for Table CON3 deleted in 51.56 seconds504450 records for Table CON4 deleted in 49.9 seconds 504450 records for Table CON4 deleted in 50.26 seconds504450 records for Table CON5 deleted in 49.76 seconds 504450 records for Table CON5 deleted in 53.68 secondsAverage delete time for all tables: 50.044 seconds. Average delete time for all tables: 52.338 seconds.RUN 2:------------------------------------------------------ ------------------------------------------------------760 CONTIGUOUS EXTENTS 12 CONTIGUOUS EXTENTS------------------------------------------------------ ------------------------------------------------------503994 records for Table CON1 selected in 2.5 seconds 503994 records for Table CON1 selected in 2.1 seconds504108 records for Table CON2 selected in 2.74 seconds 504108 records for Table CON2 selected in 2.19 seconds504222 records for Table CON3 selected in 2.46 seconds 504222 records for Table CON3 selected in 2.25 seconds504336 records for Table CON4 selected in 2.44 seconds 504336 records for Table CON4 selected in 2.32 seconds504450 records for Table CON5 selected in 1.82 seconds 504450 records for Table CON5 selected in 2.15 secondsAverage select time for all tables: 2.392 seconds. Average select time for all tables: 2.202 seconds.504450 records for Table CON1 deleted in 46.72 seconds 504450 records for Table CON1 deleted in 47.79 seconds504450 records for Table CON2 deleted in 45.12 seconds 504450 records for Table CON2 deleted in 52.17 seconds504450 records for Table CON3 deleted in 46.21 seconds 504450 records for Table CON3 deleted in 56.39 seconds504450 records for Table CON4 deleted in 48.15 seconds 504450 records for Table CON4 deleted in 60.43 seconds504450 records for Table CON5 deleted in 46.3 seconds 504450 records for Table CON5 deleted in 59.91 secondsAverage delete time for all tables: 46.5 seconds. Average delete time for all tables: 55.338 seconds.------------------------------------------------------ ------------------------------------------------------760 DISCONTIGUOUS EXTENTS 12 DISCONTIGUOUS EXTENTS------------------------------------------------------ ------------------------------------------------------504446 records for Table CON1 selected in 2.99 seconds 504446 records for Table CON1 selected in 2.26 seconds504447 records for Table CON2 selected in 2.9 seconds 504447 records for Table CON2 selected in 2.23 seconds504448 records for Table CON3 selected in 2.66 seconds 504448 records for Table CON3 selected in 2.35 seconds504449 records for Table CON4 selected in 2.88 seconds 504449 records for Table CON4 selected in 2.35 seconds504450 records for Table CON5 selected in 2.97 seconds 504450 records for Table CON5 selected in 2.18 secondsAverage select time for all tables: 2.88 seconds. Average select time for all tables: 2.274 seconds.504450 records for Table CON1 deleted in 51.02 seconds 504450 records for Table CON1 deleted in 60.65 seconds504450 records for Table CON2 deleted in 49.06 seconds 504450 records for Table CON2 deleted in 45.5 seconds504450 records for Table CON3 deleted in 49.46 seconds 504450 records for Table CON3 deleted in 47.05 seconds504450 records for Table CON4 deleted in 48.6 seconds 504450 records for Table CON4 deleted in 47.99 seconds504450 records for Table CON5 deleted in 51.7 seconds 504450 records for Table CON5 deleted in 46.91 secondsAverage delete time for all tables: 49.968 seconds. Average delete time for all tables: 49.62 seconds.Copyright © Howard Rogers 2002 3/11/2002 Page 3 of 8
  • 4. The Contiguousness of Extents Administration TipsRUN 3:------------------------------------------------------ ------------------------------------------------------760 CONTIGUOUS EXTENTS 12 CONTIGUOUS EXTENTS------------------------------------------------------ ------------------------------------------------------503994 records for Table CON1 selected in 2.06 seconds 503994 records for Table CON1 selected in 2.19 seconds504108 records for Table CON2 selected in 2.16 seconds 504108 records for Table CON2 selected in 2.47 seconds504222 records for Table CON3 selected in 2.19 seconds 504222 records for Table CON3 selected in 2.51 seconds504336 records for Table CON4 selected in 2.06 seconds 504336 records for Table CON4 selected in 2.48 seconds504450 records for Table CON5 selected in 1.69 seconds 504450 records for Table CON5 selected in 1.89 secondsAverage select time for all tables: 2.032 seconds. Average select time for all tables: 2.308 seconds.504450 records for Table CON1 deleted in 48.67 seconds 504450 records for Table CON1 deleted in 47.04 seconds504450 records for Table CON2 deleted in 46.39 seconds 504450 records for Table CON2 deleted in 57.63 seconds504450 records for Table CON3 deleted in 47.6 seconds 504450 records for Table CON3 deleted in 56.61 seconds504450 records for Table CON4 deleted in 46.86 seconds 504450 records for Table CON4 deleted in 49.11 seconds504450 records for Table CON5 deleted in 46.2 seconds 504450 records for Table CON5 deleted in 47.87 secondsAverage delete time for all tables: 47.146 seconds. Average delete time for all tables: 51.652 seconds.------------------------------------------------------ ------------------------------------------------------760 DISCONTIGUOUS EXTENTS 12 DISCONTIGUOUS EXTENTS------------------------------------------------------ ------------------------------------------------------504446 records for Table CON1 selected in 2.9 seconds 504446 records for Table CON1 selected in 2.44 seconds504447 records for Table CON2 selected in 3.07 seconds 504447 records for Table CON2 selected in 2.45 seconds504448 records for Table CON3 selected in 2.72 seconds 504448 records for Table CON3 selected in 4.15 seconds504449 records for Table CON4 selected in 2.77 seconds 504449 records for Table CON4 selected in 2.45 seconds504450 records for Table CON5 selected in 2.78 seconds 504450 records for Table CON5 selected in 2.75 secondsAverage select time for all tables: 2.848 seconds. Average select time for all tables: 2.848 seconds.504450 records for Table CON1 deleted in 50.25 seconds 504450 records for Table CON1 deleted in 49.89 seconds504450 records for Table CON2 deleted in 48.36 seconds 504450 records for Table CON2 deleted in 45.25 seconds504450 records for Table CON3 deleted in 49.51 seconds 504450 records for Table CON3 deleted in 46.81 seconds504450 records for Table CON4 deleted in 47.44 seconds 504450 records for Table CON4 deleted in 48.23 seconds504450 records for Table CON5 deleted in 48.79 seconds 504450 records for Table CON5 deleted in 48.38 secondsAverage delete time for all tables: 48.87 seconds. Average delete time for all tables: 47.712 seconds.I’m no statistician, but given the degree of variation that is evident between runs, andeven between processing the same number of records for different tables within a run,there’s no significant difference between contiguous and discontiguous, large or smallextents, whether selecting records or performing DML on them.If you just average the averages, you end up with this result:Contiguous small extents: 2.32 seconds to select, 47.28 seconds to deleteDiscontiguous small extents: 2.90 seconds to select, 49.63 seconds to deleteContiguous large extents: 2.22 seconds to select, 53.61 seconds to deleteDiscontiguous large extents: 2.46 seconds to select, 49.89 seconds to deleteSlice it and dice it any way you like, but there just isn’t a pattern in these figures. Neitherthe contiguity of extents (or lack thereof), nor the number of extents involved, makes anysignificant difference to the speed with which deletes or selects are performed.No doubt you could think of ways of improving this test: create 1000 segments, forexample, or process more rows. Be my guest: I’d love to see the results, because howevermany segments you create, and however discontiguous you make them, you’ll be runningup against a fundamental physical fact: even the blocks within a single extent aren’tactually contiguous on the hard disk.Copyright © Howard Rogers 2002 3/11/2002 Page 4 of 8
  • 5. The Contiguousness of Extents Administration TipsExtents are logical entities. They don’t have any real physical existence: at the end of theday, everything gets stored in operating system blocks on the hard disk anyway. It’s up tothe operating system to determine which operating system blocks to use when storing data–and, with the best will in the world, its chances of giving you a contiguous set of blocks inwhich to store your data are exceedingly slim.All Oracle is doing is imposing a level of logical structuring on those O/S blocks, saying, ineffect, that “these 16 512-byte operating system blocks will be regarded by me ascomprising one logical entity, a single 8K Oracle block.” But however Oracle regards those16 O/S blocks, the fact remains that they are independent physical entities .and they can(and will) come from all over the physical disk platter. Now if even an Oracle block is notcontiguous on disk, how can you expect a single extent to be physically contiguous? And ifa single extent cannot be physically contiguous, then it is obvious that a multiplicity ofextents can’t be contiguous either. Therefore, the contiguity of extents is a mirage thatnever actually happens at the physical hard disk level.Never mind the final argument: the contiguity of extents is often touted as a performancebooster, because it means the disk head doesn’t have to move around so much betweenreads. But in a multi-user system, how often are your disk heads going to be able to moveuninterruptedly from one O/S block to another before another User directs them to movesomewhere completely different? Never, is the short answer.That’s why it is pointless spending a great deal of time and effort striving to achieve asingle large extent for a segment. It’s why the number of extents for a segment (in LocallyManaged Tablespace, at any rate) is of so little concern. And it’s also why you shouldn’tworry about precisely where in a tablespace those extents end up.Extent numbers can be a concern, of course, in Dictionary Managed Tablespace. See mypaper in response to the question “Is there a “right” number of extents for a segment” fordetails, though the short story is that anything up to a few hundred extents is still going toimpose no noticeable overhead.Copyright © Howard Rogers 2002 3/11/2002 Page 5 of 8
  • 6. The Contiguousness of Extents Administration TipsThe Procedure --------------------------------------------------------------------------------------- Script: contig.txt-- Author: Howard J. Rogers-- Date: 8th March 2002-- Copyright: (c) Howard J. Rogers--------------------------------------------------------------------------------------- This script creates a procedure called contest. It was designed to-- allow you to test the oft-quoted myth that having lots or few extents-- makes a difference to query and DML performance. It was also designed-- to put an end to the nonsense that having a segments extents contiguous-- with each other in the tablespace makes a performance difference.-- The procedure therefore creates a number of tables. First, it creates-- them so that each tables extents are contiguous with each other. It-- then times selects and deletes. Then it drops the tables, and re-creates-- them so that their extents are interleaved with the extents of other-- tables. This is the discontiguous test.-- The script accepts 4 parameters: The number of tables to test with, the-- tablespace they should be created in, how many records they should be-- populated with, and where, on the server, the results should be written to-- (you specify the same directory as your UTL_FILE_DIR init.ora parameter is set to,-- the results then get written to a file called contest.txt in that directory).-- For accurate results, it is suggested that you run the test using a brand new-- User account, and a brand new tablespace.-- The user account needs the following permissions-- Grant create session, create procedure to USER;-- Grant select any table, create any table, delete any table to USER;-- Grant drop any table to USER;-- Grant execute on dbms_utility to USER;-- Alter user USERNAME quota unlimited on TABLESPACE;-- The key point is that these permissions must be directly granted to the user,-- not acquired via a role. There should be no quota restrictions for the user-- on the tablespace you propose to use for the test.-- The tablespace to be used can be created however you like. I suggest something-- like the following:-- create tablespace CONTEST1 datafile d:somewherefilename1.dbf-- size 500m autoextend on next 500m extent management local uniform size 64k;-- ...but dictionary managed tablespace is fine, too. You could also try creating-- a number of tablespaces with a variety of extent sizes: by running the procedure-- a number of times, youll then be able to see whether extent size and numbers-- have a performance impact.-- The procedure performs 3 test runs using the one set of run-time parameters.-- Obviously, you want nothing else running on the machine during run-time.-- You are responsible for tidying up after the procedure. Whilst it drops the-- test tables for you, it doesnt get rid of the tablespace, and it doesnt get-- rid of the user account you created to run it.-------------------------------------------------------------------------------------Copyright © Howard Rogers 2002 3/11/2002 Page 6 of 8
  • 7. The Contiguousness of Extents Administration Tipscreate or replace procedure contest (segs number, tblspc varchar2, numrecs number, fdir varchar2)asstarttime number default dbms_utility.get_time;endtime number default dbms_utility.get_time;deltime number(6,2);reccnt number;tottime number :=0;avgtime number :=0;iterations number :=0;objcnt number :=0;excnt number :=0;output utl_file.file_type;beginoutput := utl_file.fopen( fdir, contest.txt,w,32000);--determine number of iterations to get requested rows per tableFor x in 1 .. 3 loopexecute immediate select count(*) from all_objects into objcnt;iterations:=round(numrecs/objcnt);--contiguousutl_file.put_line(output,Test Run ||x|| Started : ||dbms_utility.get_time); for i in 1 .. segs loop execute immediate create table CON||i|| tablespace ||tblspc|| as select * from all_objects; for j in 1 .. iterations loop execute immediate insert into CON||i|| select * from all_objects; execute immediate commit; end loop; end loop; execute immediate select count(*) from user_extents into excnt; excnt:=excnt/segs; utl_file.put_line(output,------------------------------------------------------); utl_file.put_line(output,excnt || CONTIGUOUS EXTENTS ); utl_file.put_line(output,------------------------------------------------------); for i in 1 .. segs loop starttime:=dbms_utility.get_time; execute immediate select count(*) from CON||i into reccnt; utl_file.put_line (output,reccnt|| records for Table CON||i|| selected in || round( (dbms_utility.get_time-starttime)/100,2) || seconds); tottime:=tottime+round( (dbms_utility.get_time-starttime)/100,2); end loop; avgtime:=tottime/segs; utl_file.put_line (output,Average select time for all tables: ||avgtime|| seconds.); tottime:=0; for i in 1 .. segs loop starttime:=dbms_utility.get_time; execute immediate delete from CON||i; execute immediate commit; utl_file.put_line (output,reccnt|| records for Table CON||i|| deleted in || round( (dbms_utility.get_time-starttime)/100,2) || seconds); tottime:=tottime+round( (dbms_utility.get_time-starttime)/100,2); end loop;Copyright © Howard Rogers 2002 3/11/2002 Page 7 of 8
  • 8. The Contiguousness of Extents Administration Tips avgtime:=tottime/segs; utl_file.put_line (output,Average delete time for all tables: ||avgtime|| seconds.); tottime:=0;--Cleanup for i in 1 .. segs loop execute immediate drop table CON||i; end loop;--discontiguous utl_file.put_line(output,------------------------------------------------------); utl_file.put_line(output,excnt|| DISCONTIGUOUS EXTENTS ); utl_file.put_line(output,------------------------------------------------------); for i in 1 .. segs loop execute immediate create table CON||i|| tablespace ||tblspc|| as select * from all_objects; end loop; for j in 1 .. iterations loop for i in 1 .. segs loop execute immediate insert into CON||i|| select * from all_objects; execute immediate commit; end loop; end loop; for i in 1 .. segs loop starttime:=dbms_utility.get_time; execute immediate select count(*) from CON||i into reccnt; utl_file.put_line (output,reccnt|| records for Table CON||i|| selected in || round( (dbms_utility.get_time-starttime)/100,2) || seconds); tottime:=tottime+round( (dbms_utility.get_time-starttime)/100,2); end loop; avgtime:=tottime/segs; utl_file.put_line (output,Average select time for all tables: ||avgtime|| seconds.); tottime:=0; for i in 1 .. segs loop starttime:=dbms_utility.get_time; execute immediate delete from CON||i; execute immediate commit; utl_file.put_line (output,reccnt|| records for Table CON||i|| deleted in || round( (dbms_utility.get_time-starttime)/100,2) || seconds); tottime:=tottime+round( (dbms_utility.get_time-starttime)/100,2); end loop; avgtime:=tottime/segs; utl_file.put_line (output,Average delete time for all tables: ||avgtime|| seconds.);--Cleanup for i in 1 .. segs loop execute immediate drop table CON||i; end loop;end loop;utl_file.fflush(output);utl_file.fclose(output);end;/Copyright © Howard Rogers 2002 3/11/2002 Page 8 of 8

×