| 2385 | |
| 2386 | |
| 2387 | void 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 |
no test coverage detected