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

Failing test for an ORDER BY that is INNER JOINed in a subquery #1267

Closed

Conversation

austinsmorris
Copy link
Contributor

A failing test case to demonstrate a problem with #1220.

cc: @Ocramius @zeroedin-bill, @mvrhov, @stof, @brianium, @mrkrstphr

@doctrinebot
Copy link

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DDC-3519

We use Jira to track the state of pull requests and the versions they got
included in.

@billschaller
Copy link
Member

Thanks - I will take a look at this.

@stof
Copy link
Member

stof commented Jan 19, 2015

IMO, we should not only have SQL generation tests for the pagination (because nothing tells us that the asserted SQL is the right one). We should have functional tests for the pagination, ensuring that the queries are working when running them in the DB. What do you think @Ocramius @deeky666 ?

@billschaller
Copy link
Member

@Ocramius @stof I'm not entirely sure how best to fix this. I think if an orderBy clause references an identifier for a joined table, the simple solution would be to also ensure that the query is fetch joining it. But that could have performance implications.

The alternative I think would be to add any orderBy expressions not matched in the select list as hidden aliased columns... But I am not sure how best to approach that either.

Thoughts?

// current output is:
// SELECT DISTINCT id_0, a1_.name FROM (SELECT b0_.id AS id_0, b0_.author_id AS author_id_1, b0_.category_id AS category_id_2 FROM BlogPost b0_ INNER JOIN Author a1_ ON b0_.author_id = a1_.id) dctrn_result ORDER BY a1_.name ASC
//
// The problem is a1_.name is not output from the subquery, so it cannot be included in the ORDER BY clause.
Copy link
Member

Choose a reason for hiding this comment

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

Did you pin down which bit strips a1_.name?

Copy link
Member

Choose a reason for hiding this comment

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

a1_.name is not being output in the select list when LimitSubqueryOutputWalker calls $innerSql = parent::walkSelectStatement($AST);

So either it would need to be added to the select clause in the AST somehow, or it would have to be inserted after the AST is materialized to SQL.

@deeky666
Copy link
Member

@stof agree. Functional tests around ordering make totally sense IMO as it gives us more safety that the rather complex SQL also works in the end. 👍

@brianium
Copy link

@stof @deeky666 I think the functional tests are a great idea. We can see from the generated SQL that it won't work, but it was our DB crying at @austinsmorris and myself that tipped us off to the problem in the first place.

@billschaller
Copy link
Member

@stof @deeky666 @brianium Yes, functional tests would especially help highlight issues on platforms that have unhappy ORDER/LIMIT situations. Cough SQLServer cough

@mrkrstphr
Copy link
Contributor

Can we revert the original PR that caused this in the meantime? Usage in MySQL and maybe PostgreSQL + Oracle is now broke for a change that was meant to fix SQL Server. I'm sure SQL Server has a pretty small market share of Doctrine usage.

@Ocramius
Copy link
Member

Agreed with that.

Please clean up the test code and open a new PR with the actual "final"
result after this is fixed (may change the test or introduce a new one).

If you want, you can include the merge revert commit yourself: otherwise
I'll do it while merging this one.

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/

On 20 January 2015 at 16:21, Kristopher Wilson notifications@github.com
wrote:

Can we revert the original PR that caused this in the meantime? Usage in
MySQL and maybe PostgreSQL + Oracle is now broke for a change that was
meant to fix SQL Server. I'm sure SQL Server has a pretty small market
share of Doctrine usage.


Reply to this email directly or view it on GitHub
#1267 (comment).

@austinsmorris
Copy link
Contributor Author

@Ocramius, test is cleaned up. It should pass once #1220 is reverted.

Thanks!

@Ocramius
Copy link
Member

Moved to #1283 - please review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants