A
A
Andrey Surzhikov2015-10-19 12:20:15
MySQL
Andrey Surzhikov, 2015-10-19 12:20:15

What DB to choose?

Good afternoon, for the first time I come across a database with 3.5 million records.
Before that, I worked with MySQL and SQLite all the time.
I ask for help in optimizing the speed, because with simple questions everything seriously slows down.
Now there is only one table in the database:
ID (varchar 32)
4 enum fields
and about 40 TEXT type fields (now I have decided on the field lengths and converted them to VARCHAR)
Something like this:

ID 
var1 - enum
var2 - enum
var3 - enum
var4 - enum
vchar1 - varchar(200)
vchar2 - varchar(120)
vchar3 - varchar(200)
vchar4 - varchar(1200)
....
vchar40 - varchar(500)

To visualize the data, I use DataTables in Javascript-e, I pull the data from the database using PDO.
The main queries are:
1) To display data in a table (wait about 15 seconds)
SELECT id, var2, var4, vchar4, vchar5, vchar34, vchar40 
FROM tbl 
WHERE
var1="a" 
LIMIT 390, 10 
ORDER BY var2 DESC

// The table does not display all the fields from the database, but only a quarter
2) To search the table (works for a very long time)
SELECT id, var2, var4, vchar4, vchar5, vchar34, vchar40 
FROM tbl 
WHERE
var2="searchtext" 
OR var4="searchtext" 
OR vchar4 LIKE "%searchtext%" 
OR ...... 
LIMIT 390, 10 
ORDER BY var2 DESC

3) To display the data of a single line on a separate page:
SELECT * FROM tbl WHERE id="2A34SDF2fRfriow4ASF34ge135grere"

The questions are:
1. Is it possible to do it quickly with MYSQL or do I need to switch to something else (PostgreSQL?)
2. If possible on MYSQL - which engine to use, what config settings to pay attention to, how to optimize the database for faster reading
PS Speed ​​record in a DB - is not important at all.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
M
Maxim Grechushnikov, 2015-10-19
@maxyc_webber

We have a Mysql database with 40 million records. Works smart. True, there is more than one table) So it's not a matter of the database

S
shagguboy, 2015-10-19
@shagguboy

query 2 will not work quickly in this form. rewrite in full text + union all and it will fly.

O
Optimus, 2015-10-19
Pyan @marrk2

Actually, Varchar has from 1 to 255 characters, how do you have 1200 and 500? yapro.ru/web-master/mysql/tipi-poley-v-mysql.html
And full-text, at least in mysql, there is only full-text fields where there is a fulltext index, i.e. by varchar no

A
Alexander, 2015-10-19
@drunking

Normalize the database before it's too late , sort out the data types (the ID field with the varchar type confuses me a lot, of course I don't know in what format the record identifiers are stored there, but still), then create indexes on the fields that are most often used in predicates and everything will be fine.

A
Aleksey Ratnikov, 2015-10-19
@mahoho

OR vchar4 LIKE "%searchtext%"

That's why it's running for a long time - the wildcard '%' at the beginning of the LIKE argument prevents the index from being used. Try searching for this field in a different way, such as a full-text index. Also, indexes don't work for searching on an enum field due to storage specifics ( dev.mysql.com/doc/refman/5.6/en/enum.html). Try instead of enum to make regular text fields with regular indexes - this will increase the amount of storage, but will significantly speed up SELECTs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question