Skip to content

Commit 87ef7bc

Browse files
committed
rmv order_by in queries
1 parent 391addb commit 87ef7bc

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

tools/tokenserver/database.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@
8686
""")
8787

8888

89+
# No ORDER BY: pruning is destructive and `purge_old_records.py` uses a random
90+
# offset for sharding, so stable pagination is not required. Avoiding the sort
91+
# lets this stop after LIMIT+OFFSET qualifying rows instead of
92+
# sorting the entire matching set.
8993
_GET_OLD_USER_RECORDS_FOR_SERVICE = sqltext("""\
9094
select
9195
uid, email, generation, keys_changed_at, client_state,
@@ -96,14 +100,14 @@
96100
users.service = :service
97101
and
98102
replaced_at is not null and replaced_at < :timestamp
99-
order by
100-
replaced_at desc, uid desc
101103
limit
102104
:limit
103105
offset
104106
:offset
105107
""")
106108

109+
# See note on _GET_OLD_USER_RECORDS_FOR_SERVICE for why this query intentionally
110+
# has no ORDER BY.
107111
_GET_OLD_USER_RECORDS_FOR_SERVICE_RANGE = """\
108112
select
109113
uid, email, generation, keys_changed_at, client_state,
@@ -116,8 +120,6 @@
116120
::RANGE::
117121
and
118122
replaced_at is not null and replaced_at < :timestamp
119-
order by
120-
replaced_at desc, uid desc
121123
limit
122124
:limit
123125
offset

0 commit comments

Comments
 (0)