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

fix incorrect ordering of columns in clustered indexes on sql server #826

Merged
merged 3 commits into from
Apr 15, 2015

Conversation

billschaller
Copy link
Member

When schema information is fetched from SQL server, the getListTableIndexesSQL was fetching index columns ordered by sys.index_columns.index_column_id. This was incorrect, because that column is simply a unique id for the column within the index. The column ordering information is actually in the key_ordinal column.

This PR changes SQLServerPlatform to generate a resultset ordered by key_ordinal instead of index_column_id.

This was causing schema diffs on tables with composite primary keys to try to drop and re-create the indexes every time the diff is run.

So this solves index churn in schema diffs on SQL server.

@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/DBAL-1186

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

@deeky666
Copy link
Member

deeky666 commented Apr 2, 2015

@zeroedin-bill can you please provide a failing test case here plox? \m/ thanks

@billschaller
Copy link
Member Author

@deeky666 test shows the bug with the old query, should be good to go now. All hail sql server...

$table = new Table('sqlsrv_pk_ordering');
$table->addColumn('colA', 'integer', array('notnull' => true));
$table->addColumn('colB', 'integer', array('notnull' => true));
$table->setPrimaryKey(['colB', 'colA']);
Copy link
Member

Choose a reason for hiding this comment

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

You can't use short array syntax here as we are still on PHP 5.3

Can't use short array in php < 5.4
@billschaller
Copy link
Member Author

@deeky666 Fixed, thanks :)

deeky666 added a commit that referenced this pull request Apr 15, 2015
fix incorrect ordering of columns in clustered indexes on sql server
@deeky666 deeky666 merged commit c8c5470 into doctrine:master Apr 15, 2015
@deeky666
Copy link
Member

Thanks @zeroedin-bill !

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants