Improve TEXT performance?

I need to save text in a MySQL database. The text size is different for each line, usually around 10kb, but may be 100kbin some very rare cases.

The text will be available quite often for reading and writing. For this reason, I believe that it is best to do it VARCHAR, because it is much faster than TEXT.

Question : is it possible to make a column VARCHAR, and in a very rare case the text is larger than 64kbhow to somehow save it as TEXT?

+4
source share
3 answers

VARCHAR, , - 64 . TEXT 64 .

. http://dev.mysql.com/doc/refman/5.6/en/string-type-overview.html

, MEDIUMTEXT. 16 .

, VARCHAR " , ?" InnoDB VARCHAR, TEXT BLOB .

, , :

  • , , MyISAM, .

  • , " " . " , ". , .

PRIMARY UNIQUE , , :

mysql> create table foo (t text, primary key(t(50)));
mysql> insert into foo values (concat(repeat('a',50), 'x'));
mysql> insert into foo values (concat(repeat('a',50), 'y'));
ERROR 1062 (23000): Duplicate entry
  'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay' for key 'PRIMARY'

, , 2 , VARCHAR MEDIUMTEXT, VARCHAR, . 3 , VARCHAR, , . ?

. , , . , , , , .

+5

SQL , . LONGTEXT x- . , .

CREATE INDEX ltcol_idx ON my_table (ltcol(64));
+2

blobs, ~ 64k UTF-8 InnoDB.

+2

Source: https://habr.com/ru/post/1524862/


All Articles