Changing from varchar to mediumtext causes performance degradation

前端 未结 1 1853
慢半拍i
慢半拍i 2021-01-29 03:34

I have a table which stores product reviews for a website. The table uses varchar(1000) to store the review comment average response time is 0.5 seconds. I changed the datatyp

相关标签:
1条回答
  • 2021-01-29 03:51

    The two datatypes are handled virtually identically. There are many other possible reasons for sluggishness. (But none that I know of that would say MEDIUMTEXT is worse than VARHAR.)

    So... Let's see if we can speed up the web page...

    Put microtime(true) around the mysql calls -- to make sure it is MySQL, not PHP. "0.019secs" makes sense; "1.5 - 2 seconds" sounds like something is going on in PHP.

    Use InnoDB, not MyISAM. (In spite of your claims to the contrary.)

    Tune correctly; let's see SHOW VARIABLES LIKE '%buffer%'; How much RAM do you have? (Swapping is terrible for performance.)

    How many rows are you returning? It's not practical to have more than a few dozen on a web page, so add ORDER BY...LIMIT....

    If the UI limit is 1000 characters, use TEXT or VARCHAR(1000), not MEDIUMTEXT. If you are trying to raise up to 64K bytes (potentially 4K utf8mb4 characters), then use TEXT.

    You do need this (with the columns in either order):

    INDEX(part_id, language)
    

    If there has been a lot of "churn" (deletes and/or updates followed by more inserts) in the MyISAM table, the data can be fragmented, hence slow. This can happen for both VARCHAR and TEXT. This does not happen with InnoDB.

    0 讨论(0)
提交回复
热议问题