8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 22:43:03 +01:00

Fix ODS10 support after per-segment index selectivity was introduced

This commit is contained in:
skidder 2003-12-31 22:40:09 +00:00
parent 5a552a2de1
commit 7dc877ff23
4 changed files with 38 additions and 13 deletions

View File

@ -389,7 +389,7 @@ bool BTR_description(JRD_REL relation, IRT root, IDX * idx, SSHORT id)
}
else {
idx_desc->idx_selectivity = irt_desc->irt_stuff.irt_selectivity;
ptr += (sizeof(irtd) - sizeof(float));
ptr += sizeof(irtd_ods10);
}
}
idx->idx_selectivity = irt_desc->irt_stuff.irt_selectivity;
@ -1460,15 +1460,16 @@ void BTR_reserve_slot(TDBB tdbb, JRD_REL relation, JRD_TRA transaction, IDX * id
// Scan the index page looking for the high water mark of the descriptions and,
// perhaps, an empty index slot
IRTD *desc;
UCHAR *desc;
USHORT l, space;
irt::irt_repeat * root_idx, *end, *slot;
bool maybe_no_room = false;
retry:
l = idx->idx_count * sizeof(IRTD);
// dimitr: irtd_selectivity member of IRTD is introduced in ODS11
if (dbb->dbb_ods_version < ODS_VERSION11)
l -= sizeof(float);
l = idx->idx_count * sizeof(irtd_ods10);
else
l = idx->idx_count * sizeof(irtd);
space = dbb->dbb_page_size;
slot = NULL;
@ -1487,10 +1488,10 @@ retry:
}
space -= l;
desc = (IRTD *) ((UCHAR*)root + space);
desc = (UCHAR*)root + space;
// Verify that there is enough room on the Index root page.
if (desc < (IRTD *) (end + 1)) {
if (desc < (UCHAR *) (end + 1)) {
// Not enough room: Attempt to compress the index root page and try again.
// If this is the second try already, then there really is no more room.
if (maybe_no_room) {
@ -1520,6 +1521,17 @@ retry:
}
slot->irt_root = 0;
if (dbb->dbb_ods_version < ODS_VERSION11) {
for (USHORT i=0; i<idx->idx_count; i++) {
irtd_ods10 temp;
temp.irtd_field = idx->idx_rpt[i].idx_field;
temp.irtd_itype = idx->idx_rpt[i].idx_itype;
memcpy(desc, &temp, sizeof(temp));
desc += sizeof(temp);
}
} else
// Exploit the fact idx_repeat structure matches ODS IRTD one
memcpy(desc, idx->idx_rpt, l);
if (dbb->dbb_wal) {
@ -2230,7 +2242,10 @@ static USHORT compress_root(TDBB tdbb, IRT page)
root_idx < end; root_idx++)
{
if (root_idx->irt_root) {
l = root_idx->irt_keys * sizeof(IRTD);
if (dbb->dbb_ods_version < ODS_VERSION11)
l = root_idx->irt_keys * sizeof(irtd_ods10);
else
l = root_idx->irt_keys * sizeof(irtd);
p -= l;
memcpy(p, (SCHAR*)page + root_idx->irt_desc, l);
root_idx->irt_desc = p - temp;

View File

@ -62,11 +62,12 @@ typedef struct idx {
jrd_nod* idx_expression; /* node tree for indexed expresssion */
struct dsc idx_expression_desc; /* descriptor for expression result */
struct jrd_req *idx_expression_request; /* stored request for expression evaluation */
// This structure should exactly match IRTD structure for current ODS
struct idx_repeat {
USHORT idx_field; /* field id */
USHORT idx_itype; /* data of field in index */
float idx_selectivity; /* segment selectivity */
} idx_rpt[16];
} idx_rpt[MAX_INDEX_SEGMENTS];
} IDX;
/* index types and flags */

View File

@ -999,22 +999,28 @@ static void dmp_root(IRT page)
*
**************************************/
irt::irt_repeat * desc;
struct irtd *stuff;
USHORT i, j;
ib_fprintf(dbg_file,
"INDEX ROOT PAGE\t checksum %d\t generation %ld\n\tRelation: %d, Count: %d\n",
((PAG) page)->pag_checksum, ((PAG) page)->pag_generation,
page->irt_relation, page->irt_count);
bool ods11plus = (GET_THREAD_DATA->tdbb_database->dbb_ods_version >= ODS_VERSION11);
for (i = 0, desc = page->irt_rpt; i < page->irt_count; i++, desc++) {
ib_fprintf(dbg_file,
"\t%d -- root: %ld, number of keys: %d, flags: %x\n", i,
desc->irt_root, desc->irt_keys, desc->irt_flags);
ib_fprintf(dbg_file, "\t keys (field, type): ");
stuff = (struct irtd *) ((SCHAR *) page + desc->irt_desc);
for (j = 0; j < desc->irt_keys; j++, stuff++)
SCHAR *ptr = (SCHAR *) page + desc->irt_desc;
for (j = 0; j < desc->irt_keys; j++) {
if (ods11plus) then
ptr += sizeof(irtd);
else
ptr += sizeof(irtd_ods10);
irtd* stuff = (irtd*)ptr;
ib_fprintf(dbg_file, "(%d, %d),", stuff->irtd_field,
stuff->irtd_itype);
}
ib_fprintf(dbg_file, "\n");
}
}

View File

@ -289,9 +289,12 @@ typedef struct irt {
/* key descriptor */
typedef struct irtd {
struct irtd_ods10 {
USHORT irtd_field;
USHORT irtd_itype;
};
typedef struct irtd : public irtd_ods10 {
float irtd_selectivity;
} IRTD;