|
1 | 1 | /*
|
2 |
| - Copyright (c) 2024, MariaDB plc |
| 2 | + Copyright (c) 2024, 2025, MariaDB plc |
3 | 3 |
|
4 | 4 | This program is free software; you can redistribute it and/or modify
|
5 | 5 | it under the terms of the GNU General Public License as published by
|
@@ -753,6 +753,8 @@ MHNSW_Share *MHNSW_Share::get_from_share(TABLE_SHARE *share, TABLE *table)
|
753 | 753 | }
|
754 | 754 | if (ctx)
|
755 | 755 | ctx->refcnt++;
|
| 756 | + if (table) // hijack TABLE::used_stat_records |
| 757 | + table->hlindex->used_stat_records= ctx->node_cache.size(); |
756 | 758 | share->unlock_share();
|
757 | 759 | return ctx;
|
758 | 760 | }
|
@@ -1144,8 +1146,9 @@ static int search_layer(MHNSW_Share *ctx, TABLE *graph, const FVector *target,
|
1144 | 1146 |
|
1145 | 1147 | // WARNING! heuristic here
|
1146 | 1148 | const double est_heuristic= 8 * std::sqrt(ctx->max_neighbors(layer));
|
1147 |
| - const uint est_size= static_cast<uint>(est_heuristic * std::pow(ef, ctx->ef_power)); |
1148 |
| - VisitedSet visited(root, target, est_size); |
| 1149 | + double est_size= est_heuristic * std::pow(ef, ctx->ef_power); |
| 1150 | + set_if_smaller(est_size, graph->used_stat_records/1.3); |
| 1151 | + VisitedSet visited(root, target, static_cast<uint>(est_size)); |
1149 | 1152 |
|
1150 | 1153 | candidates.init(max_ef, false, Visited::cmp);
|
1151 | 1154 | best.init(ef, true, Visited::cmp);
|
@@ -1213,9 +1216,9 @@ static int search_layer(MHNSW_Share *ctx, TABLE *graph, const FVector *target,
|
1213 | 1216 | }
|
1214 | 1217 | }
|
1215 | 1218 | set_if_bigger(ctx->diameter, max_distance); // not atomic, but it's ok
|
1216 |
| - if (ef > 1 && visited.count*2 > est_size) |
| 1219 | + if (ef > 1 && visited.count > est_size) |
1217 | 1220 | {
|
1218 |
| - double ef_power= std::log(visited.count*2/est_heuristic) / std::log(ef); |
| 1221 | + double ef_power= std::log(visited.count/est_heuristic) / std::log(ef); |
1219 | 1222 | set_if_bigger(ctx->ef_power, ef_power); // not atomic, but it's ok
|
1220 | 1223 | }
|
1221 | 1224 |
|
|
0 commit comments