-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
issues with SQL backend and Unique Constraint #26
Comments
The primary key isn't the only constraint there, |
On second look, no that is indeed an error in the schema. We should have a separate This is a backwards incompatible change though, we need to check this out with @worldveil. |
Yes, I can see that. But doesn't apply both constraints?. |
because the insert query uses "INSERT IGNORE" , all the constraint errors will be silent, not only the ones from the |
@pguridi indeed, this is a bug. Although not one that will reduce accuracy most likely. Would still be good to fix it. You should use the correct method in the ORM. |
yes. Ill add an |
The primary key on |
The change is needed because it is impossible to enter both (examples) The fix is to add an |
indeed, with the primary key in the "hash" field, the composite unique constraint |
Ah, yes I overlooked that. Is there any key/indexing configuration where we can avoid adding an |
@worldveil we could try using a composite primary key, but I'm not sure how well supported it is on older MySQL versions or when using ORMs. |
@Wessie AFAIK, SQLAlchemy supports composite foreign keys. Also sqlite supports it. "Both single column and composite (multiple column) primary keys are supported." [1] |
I'd say let's go for composite key if we can then. What would the syntax be for that? My SQL is a little rusty. If that won't work then we can add an |
Should be a simple change to this: CREATE TABLE IF NOT EXISTS `fingerprints` (
`hash` binary(10) NOT NULL,
`song_id` mediumint(8) unsigned NOT NULL,
`offset` int(10) unsigned NOT NULL,
INDEX (`hash`),
UNIQUE KEY `uniq_constraint` (`song_id`,`offset`,`hash`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1; What's odd is as @pguridi says, MySQL for me allows different |
CREATE TABLE IF NOT EXISTS `fingerprints` (
`hash` binary(10) NOT NULL,
`song_id` mediumint(8) unsigned NOT NULL,
`offset` int(10) unsigned NOT NULL,
PRIMARY KEY (`hash`, `song_id`, `offset`)
UNIQUE KEY `uniq_constraint` (`hash`, `song_id`, `offset`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; Should be the correct version, please use |
Yes good on |
I'm not sure the |
The SQL statement to retrieve hashes works on a
Thus, the minimal amount of indexes to achieve that is: CREATE TABLE IF NOT EXISTS `fingerprints` (
`hash` binary(10) NOT NULL,
`song_id` mediumint(8) unsigned NOT NULL,
`offset` int(10) unsigned NOT NULL,
INDEX (`hash`)
UNIQUE KEY `uniq_constraint` (`hash`, `song_id`, `offset`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
I'm having troubles with the Unique constraint..,or maybe I'm getting something wrong.. :S. here goes..
(talking about the plain SQL backend, not the ORM):
the schema dump looks like:
"hash" is a primary key, which means will be unique for each record regardless of the other columns. What happens is that I fingerprint 2 different files, and I get some hashes that are already in the DB but from the other file (with different offset). And because hash is unique, an IntegrityError is raised. Then, the hash of the new file is never saved.
Am I missing something?.
The text was updated successfully, but these errors were encountered: