Skip to content

Refactored DNS log pagination to use LIMIT and OFFSET in QueryLogsMySql (#1317)#1702

Draft
jimstrang wants to merge 4 commits intoTechnitiumSoftware:masterfrom
jimstrang:master
Draft

Refactored DNS log pagination to use LIMIT and OFFSET in QueryLogsMySql (#1317)#1702
jimstrang wants to merge 4 commits intoTechnitiumSoftware:masterfrom
jimstrang:master

Conversation

@jimstrang
Copy link

@jimstrang jimstrang commented Jan 24, 2026

This pull request refactors the log querying and pagination logic in the QueryLogsAsync method of App.cs to simplify and improve how paginated results are fetched from MySQL. The changes replace the previous row number-based pagination with a more efficient LIMIT/OFFSET approach, fix page number validation, and update how row numbers are assigned to log entries in the result set. Ref issue #1371.

Pagination and Query Logic Improvements:

  • Replaced the manual calculation of start and end row numbers with a standard SQL LIMIT and OFFSET approach for pagination, simplifying the query and improving performance. [1] [2]
  • Updated the SQL query to remove the subquery and ROW_NUMBER() usage, directly ordering by dlid and applying LIMIT/OFFSET for result pagination.

Page Number Validation:

  • Fixed page number validation to ensure pageNumber is set to 1 if a value less than 1 is provided, preventing invalid page numbers. [1] [2]

Row Number Assignment:

  • Adjusted row number assignment logic for each log entry to account for the new pagination approach and correctly increment or decrement the row number depending on the sort order. [1] [2]

Replaced the previous ROW_NUMBER()-based pagination with a simpler and more efficient approach using SQL LIMIT and OFFSET clauses. This change removes unnecessary subqueries and row number calculations, improving code clarity and query performance for paginated DNS log retrieval.
Replace database ID with a calculated row number in DnsLogEntry objects, assigning sequential numbers based on the current page and sort order. This ensures each entry reflects its position in the paginated result set rather than its database ID.
Refactored QueryLogsAsync to better handle invalid page numbers,
ensuring pageNumber is always within valid bounds. Database queries
are now only executed if there are entries to fetch, preventing
unnecessary queries and improving efficiency. Indented and grouped
parameter setup and result reading logic for clarity and correctness.
Changed pageNumber check to require values >= 1 instead of >= 0,
ensuring that page 0 cannot be used in log queries.
@laurentlbm
Copy link

This would be a great PR to merge! I recently started hosting Technitium on a low-power Orange Pi 3B using MariaDB for query logs, but the queries often took 10+ seconds or timed out.

I came to the same conclusion as you did in issue #1371 and had made similar changes to the code for my setup (https://github.com/laurentlbm/DnsServer/blob/a57741efd7b63aab51589f69c029d979f7a3b51c/Apps/QueryLogsMySqlApp/App.cs). It completely fixed my performance issues.

@jimstrang
Copy link
Author

On my to-do list to make the same (or similar) changes to the SQL Server and SQLite projects as they have the same issue. It would be best to keep them all roughly in sync

@jimstrang jimstrang marked this pull request as draft February 4, 2026 00:17
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