Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Optimizing long string foreign keys
Boris Pelakh wrote:
> I have a schema design problem with which I would appreciate some
> advice. In my setup I have two tables, each having a very long string
> primary key (can easily be 1KB). More so, each row in table B refers
> to a row in Table A, so it has
> to store a copy of the TableA.key as well. I am concerned about
> performance,
> with the duplicate storage, the very long records, and the very long
> key.
>
> How can I resolve this problem ? I have considered auto-sequencing
> table A,
> and storing just the sequence number as a reference in table B, but I
> have
> a frequent need to do the following
>
> select <fields> from TableB where TableA_key = '<some value>';
>
> which would now force a JOIN. Is there a better solution ?
>
> I appreciate any help,
> Boris
I would still recommend auto-sequencing table A because the resulting join will still be faster than the original query with the long TableA_key included in TableB.
Here's how the original query (without joining) would be processed:
Here's how the joined query (using a sequence for the primary key of table A) would be processed:
If it's a data warehouse instead of OLTP, and TableB.foreignkey has a *low cardinality*, I would also use a bitmap join index if you're using 9i, so that the tables can be pre-joined. If the cardinality of TableB.foreignkey is low, then the performance improvement is well worth the extra storage required for the index.
CREATE BITMAP INDEX bji ON TableB (TableA.longstring) FROM TableB, TableA where TableB.foreignkey = TableA.primarykey
Cheers,
Dave
Received on Thu Aug 07 2003 - 23:55:33 CDT