From 6a653f3295c987c2c7484bbfedfb260f127ec25c Mon Sep 17 00:00:00 2001 From: Mike Dvorkin Date: Sat, 7 Aug 2010 19:33:29 -0700 Subject: [PATCH] Don't build the index unless table has primary key --- src/table.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/table.c b/src/table.c index 84c2461..0238c53 100644 --- a/src/table.c +++ b/src/table.c @@ -248,14 +248,16 @@ PTable pit_table_load(FILE *file) { pt->slots = pr = calloc(pt->number_of_slots, pt->record_size); pt->index = pi = calloc(pt->number_of_slots, sizeof(uchar *)); /* - ** Now read the records into the slots and rebuild the index. + ** Now read the records into the slots and rebuild the index if the + ** table has primary key. */ read += fread(pt->slots, pt->record_size, pt->number_of_records, file); - for(i = 1; i <= pt->number_of_slots; i++, pi++) { - // TODO: if table doesn't have id || has id && id matches... - if ((ulong)*pr == i) { - *pi = pr; - pr += pt->record_size; + if (pt->flags & TABLE_HAS_ID) { + for(i = 1; i <= pt->number_of_slots; i++, pi++) { + if ((ulong)*pr == i) { + *pi = pr; + pr += pt->record_size; + } } } return pt;