Mysql + php performance

I am using mysql based application where all data comes from mysql and display it with php.

When designing a database, all safety precautions should be taken, so mysql gives better performance.

I had a little doubt. I have a text column in my form and I don’t know how much length data will be entered. So, instead of varchar (255), if I create it as varchar (2000), does this affect performance?

+3
source share
3 answers

varchar takes the number of bytes of the data prefix + length regardless of the length definition

eg.

'xyz' 4 , 3 1 2 . 1 , 255 , 2 , , 255 . 1 , 255 .

, VARCHAR.

+1

. Varchars. ( ) , .

, , , , . . 13.2.14. InnoDB:

, (VARBINARY, VARCHAR, BLOB TEXT), . 8000 . LONGBLOB LONGTEXT 4 , BLOB TEXT, 4 .

, . , , 13.2.11.2, " ".

10.5. :

MyISAM 65 535 . BLOB TEXT, 9 12 .

+3

, varchar (255), varchar (2000), ?

. , :

 create table example (
    id int NOT NULL AUTOINCREMENT,
    smallstr VARCHAR(20),
    anumber mediumint(6) DEFAULT 0,
    bigstr (2000)
    PRIMARY KEY (id)
    KEY lookup (anumber, smallstr)
 )

, - , 1 . varchar, - , . . :

 create table example2 (
    id int NOT NULL AUTOINCREMENT,
    smallstr VARCHAR(20),
    anumber mediumint(6) DEFAULT 0
    PRIMARY KEY (id)
    KEY lookup (anumber, smallstr)
 );   
 create table example2_sub (
   ex2_id int NOT NULL,
   bigstr (2000)
   PRIMARY_KEY (ex2_id)
 );

25 , .. 1/40- , . OTOH, example2 example2_sub, , ( , 30%, ).

( , HTML , ).

.

+1
source

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


All Articles