Skip to content

Speed up query in paused loop.#573

Closed
rspier wants to merge 1 commit intoandk:masterfrom
rspier:dverified_index
Closed

Speed up query in paused loop.#573
rspier wants to merge 1 commit intoandk:masterfrom
rspier:dverified_index

Conversation

@rspier
Copy link
Copy Markdown
Collaborator

@rspier rspier commented Apr 12, 2026

  • Add an index on dverified.
  • Stop doing explicit conversion from str to int (dverified + 0)
  • dverified will always be a 10 digit unix timestamp, so string comparison results in the same as numeric.
  • Query goes from ~30 sec to ~5

(Alternative considered was adding a virtual dverified_num column, but that's a lot more invasive.)

- Add an index on dverified.
- Stop doing explicit conversion from str to int (dverified + 0)
- dverified will always be a 10 digit unix timestamp, so string comparison
  results in the same as numeric.
- Query goes from ~30 sec to ~5

(Alternative considered was adding a virtual dverified_num column, but
that's a lot more invasive.)
@andk
Copy link
Copy Markdown
Owner

andk commented Apr 12, 2026

The reason why we are using the +0 are all the dates in the table with 9 digits.

MariaDB [mod]> with cte as ( select dverified+0>1000000000 dv from uris ) select dv, count(*) cnt from cte group by dv;
+----+--------+
| dv | cnt    |
+----+--------+
|  0 |  15189 |
|  1 | 395436 |
+----+--------+
2 rows in set (3.509 sec)
MariaDB [mod]> select max(dverified) from uris where dverified > '1775030167' ;
+----------------+
| max(dverified) |
+----------------+
| 999996699      |
+----------------+
1 row in set (0.001 sec)

MariaDB [mod]> select max(dverified) from uris where dverified+0 > '1775030167' ;
+----------------+
| max(dverified) |
+----------------+
| 1776028378     |
+----------------+
1 row in set (0.915 sec)

Did you consider that?

@rspier
Copy link
Copy Markdown
Collaborator Author

rspier commented Apr 12, 2026

Totally missed that. I'll consider re-spinning this as a virtual column, but not sure when I'm going to get to it. It almost might complicate the SQLite fallback. Really, this column should be an INT.

@rspier rspier closed this Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants