Created
January 19, 2022 22:45
-
-
Save romank0/74a49d44f637de5a9df32e690765320b to your computer and use it in GitHub Desktop.
mysql search with order by
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table t ( | |
user_id int, | |
username text, | |
surname text, | |
age int, | |
aboutme text, | |
sex bool, | |
city int | |
); | |
insert into t (user_id, username, surname, age, aboutme, sex, city) | |
WITH RECURSIVE nrows(i) AS ( | |
SELECT 1 UNION ALL | |
SELECT i + 1 FROM nrows WHERE i < 1000 | |
), seq AS ( | |
SELECT l2.i * 1000 * 1000 + h.i * 1000 + l.i AS n FROM nrows h | |
JOIN nrows l on (true) | |
JOIN nrows l2 on (true) | |
where l2.i < 6) | |
select | |
seq.n, | |
concat('user_', seq.n), | |
concat('Surname', seq.n), | |
seq.n % 10, | |
concat('Some long about text to get something ', seq.n), | |
seq.n % 2 = 0 , | |
seq.n % 10 | |
from seq; | |
create unique index t_user_id_idx on t(user_id); | |
create index t2_idx on t(city, sex, age, user_id); | |
analyze table t; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment