Matthew Carter wrote:
> It would add some technical debt for sure, but running queries against
> flat text fields (like TEXT type in MySQL) is still ridiculously fast
> even on a few hundred thousand rows for LIKE type queries.
But the index key length of TEXT-type columns is limited in MySQL.
> For instance, if you stored the following JSON as part of the entry (JSON
> snippet):
>
> {..., "first_name":"Matt","last_name":"Carter",...}
>
> you could run this query without a huge headache:
>
> SELECT * FROM table WHERE json LIKE '%"first_name":"Matt"%' AND
> json LIKE '%"last_name":"Carter"%';
That is like trying to parse HTML with a single regular expression.
Not only is it very inefficient, and does not work reliably, it also can
fail horribly.
> Depending on data sanitation (or lack of), easily possible to get false
> positives (although you'd json_decode and check in PHP after the query).
Exactly. Which is why you should never serialize information that need to
be queried. If you need to store objects in a database and retrieve them by
their properties, then for goodness’ sake either put the data in separate
fully-indexable fields in an RDBMS, or use an object-oriented one, like
MongoDB.
--
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.