Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Need ideas for "proof test"
"Ed Stevens" <nospam_at_noway.nohow> wrote in message
news:atgu30tvstujr33jagkcvfp0f27a17eddn_at_4ax.com...
> On Thu, 26 Feb 2004 11:28:48 -0800, Daniel Morgan
> <damorgan_at_x.washington.edu> wrote:
> >CREATE TABLE pkfirst (
> >id NUMBER(10),
> >col1 VARCHAR2(10),
> >col2 VARCHAR2(10),
> >col3 VARCHAR2(10),
> >col4 VARCHAR2(10));
> >
> >CREATE TABLE pklast (
> >col1 VARCHAR2(10),
> >col2 VARCHAR2(10),
> >col3 VARCHAR2(10),
> >col4 VARCHAR2(10),
> >id NUMBER(10));
> >
> >ALTER TABLE pkfirst
> >ADD CONSTRAINT pk_pkfirst
> >PRIMARY KEY (id)
> >USING INDEX;
> >
> >ALTER TABLE pklast
> >ADD CONSTRAINT pk_pklast
> >PRIMARY KEY (id)
> >USING INDEX
> >TABLESPACE indx_sml;
> >
> >BEGIN
> > FOR i IN 1..200000
> > LOOP
> > INSERT INTO pkfirst
> > VALUES
> > (i, 'AAAAAAAAAA', 'BBBBBBBBBB', 'CCCCCCCCCC', 'DDDDDDDDDD');
> >
> > INSERT INTO pklast
> > VALUES
> > ('AAAAAAAAAA', 'BBBBBBBBBB', 'CCCCCCCCCC', 'DDDDDDDDDD', i);
> > END LOOP;
> > COMMIT;
> >END;
> >/
> >
> >set serveroutput on
> >
> >DECLARE
> > i PLS_INTEGER;
> > s pkfirst.col1%TYPE;
> >BEGIN
> > i := dbms_utility.get_time();
> >
> > FOR i IN REVERSE 1 .. 200000
> > LOOP
> > SELECT col1
> > INTO s
> > FROM pkfirst
> > WHERE id = i;
> > END LOOP;
> >
> > dbms_output.put_line('First: ' || TO_CHAR(dbms_utility.get_time()-i));
> >
> > i := dbms_utility.get_time();
> >
> > FOR i IN REVERSE 1 .. 200000
> > LOOP
> > SELECT col1
> > INTO s
> > FROM pklast
> > WHERE id = i;
> > END LOOP;
> >
> > dbms_output.put_line('Last: ' || TO_CHAR(dbms_utility.get_time()-i));
> >END;
> >/
> >
> >First: 3731
> >Last: 5366
> >
> >The PK in the first column consistently performs better at both 20,000
> >and 200,000 rows.
>
>
>
My *guess* (and maybe hope) would be that the example Dan provides has a constant component, how long it takes to read the index, but varies in the table access by rowid component (because Oracle doesn't have to read the whole row to answer the query).
I'd like to extend the test as follows though.
In other words try and reflect real life data access in a bit more detail and factor in the cost of regular reorgs. The tests that dan proposes seem to be a bit biased in favour of highly organized data.
My guess is that you may save some small amount of time but at an unacceptably high cost. (unless you are paid overtime by the hour in which case of course the cost may well be acceptable :) ).
-- Niall Litchfield Oracle DBA Audit Commission UKReceived on Mon Mar 01 2004 - 03:40:12 CST