Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Strip your TEXT fields

923 views

Published on

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?

Published in: Software
  • Be the first to comment

Strip your TEXT fields

  1. 1. Strip your `TEXT` field 
 
 
 Gabriela D’Avila @gabidavila
  2. 2. Databases
  3. 3. Considerations
  4. 4. 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
  5. 5. Example
  6. 6. 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
  7. 7. How long did it take?
  8. 8. Scenario • > 750 GB • > 380 milion records • 3 `TEXT` fields
  9. 9. 2 days
  10. 10. What is one the 1st things we learn when we start to program?
  11. 11. Fast Slow
  12. 12. Why? • 1 text file for field for every record • The text files are stored in a different place than the table location
  13. 13. Engine
  14. 14. MyISAM • Faster read speed • Supports FULLTEXT indexes • Non transactional • Higher probability of data loss
  15. 15. InnoDB • Transactional • Data integrity • Until the 5.6 version, MySQL didn’t support FULLTEXT indexes
  16. 16. Impacts of a TEXT field • Inefficient search with the `LIKE` statement • Slow `ALTER TABLE`
  17. 17. Alternatives
  18. 18. Faster Search
  19. 19. Faster Search
  20. 20. Faster Retrieval
  21. 21. CDN: Content Delivery Network
  22. 22. Keeping the TEXT field in your DB
  23. 23. 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
  24. 24. Thank you! @gabidavila
  25. 25. More information • http://gabriela.io/blog/2015/04/27/strip-your-text-field/ • http://www.percona.com/blog/2010/02/09/blob-storage-in-innodb/

×