MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / BTR_selectivity

Function BTR_selectivity

src/jrd/btr.cpp:2387–2589  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2385
2386
2387void BTR_selectivity(thread_db* tdbb, jrd_rel* relation, USHORT id, SelectivityList& selectivity)
2388{
2389/**************************************
2390 *
2391 * B T R _ s e l e c t i v i t y
2392 *
2393 **************************************
2394 *
2395 * Functional description
2396 * Update index selectivity on the fly.
2397 * Note that index leaf pages are walked
2398 * without visiting data pages. Thus the
2399 * effects of uncommitted transactions
2400 * will be included in the calculation.
2401 *
2402 **************************************/
2403
2404 SET_TDBB(tdbb);
2405 RelationPages* relPages = relation->getPages(tdbb);
2406 WIN window(relPages->rel_pg_space_id, -1);
2407
2408 index_root_page* root = fetch_root(tdbb, &window, relation, relPages);
2409 if (!root)
2410 return;
2411
2412 ULONG page;
2413 if (id >= root->irt_count || !(page = root->irt_rpt[id].getRoot()))
2414 {
2415 CCH_RELEASE(tdbb, &window);
2416 return;
2417 }
2418
2419 const bool descending = (root->irt_rpt[id].irt_flags & irt_descending);
2420 const ULONG segments = root->irt_rpt[id].irt_keys;
2421
2422 window.win_flags = WIN_large_scan;
2423 window.win_scans = 1;
2424 btree_page* bucket = (btree_page*) CCH_HANDOFF(tdbb, &window, page, LCK_read, pag_index);
2425
2426 // go down the left side of the index to leaf level
2427 UCHAR* pointer = bucket->btr_nodes + bucket->btr_jump_size;
2428 while (bucket->btr_level)
2429 {
2430 IndexNode pageNode;
2431 pageNode.readNode(pointer, false);
2432 bucket = (btree_page*) CCH_HANDOFF(tdbb, &window, pageNode.pageNumber, LCK_read, pag_index);
2433 pointer = bucket->btr_nodes + bucket->btr_jump_size;
2434 page = pageNode.pageNumber;
2435 }
2436
2437 FB_UINT64 nodes = 0;
2438 FB_UINT64 duplicates = 0;
2439 temporary_key key;
2440 key.key_flags = 0;
2441 key.key_length = 0;
2442 SSHORT l;
2443 bool firstNode = true;
2444

Callers 1

IDX_statisticsFunction · 0.85

Calls 15

SET_TDBBFunction · 0.85
fetch_rootFunction · 0.85
CCH_RELEASEFunction · 0.85
CCH_HANDOFFFunction · 0.85
JRD_rescheduleFunction · 0.85
CCH_HANDOFF_TAILFunction · 0.85
CCH_RELEASE_TAILFunction · 0.85
CCH_FETCHFunction · 0.85
CCH_MARKFunction · 0.85
update_selectivityFunction · 0.85
getRootMethod · 0.80
readNodeMethod · 0.80

Tested by

no test coverage detected