Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Performance question: Varchar select versus Join

Performance question: Varchar select versus Join

From: james mcgill <fishbowl_at_famine.phx3.mindspring.net>
Date: 3 Apr 2002 20:14:55 GMT
Message-ID: <a8fnrv$8lr$1@nntp9.atl.mindspring.net>


Hello, I hope someone can help settle a debate I'm having currently regarding performance.

To illustrate the question with an example, let there be two tables such as these:

CREATE TABLE PREFIX (
    prefix VARCHAR2(80),
    prefix_id NUMBER(20) NOT NULL,
    CONSTRAINT pk_prefix_id PRIMARY KEY(prefix_id)
);

CREATE TABLE SUFFIX (
    suffix VARCHAR2(80),
    suffix_id NUMBER(20) NOT NULL,
    CONSTRAINT pk_suffix_id PRIMARY KEY(suffix_id)
);

Now, it seems to me that the following select should not really be a performance problem:

SELECT PREFIX.prefix, SUFFIX.suffix FROM PREFIX, SUFFIX

    WHERE (SUFFIX.suffix = 'whatever' AND PREFIX.prefix_id = SUFFIX.suffix_id);

The argument is that it is "obvious" that it will be far higher performance to denormalize the PREFIX table by adding a field for PREFIX+SUFFIX and query on it, like so:

CREATE TABLE PREFIX (
    prefix VARCHAR2(80),
    aggregate VARCHAR2(160),
    prefix_id NUMBER(20) NOT NULL,
    CONSTRAINT pk_prefix_id PRIMARY KEY(prefix_id)
);

then to select like this:

SELECT PREFIX.aggregate FROM PREFIX WHERE (PREFIX.aggregate = 'thiswhatever');

Is it really so obvious that a single table character match on a longer varchar will significantly outperform a two-table join with a shorter varchar match and numeric primary keys? In our implementation, the tables will have 200,000 records each, and this query will be made very frequently.

Thank you for any advice you have to offer.

James
Tempe AZ

-- 
Received on Wed Apr 03 2002 - 14:14:55 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US