? ? Success

User tests: Successful: Unsuccessful:

avatar alikon
alikon
10 Mar 2019

Pull Request for Issue: save article fail on pdo postgresql

Summary of Changes

used proper UPDATE with JOIN syntax

Testing Instructions

Create an Article

Expected result

Article created

Actual result

on Postgresql you got an ERROR
Screenshot from 2019-03-10 10-46-31

avatar alikon alikon - open - 10 Mar 2019
avatar alikon alikon - change - 10 Mar 2019
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 10 Mar 2019
Category Libraries
avatar alikon alikon - change - 10 Mar 2019
Labels Added: ?
avatar alikon alikon - change - 23 Mar 2019
Title
[4.0] - SQL UPDATE with JOIN different syntax
[4.0] - Postgresql save article
avatar alikon alikon - edited - 23 Mar 2019
avatar alikon alikon - change - 23 Mar 2019
The description was changed
avatar alikon alikon - edited - 23 Mar 2019
avatar richard67
richard67 - comment - 28 Apr 2019

I have tested this item successfully on 4c65881

Was not easy to test because

  1. Had to apply PR #24747 to be able to have installation on Postgresql for the test.
  2. Patchtester does not work with Postgresql
  3. Had to apply changes of this PR manually because branch or this PR needs a rebase to current 4.0-dev.
    But at the end test has shown that this PR here corrects error as described.
    This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/24148.
avatar richard67
richard67 - comment - 28 Apr 2019

I have tested this item successfully on 4c65881

Was not easy to test because

  1. Had to apply PR #24747 to be able to have installation on Postgresql for the test.
  2. Patchtester does not work with Postgresql
  3. Had to apply changes of this PR manually because branch or this PR needs a rebase to current 4.0-dev.
    But at the end test has shown that this PR here corrects error as described.
    This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/24148.
avatar richard67 richard67 - test_item - 28 Apr 2019 - Tested successfully
avatar twister65
twister65 - comment - 28 Apr 2019

I have tested this item successfully on 4c65881


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

avatar twister65 twister65 - test_item - 28 Apr 2019 - Tested successfully
avatar twister65
twister65 - comment - 28 Apr 2019

@richard67 , I have modified patchtester to work with pgsql in J4:
com_patchtester.zip

I make a PR for the next release:
joomla-extensions/patchtester#220

avatar franz-wohlkoenig franz-wohlkoenig - change - 28 Apr 2019
Status Pending Ready to Commit
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 28 Apr 2019

Status "Ready To Commit".

avatar wilsonge
wilsonge - comment - 29 Apr 2019

This is the exact same line as in staging. Why is this an issue in J4 and not in staging :/

avatar alikon
alikon - comment - 30 Apr 2019

don't forget we use PDO postgresql in 4

avatar wilsonge
wilsonge - comment - 30 Apr 2019

This https://stackoverflow.com/questions/31740105/select-with-inner-join-using-postgresql-and-pdo suggests that PDO supports ON as a keyword. And using the second param of the join function allows specifying an ON condition. So we need to dig a bit further into this and figure out exactly where we are failing here because it must be something more specific than just an ON statement https://github.com/joomla-framework/database/blob/2.0-dev/src/DatabaseQuery.php#L1168

avatar alikon
alikon - comment - 1 May 2019

so let me clarify a bit:

the query in staging 3.x is quite different from what we have here in 4.x

this is 3.x

UPDATE tre_content
INNER JOIN (
     SELECT * FROM (
         SELECT (
             SELECT @rownum := @rownum + 1 FROM (SELECT @rownum := 0) AS r) AS new_ordering,`id` AS `pk__0`
FROM tre_content
WHERE catid = 2 AND state >= 0 AND `ordering` >= 0
ORDER BY `ordering`
) w) AS sq ON `id` = sq.`pk__0`
SET `ordering` = sq.new_ordering
WHERE catid = 2 AND state >= 0 AND `ordering` >= 0

this is 4.x before patch

UPDATE quattro_content
SET "ordering" = sq.new_ordering
FROM ( SELECT ROW_NUMBER() OVER (ORDER BY "ordering") AS new_ordering,"id" AS "pk__0"
	FROM quattro_content
	WHERE catid = 2 AND state >= 0 AND "ordering" >= 0) AS sq ON "id" = sq."pk__0"
WHERE catid = 2 AND state >= 0 AND "ordering" >= 0"

this is 4.x with patch

UPDATE quattro_content
SET "ordering" = sq.new_ordering
FROM (
SELECT ROW_NUMBER() OVER (ORDER BY "ordering") AS new_ordering,"id" AS "pk__0"
FROM quattro_content
WHERE catid = 2 AND state >= 0 AND "ordering" >= 0) AS sq 
WHERE catid = 2 AND state >= 0 AND "ordering" >= 0 AND "id" = sq."pk__0"

so the query in 4.x is using and update with join on a temporay table (look at the FROM clause) and doesn't like the ON clause instead need the AND clause

avatar wilsonge
wilsonge - comment - 2 May 2019

That seems very weird. How come in 4.x we don't have an inner join in the query at all. Given that's the command we're modifying in the code. Are you sure that's the right query?

avatar alikon
alikon - comment - 2 May 2019

pretty sure i've made my homework, but another couple of eyes checking it's always better

avatar richard67
richard67 - comment - 18 May 2019

@alikon Last bigger change on that query was PR #13505 . This is shown in the history and blame for that file on both the staging and the 4.0-dev branch. And when comparing the sql statement related code on function reorder between 4.0-dev and staging, I also see no difference, only differences to other stuff. When you checked 3.x, did you maybe check something older than 3.7?

avatar alikon
alikon - comment - 18 May 2019

from 3.x to 4.x something has changed ? .... maybe the framework ... don't know,
btw, i've already seen some strange behavior with pdo pgsql

avatar alikon alikon - change - 18 May 2019
Labels Added: ?
Removed: J4 Issue
avatar richard67
richard67 - comment - 18 May 2019

@alikon Hmm, I just see that with our PR applied, the variable $subquery will not be used anymore in that function. So either it has to be removed, or there is really something wrong.

avatar richard67
richard67 - comment - 18 May 2019

@alikon Stupid me ;-)

avatar richard67
richard67 - comment - 18 May 2019

Query in 4.0-dev without this PR, MySQL:

UPDATE j4ux0_content
INNER JOIN (
SELECT * FROM (
SELECT (SELECT @rownum := @rownum + 1 FROM (SELECT @rownum := 0) AS r) AS new_ordering,id AS pk__0
FROM j4ux0_content
WHERE catid = 2 AND state >= 0 AND ordering >= 0
ORDER BY ordering
) w) AS sq ON id = sq.pk__0
SET ordering = sq.new_ordering
WHERE catid = 2 AND state >= 0 AND ordering >= 0

Query in 4.0-dev with this PR, MySQL:

UPDATE j4ux0_content
INNER JOIN (
SELECT * FROM (
SELECT (SELECT @rownum := @rownum + 1 FROM (SELECT @rownum := 0) AS r) AS new_ordering,id AS pk__0
FROM j4ux0_content
WHERE catid = 2 AND state >= 0 AND ordering >= 0
ORDER BY ordering
) w) AS sq
SET ordering = sq.new_ordering
WHERE catid = 2 AND state >= 0 AND ordering >= 0 AND id = sq.pk__0

I will later post the same for PDO PgSQL.

Output produced with error_log($query->dump()); before the $this->_db->setQuery($query);.

avatar richard67
richard67 - comment - 18 May 2019

Query in 4.0-dev without this PR, PDO PgSQL:

UPDATE j4ux0_content
SET "ordering" = sq.new_ordering
FROM (
SELECT ROW_NUMBER() OVER (ORDER BY "ordering") AS new_ordering,"id" AS "pk__0"
FROM j4ux0_content
WHERE catid = 2 AND state >= 0 AND "ordering" >= 0) AS sq ON "id" = sq."pk__0"
WHERE catid = 2 AND state >= 0 AND "ordering" >= 0

=> It seems the join is changed to something else for PDO PgSQL, and without a join, any "ON" is a syntax error.

So the question is what removes that join. Is there something wrong with the db driver? This has to be fixed, and then this PR here might be obsolete.

avatar richard67
richard67 - comment - 18 May 2019

Also the syntax UPDATE table SET column=value FROM ( ... ) AS x ON y ... seems wrong to me. I've never heard about UPDATE ... FROM ..., I only know INSERT INTO ... SELECT FROM ....

avatar richard67
richard67 - comment - 18 May 2019

Maybe "PDO" just needs to be renamed to "PDU", "Please Don't Use". ;-)

avatar richard67
richard67 - comment - 19 May 2019

I've just checked that the queries with MySQL (PDO) are the same as with MySQLi. So the problem with the join being changed to something else appears only with PostgreSQL (PDO).

avatar twister65
twister65 - comment - 20 May 2019

You are right @richard67, there is not from with MySQL:
https://dev.mysql.com/doc/refman/8.0/en/update.html

avatar wilsonge wilsonge - change - 24 May 2019
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2019-05-24 23:06:43
Closed_By wilsonge
avatar wilsonge wilsonge - close - 24 May 2019
avatar wilsonge wilsonge - merge - 24 May 2019
avatar wilsonge
wilsonge - comment - 24 May 2019

Slightly reluctantly merging this. Still seems odd to me. But if testing proves it ok. Will do for now

Add a Comment

Login with GitHub to post a comment