Optimizing MySQL table for variety of VarChar length between 20 and 4,000 characters

redux

I plan to be storing strings that have a maximum size of 4,500 VarChar, but MOST of the entries will be under 200 characters. Is MySql smart enough to optimize?

My current solution is to use 5 tables, data_small, data_medium, data_large, etc and insert based on the length of the string. The other solution would be to save files to disk, which would mean a second hit to the database, but result in a smaller return.

JNevill

MySQL would do fine as would most every RDBMS for that matter. When you specify a field as type CHAR() the number of characters is always used regardless of how many characters are in your string. For instance: If you have Char(64) field and you insert 'ABCD' then the field is still 64 bytes (assuming non-unicode).

When using VARCHAR(), however, the cell only uses as many bytes as are in the string, plus the number of bytes necessary to store the size of the string. So: If you have VARCHAR(64) and insert 'ABCD' you will only use 5 bytes. 4 for the characters 'ABCD' and one for the number of characters '4'.

Your extremely varying string lengths are exactly the reason we have VARCHAR(), so feel free to use VARCHAR(4500) and rest assured you will only be using as much space as necessary to store the characters in the string, and a little bit extra for the length.

Somewhat related: This is why it's not a great idea to use VARCHAR() for fields that don't have varying length strings being inserted. You are wasting space storing the size of the string when it's already known. For instance, telephone numbers of the form x-xxx-xxx-xxxx should just use Char(14) since it will always take up 14 characters and only 14 bytes are necessary. If you used VARCHAR(14) instead you would actually end up using 15 bytes.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

20〜4,000文字のさまざまなVarCharの長さに合わせてMySQLテーブルを最適化する

分類Dev

What's the impact of changing the length of a varchar in mysql?

分類Dev

Retrieving XML data from clob greater than 4,000 characters

分類Dev

Variable length substring between two characters

分類Dev

同じ整数で4,000行以上のMySQLデータベースを更新します

分類Dev

ワイドからロングまで巨大なdata.table(1,000,000×4,000エイリアス8GB)を形成します

分類Dev

Optimizing indexes for a dependent subquery in MySQL

分類Dev

MYSQL 4 Table Query

分類Dev

MySql / Cloudbees VARCHAR as ForeignKey

分類Dev

4,000万と128GBのRAMを使用したmysqlの単純な更新に時間がかかりすぎる

分類Dev

Left pad varchar to certain length in sql server

分類Dev

4,000万値の自動提案

分類Dev

MySQL Optimizing MyISAM table to MASTER serverはSLAVEサーバーにも複製できますか?

分類Dev

Astropy get table length

分類Dev

Regex to keep the last 4 characters of a string of unknown length using C#

分類Dev

CREATE TABLEクエリでCHAR_LENGTH()を使用する方法-MYSQL

分類Dev

How to get all distinct words of a specified minimum length from multiple columns in a MySQL table?

分類Dev

SparkSQL / Hive:MySQLの `information_schema.table。{data_length、table_rows}`に相当しますか?

分類Dev

Optimizing finding matching substring between the two lists by regex in Python

分類Dev

MYSQL CONCAT MAX LENGTH

分類Dev

Comparison issues between varchar and int columns

分類Dev

How can I force varchar length in Linq To SQL

分類Dev

MySQL: How to select rows from one table between each interval taken from other table

分類Dev

MySQL-length()とchar_length()

分類Dev

Hive Alter table column size in VARCHAR

分類Dev

Should i avoid JOIN when MySQL not optimizing them?

分類Dev

Converting accented characters in varchar() to XML causing "illegal XML character"

分類Dev

Laravel's Eloquent: bypass the 191 characters VARCHAR limitation

分類Dev

値がvarcharフィールドで9999より大きい場合、Mysqlの「between」条件が機能しない

Related 関連記事

  1. 1

    20〜4,000文字のさまざまなVarCharの長さに合わせてMySQLテーブルを最適化する

  2. 2

    What's the impact of changing the length of a varchar in mysql?

  3. 3

    Retrieving XML data from clob greater than 4,000 characters

  4. 4

    Variable length substring between two characters

  5. 5

    同じ整数で4,000行以上のMySQLデータベースを更新します

  6. 6

    ワイドからロングまで巨大なdata.table(1,000,000×4,000エイリアス8GB)を形成します

  7. 7

    Optimizing indexes for a dependent subquery in MySQL

  8. 8

    MYSQL 4 Table Query

  9. 9

    MySql / Cloudbees VARCHAR as ForeignKey

  10. 10

    4,000万と128GBのRAMを使用したmysqlの単純な更新に時間がかかりすぎる

  11. 11

    Left pad varchar to certain length in sql server

  12. 12

    4,000万値の自動提案

  13. 13

    MySQL Optimizing MyISAM table to MASTER serverはSLAVEサーバーにも複製できますか?

  14. 14

    Astropy get table length

  15. 15

    Regex to keep the last 4 characters of a string of unknown length using C#

  16. 16

    CREATE TABLEクエリでCHAR_LENGTH()を使用する方法-MYSQL

  17. 17

    How to get all distinct words of a specified minimum length from multiple columns in a MySQL table?

  18. 18

    SparkSQL / Hive:MySQLの `information_schema.table。{data_length、table_rows}`に相当しますか?

  19. 19

    Optimizing finding matching substring between the two lists by regex in Python

  20. 20

    MYSQL CONCAT MAX LENGTH

  21. 21

    Comparison issues between varchar and int columns

  22. 22

    How can I force varchar length in Linq To SQL

  23. 23

    MySQL: How to select rows from one table between each interval taken from other table

  24. 24

    MySQL-length()とchar_length()

  25. 25

    Hive Alter table column size in VARCHAR

  26. 26

    Should i avoid JOIN when MySQL not optimizing them?

  27. 27

    Converting accented characters in varchar() to XML causing "illegal XML character"

  28. 28

    Laravel's Eloquent: bypass the 191 characters VARCHAR limitation

  29. 29

    値がvarcharフィールドで9999より大きい場合、Mysqlの「between」条件が機能しない

ホットタグ

アーカイブ