N
N
noneim2019-12-21 21:16:22
MySQL
noneim, 2019-12-21 21:16:22

Are there range unique indexes for mysql?

Suppose the table has integer fields rmin and rmax. Is it possible to make such a unique index on them so that the ranges of values ​​in these rows do not intersect, i.e. for example, for [rmin,rmax]:
[1,100],[101,200],[3000,3000] - correct, no intersections
[1,100],[50,60] - incorrect, one range is nested within another
[1,100],[90,200] - incorrect, intersecting ranges
I.e. the task is for the database itself to control such indexes and not allow intersecting ranges.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Melnikov, 2019-12-21
@immelnikoff

MySQL 8.0.16 introduced CHECK CONSTRAINT .

D
Dimonchik, 2019-12-21
@dimonchik2013

the question is not clear, I think you are confusing table indexes with xs what application indexes
about auto-increment on several tables - in Postgre it is now possible, in Muskul xs - 10 years ago it was impossible
to filter data simply there
https://habr.com/ru/ post/166411/
there is also a complex one: you can code anything you want with storages and triggers,
you just need to correctly define what you want in terms of the table

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question