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

Make join table sort stable #13025

Closed

Conversation

c960657
Copy link
Contributor

@c960657 c960657 commented May 31, 2018

As discussed in #12778, the table sort in Piwik\DataAccess\LogQueryBuilder\JoinGenerator should be stable for more reliable testing.

In case the order of two joins is irrelevant, they are now sorted by the table alias which should be unique. This makes the sorting identical in PHP 5 and PHP 7.

@sgiehl sgiehl added c: Tests & QA For issues related to automated tests or making it easier to QA & test issues. Needs Review PRs that need a code review labels May 31, 2018
@sgiehl sgiehl added this to the 3.6.0 milestone May 31, 2018
@diosmosis
Copy link
Member

Looks like some other tests need to be updated.

'tableAlias' => 'log_action_idaction_name',
'joinOn' => 'log_link_visit_action.idaction_name = log_action_idaction_name.idaction',
'tableAlias' => 'log_action_visit_exit_idaction_name',
'joinOn' => 'log_visit.visit_exit_idaction_name = log_action_visit_exit_idaction_name.idaction',
Copy link
Member

Choose a reason for hiding this comment

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

FYI: This test is actually slightly buggy because the query would never work as it references a log_visit table which is never added. I presume it needs to be log_link_visit_action instead.

@c960657 c960657 force-pushed the join-generator-stable-sort branch from dbd0801 to 9439a17 Compare June 1, 2018 06:52
@sgiehl
Copy link
Member

sgiehl commented Jun 11, 2018

Still some failures in integration tests. Seems the join generator results in an invalid query?

@c960657
Copy link
Contributor Author

c960657 commented Jun 11, 2018

I realised that using uasort() and friends will simply not work. The problem is that these functions assume transitivity, i.e. if the callback reports that A < B and B < C (i.e. A depends on B, and B depends on C), then it should also report that A < C, but it doesn't.

I think we need to implement a topological sort.

@diosmosis diosmosis modified the milestones: 3.6.0, 3.7.0 Jul 24, 2018
@mattab mattab modified the milestones: 3.7.0, 3.6.1 Sep 1, 2018
@@ -286,15 +286,15 @@ public function sortTablesForJoin($tA, $tB)
$tBName = $tB['table'];
}

if ($tBName && isset($tA['joinOn']) && strpos($tA['joinOn'], $tBName) !== false) {
if ($tBName && isset($tA['joinOn']) && strpos($tA['joinOn'] . '.', $tBName) !== false) {
Copy link
Member

Choose a reason for hiding this comment

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

is this dot . needed?

Copy link
Member

Choose a reason for hiding this comment

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

is this in case there is like a table log_action and log_action_foo maybe?

@sgiehl
Copy link
Member

sgiehl commented Oct 30, 2018

closing in favor of #13634

@sgiehl sgiehl closed this Oct 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Tests & QA For issues related to automated tests or making it easier to QA & test issues. Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants