// sqlite · query planner

reverse_unordered_selects

Make SELECTs without ORDER BY return rows in the opposite of their usual order.

Par défaut
0 (off)
Range
0, 1
Restart needed
Non
Default checked on
SQLite 3.5x

Ce que cela fait

A debugging switch. If an application breaks with it on, that query was assuming a row order it never asked for. It works for most SELECT statements, but the planner sometimes picks an algorithm it cannot easily reverse, and then the output order stays as before.

Valeur par défaut

0 (off). Off (a stock SQLite 3.5x build).

Check the current value

PRAGMA reverse_unordered_selects;

SELECT * FROM pragma_reverse_unordered_selects;   -- table-valued form, usable in queries

Change it

PRAGMA reverse_unordered_selects = ON;   -- this connection only

No restart. It applies at once to the connection that runs it and is lost when that connection closes, so set it every time a connection opens.

When to change it

In tests and staging before a release, to flush out queries that lean on natural row order before a schema change or an upgraded build exposes the assumption in production.

What can go wrong

Even with it on, some queries keep their normal order because the planner chose an algorithm that cannot reverse, so a clean run does not prove the application is free of missing ORDER BY clauses; expect reversed results, not an error.

Questions about reverse_unordered_selects

What is the default value of reverse_unordered_selects in SQLite?

0 (off). Off (a stock SQLite 3.5x build).

Does changing reverse_unordered_selects require a restart?

No. No restart. It applies at once to the connection that runs it and is lost when that connection closes, so set it every time a connection opens.

When should I change reverse_unordered_selects?

In tests and staging before a release, to flush out queries that lean on natural row order before a schema change or an upgraded build exposes the assumption in production.

Back to all SQLite settings, or check the SQLite manual for every option.

// one client for every engine

Check reverse_unordered_selects on your own server

SQLly runs the query above against SQLite and the other engines in this reference, from one desktop app on macOS, Windows and Linux.

Texte et données de cette page : CC BY 4.0, en citant SQLly (sqlly.app). Code et extraits SQL : MIT. Détails de la licence