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

Improvement #8161 : Cardinality estimation should use primary record versions only

This commit is contained in:
Vlad Khorsun 2024-06-18 20:10:06 +03:00
parent cee5712085
commit a39c3554b2

View File

@ -245,28 +245,31 @@ double DPM_cardinality(thread_db* tdbb, jrd_rel* relation, const Format* format)
ULONG recordCount = 0, recordLength = 0; ULONG recordCount = 0, recordLength = 0;
const RelationPages* const relPages = relation->getPages(tdbb); RelationPages* const relPages = relation->getPages(tdbb);
const vcl* const vector = relPages->rel_pages; if (relPages->rel_pages)
if (vector)
{ {
WIN window(relPages->rel_pg_space_id, (*vector)[0]); bool done = false;
for (ULONG sequence = 0; !done; sequence++)
{
WIN window(relPages->rel_pg_space_id, -1);
Ods::pointer_page* ppage = const pointer_page* ppage =
(Ods::pointer_page*) CCH_FETCH(tdbb, &window, LCK_read, pag_pointer); get_pointer_page(tdbb, relation, relPages, &window, sequence, LCK_read);
if (!ppage) if (!ppage)
{ {
BUGCHECK(243); BUGCHECK(243);
// msg 243 missing pointer page in DPM_data_pages // msg 243 missing pointer page in DPM_data_pages
} }
const ULONG* page = ppage->ppg_page; const UCHAR* bits = (UCHAR*)(ppage->ppg_page + dbb->dbb_dp_per_pp);
const ULONG* const end_page = page + ppage->ppg_count; for (USHORT slot = 0; slot < ppage->ppg_count; slot++)
while (page < end_page)
{ {
if (*page) if (ppage->ppg_page[slot] &&
!PPG_DP_BIT_TEST(bits, slot, ppg_dp_secondary) &&
!PPG_DP_BIT_TEST(bits, slot, ppg_dp_empty))
{ {
Ods::data_page* dpage = Ods::data_page* dpage =
(Ods::data_page*) CCH_HANDOFF(tdbb, &window, *page, LCK_read, pag_data); (Ods::data_page*) CCH_HANDOFF(tdbb, &window, ppage->ppg_page[slot], LCK_read, pag_data);
const data_page::dpg_repeat* index = dpage->dpg_rpt; const data_page::dpg_repeat* index = dpage->dpg_rpt;
const data_page::dpg_repeat* const end = index + dpage->dpg_count; const data_page::dpg_repeat* const end = index + dpage->dpg_count;
@ -279,14 +282,15 @@ double DPM_cardinality(thread_db* tdbb, jrd_rel* relation, const Format* format)
} }
} }
if (recordCount)
break; break;
} }
page++;
} }
done = (recordCount != 0) || (ppage->ppg_header.pag_flags & ppg_eof);
CCH_RELEASE(tdbb, &window); CCH_RELEASE(tdbb, &window);
} }
}
// AB: If we have only 1 data-page then the cardinality calculation // AB: If we have only 1 data-page then the cardinality calculation
// is too imprecise to be useful, therefore rely on the record count // is too imprecise to be useful, therefore rely on the record count