Used: Comp: - 2.6GHz - 6.0 GB of RAM - Win 7x64

Programs:
- OpenServer
- Access - 2016
- MySql 5.7 x 64
- Odbc - mysql-connector-odbc-5.3.7-winx64

Everything is installed and used on one computer

Characteristics of the table:
- number of lines assumed - more than 1.0 million
- number of columns ~ 20 pieces

Table (tbl8)
Count lines - 12,425 lines
Volume - 24.6 MB

CREATE TABLE `tbl5` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `tbl` LONGTEXT NULL, `idsub` INT(20) NOT NULL, `pol_3` INT(11) NULL DEFAULT NULL, `pol_4` LONGTEXT NULL, `pol_5` LONGTEXT NULL, `pol_6` LONGTEXT NULL, `pol_7` LONGTEXT NULL, `pol_8` LONGTEXT NULL, `pol_9` LONGTEXT NULL, `pol_10` LONGTEXT NULL, `pol_11` LONGTEXT NULL, `pol_12` LONGTEXT NULL, `pol_13` LONGTEXT NULL, `pol_14` LONGTEXT NULL, `pol_15` LONGTEXT NULL, `pol_16` LONGTEXT NULL, `pol_17` LONGTEXT NULL, UNIQUE INDEX `id` (`id`) ) COLLATE='utf8_general_ci' ENGINE=InnoDB AUTO_INCREMENT=240013 ; 

In the table, the field type "LONGTEXT" is taken as a preliminary, for checking the operation of the database ... Then the necessary types will be assigned to the fields: LONGTEXT, TEXT, numbers, dates, etc. In the fields: pol_9, pol_10, pol_11 a lot of lower case text of more than 1,000 characters is used. In the remaining fields, just the text "TEXT _ RECORDS pol_n"

Request
Execute the query in the HeidiSql program from the tbl8 table

 select* from `01tst`.`tbl8` where ( `01tst`.`tbl8`.`idsub` = 2 ) 

The request is executed 2 seconds.
When the number of lines reaches more than 100,000 - the duration of the query 40 seconds.

Question
How to reduce the duration of the request?
What influences the duration of the request?
enter image description here

  • one
    For example, try to index not by UNIQUE , but by PRIMARY - SLy_huh
  • one
    In any questions on the speed of work, it is necessary to give the execution plan obtained (for MySQL) using explain. In general, with such a runtime, it looks like you do not have an index on the idsub column and it is forced to iterate over the entire table - Mike
  • one
    I first tried to create an index for idsub . Since it is filtered by it, it can help a lot - KoVadim
  • one
    Why id not primary key ? And there is no index on id_sub . - vp_arth

1 answer 1

Add an index to the idsub field. Learn what indexes are 1 2 It would also be good to know about EXPLAIN 1