
Most editorial assets here are drafts. An index restricted to live rows can reduce the working set for the public listing while leaving the user-facing lookup logically simple. Each row names an asset at one folder location. A repeated basename does not establish identical bytes. The size is an integer estimate in KiB; a null means the size has yet to be measured.
Set up an in-memory example
The fixture uses a fresh SQLite database. Its small size allows the result to be checked by hand before the query is applied to an export with thousands of rows. The unit of observation matters here because a query can execute cleanly and still answer a different editorial or operational question.
CREATE TABLE assets (
id INTEGER PRIMARY KEY,
kind TEXT,
folder TEXT,
name TEXT,
kib INTEGER,
live INTEGER
);
INSERT INTO assets VALUES
(1, 'image', 'issue-1', 'cover.jpg', 120, 1),
(2, 'text', 'issue-1', 'intro.txt', 4, 1),
(3, 'image', 'issue-2', 'cover.webp', 80, 0),
(4, 'audio', 'issue-2', 'theme.ogg', 300, 1),
(5, 'text', 'issue-2', 'notes.md', NULL, 0),
(6, 'image', 'shared', 'icon.svg', 2, 1);Inspect the selected rows
SELECT folder,name
FROM assets
WHERE live=1 AND folder='issue-1'
ORDER BY name;| folder | name |
|---|---|
| issue-1 | cover.jpg |
| issue-1 | intro.txt |
For a representative copy, compare EXPLAIN QUERY PLAN before and after CREATE INDEX live_folder ON assets(folder,name) WHERE live=1. Tiny fixture timings are uninformative.
What changes with one more record?
Append this single row to the same fixture and rerun the query. Its named fields are id = 7, kind = audio, folder = issue-3, name = theme.ogg, kib = 300, live = 0. Keep the other rows intact so a comparison isolates the effect of this one insert.
INSERT INTO assets VALUES (7, 'audio', 'issue-3', 'theme.ogg', 300, 0);The original query returned 2 rows. After the insert it returns 2. Every output row remains the same. The extra record is a useful negative test because adding data to the table has not changed the reported observation. 2 earlier output rows still appear unchanged.
Before exporting the result, document what one displayed row represents and which fields decide its order. Look for the same shape of input in an anonymized sample from the application. A query validated only against an empty development database cannot show what happens when a record is missing, repeated or tied with another record.
SQLite reference for partial index · SQLite SQL syntax reference
Sources and further reading
Cover photograph: FSC Primergy TX200 S2 0012 by Mixabest. Public domain. Cropped and typeset for this cover. The photograph illustrates the topic.
