From 47548c058960de272472ccd3eb2e98f08e9c25a9 Mon Sep 17 00:00:00 2001 From: hackerman <3372410+aeneasr@users.noreply.github.com> Date: Thu, 10 Oct 2024 12:48:00 +0200 Subject: [PATCH] fix: unused order (#1590) We filter for `nid = ?` so there is no point in ordering by nid. Column `shard_id` is the prefix (`CONSTRAINT keto_relation_tuples_uuid_pkey PRIMARY KEY (shard_id ASC, nid ASC)`) so it should not impact the query planner. --- internal/persistence/sql/relationtuples.go | 2 +- internal/persistence/sql/traverser.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/persistence/sql/relationtuples.go b/internal/persistence/sql/relationtuples.go index f36103f57..9d82bee31 100644 --- a/internal/persistence/sql/relationtuples.go +++ b/internal/persistence/sql/relationtuples.go @@ -214,7 +214,7 @@ func (p *Persister) GetRelationTuples(ctx context.Context, query *relationtuple. } sqlQuery := p.queryWithNetwork(ctx). - Order("shard_id, nid"). + Order("shard_id"). Where("shard_id > ?", pagination.LastID). Limit(pagination.PerPage + 1) diff --git a/internal/persistence/sql/traverser.go b/internal/persistence/sql/traverser.go index 542e6f2ff..33af2402e 100644 --- a/internal/persistence/sql/traverser.go +++ b/internal/persistence/sql/traverser.go @@ -85,7 +85,7 @@ WHERE current.nid = ? AND current.object = ? AND current.relation = ? AND current.subject_id IS NULL -ORDER BY current.nid, current.shard_id +ORDER BY current.shard_id LIMIT ? `, targetSubjectSQL), append(targetSubjectArgs, t.p.NetworkID(ctx), shardID, start.Namespace, start.Object, start.Relation, limit)...,