From 9730b3aa52d3c347e27cd4533650212e99c6295e Mon Sep 17 00:00:00 2001 From: Alp Date: Tue, 24 Mar 2026 19:46:36 +1100 Subject: [PATCH] query: use actual table id for IsA matches in fixed traversal --- distr/flecs.c | 18 ++++++++++++++---- src/query/engine/eval_trav.c | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/distr/flecs.c b/distr/flecs.c index 83c49adbe9..770ef353ba 100644 --- a/distr/flecs.c +++ b/distr/flecs.c @@ -85789,10 +85789,10 @@ bool flecs_query_trav_fixed_src_up_fixed_second( /* Check if table has transitive relationship by traversing upwards */ ecs_table_record_t *tr = NULL; - ecs_search_relation(ctx->world, table, 0, - ecs_pair(trav, second), trav, EcsSelf|EcsUp, NULL, NULL, &tr); + const int32_t column = ecs_search_relation(ctx->world, table, 0, + ecs_pair(trav, second), trav, EcsSelf| EcsUp, NULL, NULL, &tr); - if (!tr) { + if (column == -1 || !tr) { if (op->match_flags & EcsTermReflexive) { return flecs_query_trav_fixed_src_reflexive(op, ctx, &range, trav, second); @@ -85801,7 +85801,17 @@ bool flecs_query_trav_fixed_src_up_fixed_second( } } - flecs_query_set_trav_match(op, tr, trav, second, ctx); + ecs_id_t matched = ecs_pair(trav, second); + if (trav == EcsIsA) { + matched = table->type.array[column]; + } + + if (op->field_index != -1) { + ecs_iter_t *it = ctx->it; + it->ids [op->field_index] = matched; + flecs_query_it_set_tr(it, op->field_index, tr); + } + flecs_query_set_vars(op, matched, ctx); return true; } diff --git a/src/query/engine/eval_trav.c b/src/query/engine/eval_trav.c index 00177c982f..f5166d305e 100644 --- a/src/query/engine/eval_trav.c +++ b/src/query/engine/eval_trav.c @@ -96,10 +96,10 @@ bool flecs_query_trav_fixed_src_up_fixed_second( /* Check if table has transitive relationship by traversing upwards */ ecs_table_record_t *tr = NULL; - ecs_search_relation(ctx->world, table, 0, - ecs_pair(trav, second), trav, EcsSelf|EcsUp, NULL, NULL, &tr); + const int32_t column = ecs_search_relation(ctx->world, table, 0, + ecs_pair(trav, second), trav, EcsSelf| EcsUp, NULL, NULL, &tr); - if (!tr) { + if (column == -1 || !tr) { if (op->match_flags & EcsTermReflexive) { return flecs_query_trav_fixed_src_reflexive(op, ctx, &range, trav, second); @@ -108,7 +108,17 @@ bool flecs_query_trav_fixed_src_up_fixed_second( } } - flecs_query_set_trav_match(op, tr, trav, second, ctx); + ecs_id_t matched = ecs_pair(trav, second); + if (trav == EcsIsA) { + matched = table->type.array[column]; + } + + if (op->field_index != -1) { + ecs_iter_t *it = ctx->it; + it->ids [op->field_index] = matched; + flecs_query_it_set_tr(it, op->field_index, tr); + } + flecs_query_set_vars(op, matched, ctx); return true; }