Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Fix smart search sql error #44778

Open
wants to merge 2 commits into
base: 5.3-dev
Choose a base branch
from

Conversation

joomdonation
Copy link
Contributor

@joomdonation joomdonation commented Jan 25, 2025

Pull Request for Issue # .

Summary of Changes

There is an SQL error in smart search which only happens in certain database version. In the test site which I helped a user, it is 10.6.15-MariaDB. The reason is because alias is not allowed in DELETE statements when deleting from a single table.

Update by richard67: It seems to apply also to later versions of MariaDB, e.g. 10.11.7, and it needs some orphan nodes in the finder taxonomy table to run into it.

Testing Instructions

  • Use Joomla 5.3.0-alpha2 or 5.3.0-alpha3 or a current 5.3 nightly build or a current 5.3-dev branch.
  • Edit an article, save it

Actual result BEFORE applying this Pull Request

With certain database version, there is an error displayed, article is not saved properly. You might not see this error yourself because as mentioned, the error only happens with certain database version

Expected result AFTER applying this Pull Request

No error while saving article. So in your test, just please make sure article can be saved without any error.

Link to documentations

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

@richard67
Copy link
Member

In can confirm that it's a bug specific for 5.3-dev which was introduced with 5.3.0-alpha2. 5.3.0-alpha1 and 5.2-dev are ok.

@richard67
Copy link
Member

By review I can confirm that this PR is right, the table alias is not needed in the DELETE statement, and whereIn can be used here.

@richard67
Copy link
Member

I think the bug is severe enough to set the "Release Blocker" label.

@web-eau-net
Copy link

Test OK article can be saved now.

@web-eau-net
Copy link

I have tested this item ✅ successfully on 287e679

Test OK article can be saved now.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/44778.

@richard67
Copy link
Member

richard67 commented Jan 25, 2025

Unfortunately I cannot reproduce the issue, not with MySQL 8.0 nor PostgreSQL nor MariaDB 10.11.

As the error is in the removeOrphanNodes method of the Taxonomy, it might need some orphan node for the error happening. @Hackwar Do you know how to produce some taxonomy orphan nodes in com_finder?

@Hackwar
Copy link
Member

Hackwar commented Jan 25, 2025

The simplest solution would be to delete a row from the #__finder_links table and then to run the maintenance task from the Index view. The link entry should of course have a taxonomy related to it and be the only entry which has this taxonomy. For example an article in a category and this would be the only article in that category.

@richard67
Copy link
Member

richard67 commented Jan 26, 2025

Meanwhile I've tested the DELETE statement as it is without this PR for some not existing IDs in phpMyAdmin and for Postgres in phpPgAdmin:

DELETE FROM `#__finder_taxonomy` AS `t` WHERE `t`.`id` IN (97,98,99);

(in phpPgAdmin with PostgreSQL of course with the right name quotes).

Results:

  • On MySQL 8 and PostgreSQL the statement works.
  • On MariaDB 10.11.7 and MariaDB 10.6.15 I get an SQL syntax error.

The fixed statement from this PR works on all.

@richard67
Copy link
Member

richard67 commented Jan 26, 2025

I still cannot reproduce the issue on MariaDB on a "normal" Joomla 5.3-alpha3.

The reason for that is that the first query in the removeOrphanNodes method will never return any records because of the AND m.link_id IS NULL condition in the WHERE clause.

I don't know yet since which Joomla version, but from memory I would say it's 4.0.0, there is a NOT NULL constraint on the link_id column of the #__finder_taxonomy_map.

So the only explanation which I have right now for the issue is that the site has a long update history and some old records in the #__finder_taxonomy_map table which have a NULL value for the link_id.

But anyway, regarding the SQL syntax the fix from this PR is right.

@Hackwar Am I on the right track, or am I missing something?

@alikon
Copy link
Contributor

alikon commented Jan 26, 2025

the DELETE syntax doesn't need the alias nor having it is wrong strictly sql speaking
btw, if there are some strange behaviours with some "strange" MariaDB versions this PR is correct anyway

@richard67
Copy link
Member

I have tested this item ✅ successfully on 287e679

I was able to reproduce the issue with MariaDB 10.11.7, but only with some kind of a hack.

I have created a new category and a new article so that article was the only one in that category.

Then I have investigated the record in the #__finder_taxonomy_map table which belongs to that article and have deleted that record, so that the following SQL statement returned one record as result:

SELECT `t`.`id`
  FROM `#__finder_taxonomy` AS `t`
  LEFT JOIN `#__finder_taxonomy_map` AS `m` ON `m`.`node_id` = `t`.`id`
 WHERE `t`.`parent_id` > 1
   AND `t`.`lft` + 1 = `t`.`rgt`
   AND `m`.`link_id` IS NULL;

Then I have tried to change and save any other article.

Without this PR it failed as described.

With this PR it succeeded. After that, the above query did not return any result, and Smart Search indexing and index optimization still work.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/44778.

@richard67
Copy link
Member

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/44778.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jan 26, 2025
@richard67 richard67 added this to the Joomla! 5.3.0 milestone Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug PR-5.3-dev Release Blocker RTC This Pull Request is Ready To Commit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants