Corrections and enhancements on index handling.

This commit is contained in:
brianb
2001-05-23 01:42:46 +00:00
parent 7104e68db2
commit abab3e0fc8
5 changed files with 65 additions and 21 deletions

View File

@@ -23,7 +23,8 @@ GPtrArray *mdb_read_indices(MdbTableDef *table)
{
MdbHandle *mdb = table->entry->mdb;
MdbIndex idx, *pidx;
int len, i;
int len, i, j;
int idx_num, key_num, col_num;
int cur_pos;
int name_sz;
@@ -31,22 +32,14 @@ int name_sz;
table->indices = g_ptr_array_new();
cur_pos = table->index_start;
for (i=0;i<table->num_real_idxs;i++) {
memset(&idx, '\0', sizeof(MdbIndex));
idx.index_num = i;
cur_pos += 34;
idx.first_pg = mdb_get_int32(mdb, cur_pos);
cur_pos += 5;
mdb_append_index(table->indices, &idx);
}
cur_pos = table->index_start + 39 * table->num_real_idxs;
for (i=0;i<table->num_idxs;i++) {
pidx = g_ptr_array_index (table->indices, i);
memset(&idx, '\0', sizeof(MdbIndex));
idx.index_num = mdb_get_int16(mdb, cur_pos);
cur_pos += 19;
if (mdb->pg_buf[cur_pos++]==0x01)
pidx->primary_key=1;
idx.index_type = mdb->pg_buf[cur_pos++];
mdb_append_index(table->indices, &idx);
}
for (i=0;i<table->num_idxs;i++) {
@@ -57,13 +50,60 @@ int name_sz;
//fprintf(stderr, "index name %s\n", pidx->name);
cur_pos += name_sz;
}
cur_pos = table->index_start;
idx_num=0;
for (i=0;i<table->num_real_idxs;i++) {
do {
pidx = g_ptr_array_index (table->indices, idx_num++);
} while (pidx && pidx->index_type==2);
/* if there are more real indexes than index entries left after
removing type 2's decrement real indexes and continue. Happens
on Northwind Orders table.
*/
if (!pidx) {
table->num_real_idxs--;
continue;
}
key_num=0;
for (j=0;j<MDB_MAX_IDX_COLS;j++) {
col_num=mdb_get_int16(mdb,cur_pos);
cur_pos += 2;
if (col_num != 0xFFFF) {
/* set column number to a 1 based column number and store */
pidx->key_col_num[key_num]=col_num + 1;
if (mdb->pg_buf[cur_pos]) {
pidx->key_col_order[key_num]=MDB_ASC;
} else {
pidx->key_col_order[key_num]=MDB_DESC;
}
key_num++;
}
cur_pos++;
}
cur_pos += 4;
pidx->first_pg = mdb_get_int32(mdb, cur_pos);
cur_pos += 5;
}
}
void mdb_index_dump(MdbIndex *idx)
void mdb_index_dump(MdbTableDef *table, MdbIndex *idx)
{
int i;
MdbColumn *col;
fprintf(stdout,"index number %d\n", idx->index_num);
fprintf(stdout,"index name %s\n", idx->name);
fprintf(stdout,"index first page %d\n", idx->first_pg);
if (idx->primary_key) fprintf(stdout,"index is a primary key\n");
if (idx->index_type==1) fprintf(stdout,"index is a primary key\n");
for (i=0;i<MDB_MAX_IDX_COLS;i++) {
if (idx->key_col_num[i]) {
col=g_ptr_array_index(table->columns,idx->key_col_num[i]-1);
fprintf(stdout,"Column %s(%d) Sorted %s\n",
col->name,
idx->key_col_num[i],
idx->key_col_order[i]==MDB_ASC ? "ascending" : "descending"
);
}
}
}