Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Strip your TEXT fields

Strip your TEXT fields

Unconference track of PHPNW 2015

We use a TEXT field to store JSON, plain text and sometimes even HTML content. Buy why this kind of field is so prejudicial to your database? What can we use instead to have the same flexibility? And if it can't be avoided, what can be the best solution to using it?

Avatar for Gabriela D'Ávila Ferrara

Gabriela D'Ávila Ferrara

October 03, 2015
Tweet

More Decks by Gabriela D'Ávila Ferrara

Other Decks in Programming

Transcript

  1. Doing an `ALTER TABLE` • Creates a new table with

    the new structure • Copies the data from the old table to the new table • Renames the new table as the old table
  2. Alter PK from INT to BIGINT* - 2.147.483.648 to 2.147.483.647

    INT - 922.337.203.854.775.808 to 922.337.203.854.775.807 BIGINT **out of scale *signed
  3. Why? • 1 text file for field for every record

    • The text files are stored in a different place than the table location
  4. MyISAM • Faster read speed • Supports FULLTEXT indexes •

    Non transactional • Higher probability of data loss
  5. InnoDB • Transactional • Data integrity • Until the 5.6

    version, MySQL didn’t support FULLTEXT indexes
  6. Impacts of a TEXT field • Inefficient search with the

    `LIKE` statement • Slow `ALTER TABLE`
  7. Conclusions • There is no right solution • Some solutions

    may add another layer to the application • Some solutions can only be applied in a low coupling system