CRUD icon indicating copy to clipboard operation
CRUD copied to clipboard

[Bug] Large increase in amount of executed queries

Open jnoordsij opened this issue 1 year ago • 1 comments

Bug report

What I did

In my recent Sentry reports, I found several N+1 query issue reports on various different admin panel pages. Looking into them, I noticed that on basically all pages visited, for each table available in my database, there are two queries being fired (regardless of page content):

select column_name as `name`, data_type as `type_name`, column_type as `type`,
                      collation_name as `collation`, is_nullable as `nullable`,
                                        column_default as `default`, column_comment as `comment`,
                                        generation_expression as `expression`, extra as `extra`
from information_schema.columns
where table_schema = 'FOO'
  and table_name = 'BAR'
order by ordinal_position asc
select index_name as `name`, group_concat(column_name order by seq_in_index) as `columns`,
       index_type as `type`, not non_unique as `unique`
from information_schema.statistics
where table_schema = 'FOO'
  and table_name = 'BAR'
group by index_name, index_type, non_unique

What I expected to happen

No obsolete queries being fired.

What happened

A lot of queries fetching data that seems largely obsolete.

What I've already tried to fix it

My observations and thoughts:

  • this only started appearing recently; I suspect the Laravel 11 upgrade for my application is involved
  • given the origin of the calls and the large refactorings in https://github.com/Laravel-Backpack/CRUD/pull/5457, I suspect the issue might originate there
  • the bug is not present when I checkout an old tag running on Laravel 10.48.3 + Backpack CRUD 6.7.0

Given that I'm not immediately sure about the moving parts involved, I've decided to stick with reporting this for now. If more info/help is needed, let me know, then I'll happily assist in tracking down the source of this issue.

Is it a bug in the latest version of Backpack?

Yes

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

### PHP VERSION:
8.3.6

### PHP EXTENSIONS:
Core, bcmath, calendar, ctype, date, filter, hash, iconv, json, SPL, pcre, random, readline, Reflection, session, standard, mysqlnd, tokenizer, zlib, libxml, dom, PDO, openssl, SimpleXML, xml, xmlreader, xmlwriter, curl, FFI, ftp, fileinfo, gd, gmp, intl, mbstring, exif
, mysqli, Phar, pdo_mysql, pdo_sqlite, xsl, zip, xdebug, Zend OPcache

### LARAVEL VERSION:
11.3.1.0

### BACKPACK PACKAGE VERSIONS:
backpack/basset: 1.3.1
backpack/crud: 6.7.11
backpack/filemanager: 3.0.7
backpack/pro: 2.1.12
backpack/theme-tabler: 1.2.8

Further info: running this on MySQL databases, both 8.0.x and 8.4.0.

jnoordsij avatar May 03 '24 15:05 jnoordsij

Hey @jnoordsij thanks for the heads up. 🙏

I am already working on the fix for that here: https://github.com/Laravel-Backpack/CRUD/pull/5504

I will bump that PR priority.

Cheers

pxpm avatar May 06 '24 08:05 pxpm

Fixed by #5504.

jnoordsij avatar May 07 '24 08:05 jnoordsij