Ticket #309 (closed defect: fixed)

Opened 4 years ago

Last modified 2 years ago

Problem with the SQL query of the LoadWantedPages() function with MySQL 5.0.22.

Reported by: vincent.fretin@… Owned by: DarTar
Priority: high Milestone: 1.1.6.5
Component: database Version: 1.1.6.4
Severity: major Keywords: mysql, php5, LoadWantedPages, 1.1.7-ported
Cc: ajmh

Description

There is a problem with the SQL query of the LoadWantedPages() function with MySQL 5.0.22. With Mysql 5.0.22, it seems the field name tag from pages table has priority on the alias "wikini_links.to_tag as tag", and so the "group by" statement doesn't work as expected and so the WantedPages page give you false result.

Here is the original query:

select distinct wikka_links.to_tag as tag,count(wikka_links.from_tag) as count from wikka_links left join wikka_pages on wikka_links.to_tag = wikka_pages.tag where wikka_pages.tag is NULL group by tag order by count desc

I propose to rename the tag alias to page_tag:

select distinct wikka_links.to_tag as page_tag,count(wikka_links.from_tag) as count from wikka_links left join wikka_pages on wikka_links.to_tag = wikka_pages.tag where wikka_pages.tag is NULL group by page_tag order by count desc

And there are 3 modificiations to do in actions/wantedpages.php and one modification in IsWantedPage() function in libs/Wakka.class.php

The above changes give you good results in the WantedPages page.

Attachments

LoadWantedPages-MySQL-5.0.22.patch Download (3.4 KB) - added by vincent.fretin@… 4 years ago.
tag->page_tag, _REQUEST->_GET, uniformization/optimization
LoadWantedPages-MySQL-5.0.22-2.patch Download (3.2 KB) - added by vincent.fretin 4 years ago.
tag->page_tag, _REQUEST->_GET, uniformization/optimization (this one apply cleanly against trunk)
LoadWantedPages_LoadWantedPages2_MySQL-5.0.22.patch Download (3.4 KB) - added by Mokoshi 4 years ago.
Please apply it! (you can delete all previous patches)
Wakka.class.php Download (66.9 KB) - added by ajmh 2 years ago.
Fixed 1.1.6.4 Wakka.class.php file

Change History

  Changed 4 years ago by DarTar

  • owner changed from unassigned to DarTar
  • status changed from new to assigned

Changed 4 years ago by vincent.fretin@…

tag->page_tag, _REQUEST->_GET, uniformization/optimization

  Changed 4 years ago by vincent.fretin@…

You can delete the first patch (Wikka-1.1.6.2-LoadWantedPages-MySQL-5.0.22.patch), there is an error. LoadWantedPages-MySQL-5.0.22.patch is the good one.

  Changed 4 years ago by DarTar

done

Changed 4 years ago by vincent.fretin

tag->page_tag, _REQUEST->_GET, uniformization/optimization (this one apply cleanly against trunk)

Changed 4 years ago by Mokoshi

Please apply it! (you can delete all previous patches)

follow-up: ↓ 5   Changed 3 years ago by DarTar

  • status changed from assigned to closed
  • resolution set to fixed

[410] applies the patch to trunk, thanks!

in reply to: ↑ 4   Changed 3 years ago by BaxilDragon

Just as a heads-up, I applied this patch to my 1.1.6.2 installation, and while it fixed the listed problem, it left the backlinks action broken. I think the "tag" needs to be changed to "page_tag" in that action as well.

  Changed 3 years ago by BaxilDragon

... Never mind; I made an error while applying the patch.

follow-up: ↓ 8   Changed 2 years ago by ajmh

  • status changed from closed to reopened
  • resolution fixed deleted

This problem is still present in the 1.1.6.4 code base. I would recommend changing the SQL to reference the actual table and column which is being grouped by explicitly to avoid any future issues with implicit column aliasing (rather than chasing changed aliases around the rest of the code base).

Line 710 in Wakka.class.php could be changed to the following:

function LoadWantedPages() { return $this->LoadAll("select distinct ".$this->configtable_prefix?."links.to_tag as tag,count(".$this->configtable_prefix?."links.from_tag) as count from ".$this->configtable_prefix?."links left join ".$this->configtable_prefix?."pages on ".$this->configtable_prefix?."links.to_tag = ".$this->configtable_prefix?."pages.tag where ".$this->configtable_prefix?."pages.tag is NULL group by ".$this->configtable_prefix?."links.to_tag order by count desc"); }

Changed 2 years ago by ajmh

Fixed 1.1.6.4 Wakka.class.php file

in reply to: ↑ 7 ; follow-up: ↓ 9   Changed 2 years ago by ajmh

Replying to ajmh:

Sorry - form garbled my output. I've attached a complete copy of a patched version of the Wakka.class.php library file from the 1.1.6.4 distribution.

in reply to: ↑ 8   Changed 2 years ago by ajmh

Replying to ajmh:

After having a look at the trunk the SQL is still using the aliased column name (rev 1071, line 1717).

  Changed 2 years ago by NilsLindenberg

  • keywords mysql, php5, LoadWantedPages added
  • version changed from 1.1.6.2 to 1.1.6.4
  • milestone changed from 1.1.7 to 1.1.6.5

Moving to 1.1.6.5

  Changed 2 years ago by DotMG

  • keywords LoadWantedPages, 1.1.7-unported added; LoadWantedPages removed

  Changed 2 years ago by DarTar

  • cc ajmh added

  Changed 2 years ago by DarTar

  • status changed from reopened to closed
  • resolution set to fixed

(In [1143]) Replace alias with actual column name in LoadWantedPages(), thanks ajmh for the patch, fixes #309

  Changed 2 years ago by DarTar

Before marking this as 1.1.7-ported, can someone please explain the rationale for two separate methods (LoadWantedPages() and LoadWantedPages2()) in trunk? Shouldn't we just have a backward-compatible LoadWantedPages() extended with the new parameters?

  Changed 2 years ago by DotMG

  • keywords 1.1.7-ported added; 1.1.7-unported removed

My code! We can remove the actual code for LoadWantedPages() and rename LoadWantedPages2() as LoadWantedPages().

See #776

  Changed 2 years ago by DarTar

agreed, provided the parameter list is backward-compatible.

Note: See TracTickets for help on using tickets.