#36380: SQL is formatted for logging regardless of whether it will be logged -------------------------------------+------------------------------------- Reporter: Jacob Walls | Owner: Natalia | Bidart Type: Bug | Status: assigned Component: Database layer | Version: dev (models, ORM) | Severity: Release blocker | Resolution: Keywords: debug-sql | Triage Stage: Accepted format_debug_sql | Has patch: 1 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 1 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Comment (by Sage Abdullah):
Thanks for reporting this, Tim! I did notice this when I made [https://github.com/laymonage/django-sqlite-bulk-optimization my repro] for #36143. You can see that with Django's `main` branch, my `assertNumQueries` test [https://github.com/laymonage/django-sqlite-bulk- optimization/actions/runs/15422012460/job/43399341443 took more than 5 mins]. On Natalia's PR branch for this ticket, [https://github.com/laymonage/django-sqlite-bulk- optimization/actions/runs/15422012460/job/43399341468 it only took less than a second]. Here's a minimal diff to demonstrate the issue on Django's `main` branch: {{{#!diff diff --git a/tests/bulk_create/tests.py b/tests/bulk_create/tests.py index d590a292de..0c9aa65aeb 100644 --- a/tests/bulk_create/tests.py +++ b/tests/bulk_create/tests.py @@ -295,7 +295,7 @@ class BulkCreateTests(TestCase): @skipUnlessDBFeature("has_bulk_insert") def test_max_batch_size(self): - objs = [Country(name=f"Country {i}") for i in range(1000)] + objs = [Country(name=f"Country {i}") for i in range(2**12)] fields = ["name", "iso_two_letter", "description"] max_batch_size = connection.ops.bulk_batch_size(fields, objs) with self.assertNumQueries(ceil(len(objs) / max_batch_size)): }}} Using SQLite, the test took more than 18s on my machine, and less than 0.1s with Natalia's PR branch. -- Ticket URL: <https://code.djangoproject.com/ticket/36380#comment:18> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/django-updates/01070197368c3e45-14b83b1d-3b16-447a-88f8-044989a2dde1-000000%40eu-central-1.amazonses.com.