Pages: 1
I was using the batch manager to add information to some photos (tags, album links etc) in solo mode when after one save I got this error:
Warning: [mysql error 1104] The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET MAX_JOIN_SIZE=# if the SELECT is okay
SELECT
COUNT(DISTINCT(image_id))
FROM piwis3_image_category
; in /home/fellfixe/public_html/piwigo/include/dblayer/functions_mysqli.inc.php on line 847
Fatal error: Uncaught Error: Call to a member function fetch_row() on bool in /home/fellfixe/public_html/piwigo/include/dblayer/functions_mysqli.inc.php:216 Stack trace: #0 /home/fellfixe/public_html/piwigo/admin/include/functions.php(3335): pwg_db_fetch_row(false) #1 /home/fellfixe/public_html/piwigo/admin.php(304): count_orphans() #2 {main} thrown in /home/fellfixe/public_html/piwigo/include/dblayer/functions_mysqli.inc.php on line 216
Since then I can get to the Gallery but if I try to go to the Admin page or edit a photo the error message is displayed again. I've tried logging out/in again, closed/reopened my browser but the problem still occurs.
Any idea how I can clear this error?
Environment
Piwigo 15.3.0 Check for upgrade
Installed on 9 January 2025, 10 days ago
Operating system: Linux
PHP: 7.4.33
MySQL: 5.5.5-10.11.10-MariaDB-cll-lve
Graphics Library: ImageMagick ImageMagick 7.1.1-39
Cache size 91.5 Mo
Activated plugin list
Batch Downloader
Export Data
LocalFiles Editor
Manage Properties Photos
Read Metadata
Rotate Image
Tag Groups
URL Uploader
Last edited by strutha (2025-01-23 03:11:05)
Offline
Managed to fix this myself. The last thing thing I did before the crash was to add an image to album Y, remove it from album X and also add it to album Z (which I created as a new album 'on the fly' using 'creation mode' in the Add album dialog) then clicked on Save.
I suspected the error message
"The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET MAX_JOIN_SIZE=# if the SELECT is okay"
was misleading mainly because at this time there are only 525 photos (images) and 25 albums (categories) in my gallery. But even if there was some malformed SQL query embedded in the php code creating a cartesian join, 525 x 25 would still only produce 13,125 rows (if only the photos and albums tables were joined) which is diddly-squat for a MySQL database. So I don't really believe that message and unfortunately I don't know any php to go digging any deeper into other aspects of the error message.
But the reported error did at least lead me to take a look in the database to see if I could find any obvious data integrity issue. I couldn't but I decided to manually back out my last action step by step in the hope it would fix the problem and that worked at the very first step, which was to hack the image_category table to delete the record linking the photo to album Z.
Adding a photo to more than one album is supported by Piwigo so I have absolutely no idea why deleting that one image-category link should fix it.
So I'm happy I have fixed it but would still like to know the root cause. I see my original post got viewed quite a few times but nobody posted any replies. It would be really helpful if a member of the Piwigo team could post their thoughts on possible causes.
Offline
So out of curiosity I went back into the batch manager and selected a different photo to add to more than one album and got the same error. And the same fix worked.
Difficult to believe I am the only person in the Piwigo community who is adding photos to multiple albums. Can anybody else reproduce this behaviour in their gallery?
Offline
I changed the title of my original post to give a clearer description of the issue.
In the meantime I also tried adding a photo to more than one album via the Edit photo icon when viewing the photo in the gallery. This too resulted in the error message so I guess that rules out the possibility the problem is related to edits via the batch manager.
Offline
This all doesn't make much sense. As the error appears to occur with the
SELECT
COUNT(DISTINCT(image_id))
FROM piwis3_image_category
in admin/include/functions.php line 3331 while obtaining the number of orphans, how many rows does your piwis3_image_category table have and are there a lot of orphan images? And what MAX_JOIN_SIZE is actually set for your DB?
Btw, your PHP 7.4.33 is outdated legacy.
Offline
This all doesn't make much sense
I agree. The query doesn't do a JOIN. In researchinhg the error message I found this posted on another web site:
Before MySQL 8.0.31, max_join_size also applies to single-table queries: MySQL 8.0.30 and earlier: Do not permit statements that probably need to examine more than max_join_size rows (for single-table statements) or row combinations (for multiple-table statements) or that are likely to do more than max_join_size disk seeks.
But I'm not sure if that's relevant because I cannot tie up the referenced MySQL version 8.0.31 with the version I am running ( 5.5.5-10.11.10-MariaDB-cll-lve).
As of today I have only 536 records in the piwis3_images table and 539 records in the piwis3_image_category table which suggests that one or two images do in fact appear in more than one album (I need to dig a little deeper on which ones in case that gives me any clues).
There are no orphans but that said, at the moment the issue is not occuring because as mentioned in my earlier post I fixed it by deleting one of the records in the piwis3_image_category table for the photo I was editng when the problem occurred.
I can't get to it till tomorrow I will reproduce the behaviour and then check for orphans. Please post re any other diagnostics I can try.
Offline
I tried reproducing the error by using Edit photo with an image already in the gallery to add it to a second album. The error did not occur.
I uploaded 3 photos to an album I have called For Indexing and then processed them in batch manager Solo mode to move them to their final albums, except one of the images I also left in the For Indexing album. The saves of the edits were successful but when I clicked on the Dashboard the error occurred. (I happened to click on Dashboard but I know from previous occurences I could have clicked on any of the Admin menu options and the error would have occurred at that point).
Once the error occurs it is not possible to get to any of the admin pages to see if the orphaned images message is displayed, but I queried the piwis3_image_category table directly and could not find any orphans and confirmed the three photos I had uploaded were all linked to albums (including the test photo I linked to two albums).
I also used PHPMyAdmin to run the SQL query which is referenced in the error message and got the same error message.
I also ran EXPLAIN for the SQL query and got this output:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE piwis3_image_category ALL NULL NULL NULL NULL 543
which doesn't seem to show anything surprising.
I cleared the error by deleting one of the records for the test image in piwis3_image_category table. I then put a couple of other images from a different album into the caddie and went into the batch manager to 1) move one to a new album and 2) add the other to a second album. After making edit 1) I saved the change and before making edit 2) I checked in the gallery and in piwis3_image_category and was surprised to see that the image in edit 1) was still linked to its original album. I went ahead with edit 2) on the other image anyway, saved the change and once again got the error when selecting another option in the Admin menu
So to summarise:
- previously I said I got the same error via the Edit option when viewing an image in the gallery but I was not able to reproduce that in this set of tests
- I can consistently reproduce the error when using batch queue manager in Solo mode to assign an image to more than one album
- it may be unrelated but in this set of tests I observed that an edit I made and saved in the batch manager Solo moce (and for which the UI displayed a confirmation message) did not actually get saved.
The mystery deepens.
Last edited by strutha (2025-01-25 02:24:50)
Offline
Continuing my attempts to debug this issue but the problem seems to have got worse. Now I get an error directly I try to go to batch manager after uploading a set of images. Up till now the error occurred when editing data in batch manager.
Here's the current sequence of steps I followed to reproduce the error:
1. Uploaded 11 files to an album called Events
2. Clicked on "Manage this set of 11 photos" after successful upload
3. Error message displayed:
Fatal error: Uncaught mysqli_sql_exception: The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET MAX_JOIN_SIZE=# if the SELECT is okay in /home/fellfixe/public_html/piwigo/include/dblayer/functions_mysqli.inc.php:132 Stack trace: #0 /home/fellfixe/public_html/piwigo/include/dblayer/functions_mysqli.inc.php(132): mysqli->query() #1 /home/fellfixe/public_html/piwigo/admin/include/functions.php(3335): pwg_query() #2 /home/fellfixe/public_html/piwigo/admin.php(304): count_orphans() #3 {main} thrown in /home/fellfixe/public_html/piwigo/include/dblayer/functions_mysqli.inc.php on line 132
Note: this is similar to but different from the original error message and also doesn't include the offending SQL statement. The original error message was:
Warning: [mysql error 1104] The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET MAX_JOIN_SIZE=# if the SELECT is okay
SELECT
COUNT(DISTINCT(image_id))
FROM piwis3_image_category
; in /home/fellfixe/public_html/piwigo/include/dblayer/functions_mysqli.inc.php on line 847
Fatal error: Uncaught Error: Call to a member function fetch_row() on bool in /home/fellfixe/public_html/piwigo/include/dblayer/functions_mysqli.inc.php:216 Stack trace: #0 /home/fellfixe/public_html/piwigo/admin/include/functions.php(3335): pwg_db_fetch_row(false) #1 /home/fellfixe/public_html/piwigo/admin.php(304): count_orphans() #2 {main} thrown in /home/fellfixe/public_html/piwigo/include/dblayer/functions_mysqli.inc.php on line 216
(Perhaps the different message is because I upgraded my PHP version from 7.4.33 to 8.3.15 in case this was the possible cause of the error).
4. Checked in piwis3_images - all 11 images were there
5. Checked in piwis3_image_category - all 11 images were linked to only one album
6. Checked in piwis3_caddie - no rows in table (which seems strange and significant given at step 2 I opted to manage the uploaded images)
7. Checked in piwis3_tags - the keywords in the images' metadata were there
8. Deleted the 11 records added to piwis3_image_category
9. In Piwigo tab clicked on the Back button, the gallery home page was displayed, clicked on Admin - the Admin Dashboard was displayed with warning of 11 orphans in Header
10. Clicked on Photos > Orphans and chose action to move all 11 images to For Indexing album - the error recurred.
I'm almost out of ideas as to what else I can try to identify the problem. Is there any logging I can switch on and inspect to see if it gives any other clues?
Can any of the Piwigo development team familiar with the upload and batch manager code describe what should happen under the covers at each step in the above sequence to maybe give me a clue as to anything else I can check?
Offline
My latest investigation: I wondered if there was a specific photo causing the error to occur so I ran a series of batch uploads starting with just one photo, then two, then three etc.
All was OK when uploading up to 5 photos but then the error was thrown when uploading a batch of 6 photos. I looked at the 6th photo (image and metadata) but could see nothing unusual that might suggest the cause of the error.
I cleared the error and then uploaded the 6th photo as the only photo in the batch. The error did not occur and I was able to use the batch manager to move the uploaded photo from one album to another.
I cleared the error again and uploaded the same batch of 6 except replacing the 6th file with a different one. The error occurred.
So the above behaviour seems to suggest the error has nothing to do with the content or metadata of a specific file. It seems more like it is in some way related to the number of files in an upload batch. But I'm not entirely convinced of that either because at other times I have been able to successfully upload batches of more than 6 some of which did not throw the error at any point, some of which did.
I'm reporting these observations in the hope that they might trigger a thought in the mind of somebody who knows the inner workings of this part of the code. But with no solution in sight I'm getting very close to giving up on this issue and I'll just have to look for other software. That's a real shame because I really like Piwigo and was on the point of recommending it to the volunteering organisation I belong to, but I can't really do that if I can't get this diagnosed and fixed.
Offline
I was about to give up on this (and on Piwigo) but decided to do another search of the forum. Should have thought much earlier of searching for MAX_JOIN_SIZE. Doing so led me to these two topics:
https://piwigo.org/forum/viewtopic.php?id=33307 (First post in topic July 2021)
https://piwigo.org/forum/viewtopic.php?id=33820 (First post in topic August 2024)
Those posts reveal the problem appears to be with the count_orphans function called at line 304 (Piwigo 15.3.0) in admin.php. So commenting out the following lines fixed it for me:
//if ($page['nb_photos_total'] < 100000) // 100k is already a big gallery
//{
// $page['nb_orphans'] = count_orphans();
//}
Some of the above-referenced posts suggest commenting out more lines than that but not being a programmer myself I prefer to keep my amateur hacking to the bare minimum for simplicity.
So although that has fixed the problem I, and others who reported it, still have no idea what the root cause is. We all seem to have observed it occurring under completely different circumstances. Given that the problem seems to have been around for at least 3.5 years it is a little surprising that many more people haven't run into it and a fix implemented. (That's just an observation, not a complaint).
Last edited by strutha (2025-02-01 05:15:18)
Offline
Pages: 1