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: update rows did not work #2213

Closed
wants to merge 1 commit into from

Conversation

davecramer
Copy link
Member

@davecramer davecramer commented Jul 14, 2021

if only unique keys were provided. No reason why this should not work
Previously we only retrieved the primary keys. Obviously we could have gone back and done another query for unique keys if there were no primary keys
This would be prohibitively slow. Current solution gets both primary and unique keys.
If there is a primary key we use only the primary keys and remove the unique keys from the list
Otherwise we use the unique keys. Fixes issue #2196

if only unique keys were provided. No reason why this should not work
Previously we only retrieved the primary keys. Obviously we could have gone back and done another query for unique keys if there were no primary keys
This would be prohibitively slow. Current solution gets both primary and unique keys.
If there is a primary key we use only the primary keys and remove the unique keys from the list
Otherwise we use the unique keys.
`
@davecramer
Copy link
Member Author

Thinking about this some more, unique keys allow nulls, we would also need to make sure the column has a non-null constraint on it

@sehrope
Copy link
Member

sehrope commented Jul 15, 2021

Driving this off of pg_index and including indisunique will also include unique partial indexes. I'm not sure off hand what impact that would have but I'd imagine it might break something if the condition is not met in the updated row.

@davecramer
Copy link
Member Author

I'm starting to question the sanity of using anything but primary indexes. WTF is this Oracle thing ? :)

@davecramer
Copy link
Member Author

we can exclude partial indexes, fairly easy to add that to the query. indpred is not null if it is a partial index

@sehrope
Copy link
Member

sehrope commented Jul 15, 2021

I think all those APIs are crazy. I mean there's no way to really implement this without a full fledged SQL parser in the driver to figure out what table is being referenced. If it was driven off an API that didn't involve user provided SQL as a string it'd be considerable more sane.

@chalmagr
Copy link

There is an additional problem that was pulled in after the change, which is if the table has both (primary key / unique key) then the resulting requirement becomes too broad... e.g. in a table with an id column that is the primary key and a name column (that is unique), and a data column trying to update the resultset for the query "SELECT id, data from myTable" will not allow since the count of P/UK columns is 2 and there is only 1 in the query - this should instead perform a selection of the pk/uk that matches all selected columns (PK can be considered first, so that if PK is met then no need to keep scanning) - as of now, the MetaData retrieval is returning all of them, and using the constraint name to stop processing if all columns in the PK were found in the resultSet... hopefully this makes sense :)

@davecramer
Copy link
Member Author

davecramer commented Jul 19, 2021 via email

@chalmagr
Copy link

I have made small changes to the code from tag REL42.2.23 - I am currently trying it out... need to read the guidelines for requesting a new PR. not sure what other changes are part of this issue right now or if other issues that I'm unaware of are lingering around... hopefully it will help out :) the response on the issue was quick and I really appreciate it

@davecramer
Copy link
Member Author

davecramer commented Jul 19, 2021 via email

@chalmagr
Copy link

Added comments to the PR

@davecramer davecramer closed this Sep 3, 2021
@davecramer davecramer deleted the fixupdaterows branch September 3, 2021 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants