Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions libraries/joomla/table/table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,13 @@ public function reorder($where = '')
throw new UnexpectedValueException(sprintf('%s does not support ordering.', get_class($this)));
}

// Speedup by SQL optimalization
if ( strpos($this->_db->name, 'mysql') !== false )
{
return $this->reorderMysql($where);
}

// Default (slow) reorder
$k = $this->_tbl_key;

// Get the primary keys and ordering values for the selection.
Expand Down Expand Up @@ -1410,6 +1417,46 @@ public function reorder($where = '')
return true;
}

/**
* Method to compact the ordering values of rows in a group of rows
* defined by an SQL WHERE clause.
*
* @param string $where WHERE clause to use for limiting the selection of rows to compact the ordering values.
*
* @return mixed Boolean True on success.
*
* @link http://docs.joomla.org/JTable/reorder
* @since 11.1
*/
protected function reorderMysql($where = '')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it necessary to only patch the behavior for MySQL engines? This should probably be patched for the non-MySQL engines as well if there is a known performance issue.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's necessary to patch all engines. If you'd like to develop the solution for engines other than MySQL, you are more than welcome to. This patch has been developed over 2 years ago and is still not incorporated in Joomla, causing problems for a lot of people. Seems to me the right thing to do would be incorporating it, and then adding a solution for other engines.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepting patches that only fix behavior on MySQL while ignoring the non-MySQL engines is part of the reason why the non-MySQL support in Joomla is pure crap. And if you look throughout the code base you find plenty of "incorporate this first then improve it later" TODO style comments that years later are never addressed.

IMO database engine specific changes must include the appropriate comparable changes for other engines or should not be merged. Or just say screw it and rip out the non-MySQL support already, all 3 users of those platforms have probably smartened up and moved to a platform that actually supports their needs already.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are absolutely right, and so I suggest rejecting this patch altogether. This way not only the users of engines other than MySQL will continue to experience this bug. Hence, also MySQL users will be encouraged to find a different solution for their site. Makes perfect sense to me!

It's a patch created over 2 years ago by some good soul that shared it back then and disappeared. We are using this in production on a high-traffic site. I went the extra mile to create a pull request so that other Joomla users can take advantage of it; however, I have exactly zero time to work on adding other engines to it.

In this context, I'd like to know if I should bother fixing the tabulation and PDO support issues on it, or assume it's not going to be merged anyway and just call it a day.

Thanks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not saying abandon or reject the patch. But unless someone is going to commit to working on the same issue for other engines, I do not encourage patches that include engine specific fixes or hacks to be merged (unless those are in the database API where that's kind of how things work). The project's track record with "let's start this and finish it later" is abysmal to say the least, there are more half baked ideas in the core platform right now than truly feature complete APIs or extensions. It's how things like the abandoned UCM concept get merged.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a "let's start this and finish later" patch. It is a "optimise a thing, a lot" patch. Yes, it only optimises it for a particular engine; no, it does not degrade performance for other engines.

So the question is simple: is it okay to merge an engine-specific optimisation (needed on live systems, as apparent by the ticket comment thread), or should this patch be rejected, because it does not offer the same optimisation for all engines. If merged, a certain action will take much less time on one of the engines. If not merged, this action will take the same huge amount of time on all engines.

This is not my decision. But please, somebody make one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #8564

If accepted, merge this patch as is. It's pretty clear the platform's FUBAR anyway.

{
$k = $this->_tbl_key;

$this->_db->setQuery('set @num = 0');
$this->_db->execute();

$query = $this->_db->getQuery(true)
->update($this->_tbl)
->set('ordering = @num := @num + 1')
->where('ordering >= 0')
->order('ordering');

// Setup the extra where and ordering clause data.
if ($where)
{
$query->where($where);
}

/* Warning: Unpatched version of JDatabaseQuery->__toString ignores 'order' to update query.
* Then query must be built from string like this:
* $query = "update {$this->_tbl} set ordering = @num := @num + 1 where ordering >= 0 " . $where? (" and " . $where): "" . " order by ordering"; */

$this->_db->setQuery($query);
$this->_db->execute();

return true;
}

/**
* Method to move a row in the ordering sequence of a group of rows defined by an SQL WHERE clause.
* Negative numbers move the row up in the sequence and positive numbers move it down.
Expand Down