Subject | RE: [ib-support] Table size and indexing |
---|---|
Author | Helen Borrie |
Post date | 2001-06-18T10:16:25Z |
At 10:25 AM 18-06-01 +0100, you wrote:
Cheers,
Helen
All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________
> >Making foreign keys on other tables that reference these small tables willPrimary table in the structure?
>DEFINITELY slow >things down - IB will form long duplicate chains in the
>index tree of the mandatory index >and wreck performance. Instead, make
>composite indexes on such columns, combining the >lookup column + the
>primary key.
>
>I'd just about finished designing the database for an analysis system I'm
>developing when I read the above. Following is a (stripped down) table which
>records responses to direct response advertising campaigns:
>
>CREATE TABLE "RESPONSES"
>(
> "NUM" "POSITIVEBIGINT" NOT NULL,
> "CAMPNUM" "POSITIVEBIGINT" NOT NULL,
> "REGNUM" "POSITIVESMALLINT",
> "CONTMODENUM" "POSITIVEBIGINT" NOT NULL,
> "ADNUM" "POSITIVEBIGINT",
>CONSTRAINT "RESP_PK" PRIMARY KEY ("NUM")
>);
>
>CAMPNUM refers to the advertising campaign that generated the response.
>CAMPNUM is likely to be in the hundreds (or very low thousands).
>REGNUM refers to the region of the country from which the response came.Selectivity is too low to justify an index for sorting or joining purposes.
>REGNUM is about 12 and not likely to change.
>CONTACTMODENUM refers to the method of contact used (e.g. web, phone).Same as above if you have these defined in a control table.
>CONTACTMODENUM has only 2 values currently and is not likely to change much,
>say 10 or below.
>ADNUM refers to the advertisement (TV commercial, press ad, radio ad) thatForeign key relationship and its index are both justified.
>generated the response. ADNUM will be in the thousands.
>All these columns are implemeted as FK's to ensure data integrity and toI don't see why the first two tables need to referenced to ensure data integrity. The cost of those indexes is large; if you need data integrity triggers, write your own. The IB-generated indexes will be terrible. If you want these columns indexed in the referring table for ordering purposes, define your own composite indexes, viz. low-integrity key + pri key to raise their selectivity.
>make use of the IB generated indexes.
>Also, this keeps the design clean and/* Comments */ have the same effect without forcing you to accept engine-style foreign key constraints that kill performance because of their low selectivity. You can have foreign keys in your database without using the db engine to enforce it!
>understandable.
>Are you saying that none of these should be implemented asAdnum is the only eligible FK I see there.
>FK's?
>CONTACTMODENUM could be a domain with a check on the content, butWhy would you have to change the database structure to add a new contact method ????? If it's a control table, you only need to add a new row.
>since they are likely to change I would rather not have to change the
>database structure just to add a new contact method.
>What would be the best approach in the above 4 cases, from a performaceNo, it's not unique to IB, just particularly noticeable in IB. As for why, and for the scale of the performance hit, have a look at Ann's posting...
>viewpoint? What's the scale of the performane 'hit' with the above approach?
>If defining FK's as FK's produces a noticable performance penalty, is that
>unique to IB?
Cheers,
Helen
All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________