8000 primary_key mismatch with sum in MySQL · Issue #24 · flyerhzm/eager_group · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

primary_key mismatch with sum in MySQL #24

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

Open
maxigs opened this issue Dec 29, 2021 · 2 comments
Open

primary_key mismatch with sum in MySQL #24

maxigs opened this issue Dec 29, 2021 · 2 comments

Comments

@maxigs
Copy link
maxigs commented Dec 29, 2021

I found a issue with MySQL (or MariaDB in my case) and using sum aggregation.

The Primary keys on the DB query seem to be returned with string primary_keys. Which then does not match the primary_key of the given record for mapping the values.

As the tests only run against sqlite this issue does not seem present. But i thought it might be interesting for someone else.

My change can be seen here: https://github.com/maxigs/eager_group/blob/master/lib/eager_group/preloader.rb#L48
(I just copied the whole class into an initializer in my rails project for now, so i could test it with real database)

@flyerhzm
Copy link
Owner

@maxigs hmmm...I didn't face such issue.
This change will break if someone use uuid as primary key

@maxigs
Copy link
Author
maxigs commented Dec 31, 2021

@flyerhzm

You are corret. I know it's not a real fix, that's why i did not create a pull-request, but still found it might be usefull for someone else facing a similar issue.

I spent a couple hours debugging, why some numbers did not add up, until i fould thataggregate_hash was returning a hash with string-keys, for a model where primary-keys are integers. So every sum was retuning zero values.
It only happend with sum not any other method. Also it only happend in a real application using MariaDB, not with the tests in the gem itself (using SQLite).
Might rather be a issue in Activerecord or even Mysql driver, not sure - unfortunately i did not have more time to dig even deeper so far.

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

No branches or pull requests

2 participants
0