I've heard that if you have a table with a TEXT column that will hold a large chunk of text data, it's better for performance to move that column into a separate table and get it via JOINs to the base record.
Is this true, and if so why?
Can postgresql and mysql run together in the same machine ? yes. Ehm. There is no conflict between the 2 so you install mysql the normal way ( sudo apt-get install mysql-server ) , you install postgres ( sudo apt-get install postgresql postgresql-contrib ) the normal way.
Using text data type in PostgreSQL, we can store the unlimited length of the string. The text data type is stored data up to 1 GB in the field of a column. Varchar and text data type performance is the same in PostgreSQL. But varchar allows only to store 255 characters into the column.
MySQL is a simpler database that's fast, reliable, well understood, and easy to set up and manage. PostgreSQL is an object-relational database (ORDBMS) with features like table inheritance and function overloading, whereas MySQL is a pure relational database (RDBMS).
Not with PostgreSQL, from the manual:
Very long values are also stored in background tables so that they do not interfere with rapid access to shorter column values.
So a large character column (such as TEXT
or VARCHAR
without a specified size limit) is stored away from the main table data. So, PostgreSQL has your "put it in a separate table" optimization built in. If you're using PostgreSQL, arrange your table sensibly and leave the data layout to PostgreSQL.
I don't know how MySQL or other RDBMs arrange their data.
The reason behind this optimization is that the database will usually keep the data for each row in contiguous blocks on disk to cut down on seeking when the row needs to be read or updated. If you have a TEXT (or other variable length type) column in a row then the size of the row is variable so more work is needed to go from row to row. An analogy would be the difference between accessing something in a linked list versus accessing an array; with a linked list, you have to read three elements one at a time to get to the fourth one, with an array you just offset 3 * element_size
bytes from the beginning and you're there in one step.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With