updated submodule
Moved SegmentExpression into namespace Piwik\Segment
move logic that creates the SQL query into LogQueryBuilder class
Renamed method to have distinct name
Refactoring without changing logic, so I can understand the code
Building the inner query reusing buildSelectQuery
Added ORDER BY NULL optimisation, fixing unit tests
Refactor Live SQL into Model
Refactor Live API Visitor Profile logic in own class
Removed checkLatLong API parameter and always set the info
Visitor Profile clean code
Fix one test
Introduce new $limit parameter to the query builder, which will LIMIT all queries including inner ones - do not use when aggregating or it will sample
Added unit test for $limit parameter
Re-ordering $orderBy, $groupBy  --> $groupBy, $orderBy as it's proper order in SQL logic
Fix test
Added integration test for the model, to test the SQL query generated
ORDER BY the inner query so the order is deterministic + It uses the INDEX
Only set order by if it's set, otherwise we ORDER BY NULL
The ultimate prize and final step to close the issue: do not group by the whole set of matched rows, way too slow on huge datasets!