| 1008 | } |
| 1009 | |
| 1010 | bool Applier::lookupKey(thread_db* tdbb, jrd_rel* relation, index_desc& key) |
| 1011 | { |
| 1012 | RelationPages* const relPages = relation->getPages(tdbb); |
| 1013 | auto page = relPages->rel_index_root; |
| 1014 | if (!page) |
| 1015 | { |
| 1016 | DPM_scan_pages(tdbb); |
| 1017 | page = relPages->rel_index_root; |
| 1018 | } |
| 1019 | |
| 1020 | const PageNumber root_page(relPages->rel_pg_space_id, page); |
| 1021 | win window(root_page); |
| 1022 | const auto root = (index_root_page*) CCH_FETCH(tdbb, &window, LCK_read, pag_root); |
| 1023 | |
| 1024 | index_desc idx; |
| 1025 | idx.idx_id = key.idx_id = idx_invalid; |
| 1026 | |
| 1027 | for (USHORT i = 0; i < root->irt_count; i++) |
| 1028 | { |
| 1029 | if (BTR_description(tdbb, relation, root, &idx, i)) |
| 1030 | { |
| 1031 | if (idx.idx_flags & idx_primary) |
| 1032 | { |
| 1033 | key = idx; |
| 1034 | break; |
| 1035 | } |
| 1036 | |
| 1037 | if (idx.idx_flags & idx_unique) |
| 1038 | { |
| 1039 | if (key.idx_id == idx_invalid) |
| 1040 | key = idx; |
| 1041 | else if (relation->isSystem()) |
| 1042 | { |
| 1043 | // For unique system indices, prefer ones using metanames rather than IDs |
| 1044 | USHORT metakeys1 = 0, metakeys2 = 0; |
| 1045 | |
| 1046 | for (USHORT id = 0; id < idx.idx_count; id++) |
| 1047 | { |
| 1048 | if (idx.idx_rpt[id].idx_itype == idx_metadata) |
| 1049 | metakeys1++; |
| 1050 | } |
| 1051 | |
| 1052 | for (USHORT id = 0; id < key.idx_count; id++) |
| 1053 | { |
| 1054 | if (key.idx_rpt[id].idx_itype == idx_metadata) |
| 1055 | metakeys2++; |
| 1056 | } |
| 1057 | |
| 1058 | if (metakeys1 > metakeys2) |
| 1059 | key = idx; |
| 1060 | } |
| 1061 | else if (idx.idx_count < key.idx_count) |
| 1062 | key = idx; |
| 1063 | } |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | CCH_RELEASE(tdbb, &window); |
nothing calls this directly
no test coverage detected