0

I am currently using the Django shell in debugging mode in order to benchmark my queries.

This is an example of what I get:

>>> Item.objects.filter(param1=63)
(0.001) SELECT `items`.`id`, `items`.`param1`, `items`.`param2`, FROM `items` WHERE `items`.`param1` = 63; args=(63,)

Most of the results I am getting lay in the order of a millisecond, so I was wondering: is it possible to increase the query precision say, one or two orders of magnitude in order to tell them apart?

I am using MariaDB as a database.

mariadb --version
mariadb  Ver 15.1 Distrib 10.4.11-MariaDB, for Linux (x86_64) using readline 5.1

Thank you in advance.

Regards.

Atenea_v10
  • 87
  • 1
  • 8
  • 1
    Usually an application scales more with the *number* of queries than the delay of a query. In order to make a query, Django needs to convert the `QuerySet` to a query, send the query to the database, the database should read the query, evaluate it, and return the result back, and then Django needs to "parse" the data into objects, so for (quite) simple queries, it is normal that they all have very similar delays, therefore one better aims to *minimize* the *number* of queries. – Willem Van Onsem Jul 26 '21 at 09:35
  • @WillemVanOnsem Thanks for your response. I am trying to quantify the benefits of using [select_related()](https://docs.djangoproject.com/en/3.2/ref/models/querysets/#select-related) in my queries. Some of them go before a _for_ loop and hence my question. Each iteration gets a 0.001 seconds and I suppose Django is rounding it somehow. – Atenea_v10 Jul 26 '21 at 10:45
  • 1
    you should avoid querying in a `for` loop, since then you have a problem that is known as the *N+1 problem*: https://scoutapm.com/blog/django-and-the-n1-queries-problem – Willem Van Onsem Jul 26 '21 at 10:49

0 Answers0