Most efficient method for persisting complex types with variable schemas in SQL

前端 未结 5 1006
旧巷少年郎
旧巷少年郎 2021-01-03 08:21

What I\'m doing

I am creating an SQL table that will provide the back-end storage mechanism for complex-typed objects. I am trying to determine how

5条回答
  •  梦毁少年i
    2021-01-03 08:34

    Interesting question.

    I think you may be asking the wrong question here. Broadly speaking, as long as you have a FULLTEXT index on your text field, queries will be fast. Much faster than varchar if you have to use wild cards, for instance.

    However, if I were you, I'd concentrate on the actual queries you're going to be running. Do you need boolean operators? Wildcards? Numerical comparisons? That's where I think you will encounter the real performance worries.

    I would imagine you would need queries like:

    • "find all addresses in the states of New York, New Jersey and Pennsylvania"
    • "find all addresses between house numbers 1 and 100 on Mulberry Street"
    • "find all addresses where the zipcode is missing, and the city is New York"

    At a high level, the solution you propose is to store your XML somewhere, and then de-normalize that XML into name/value pairs for querying.

    Name/value pairs have a long and proud history, but become unwieldy in complex query situations, because you're not using the built-in optimizations and concepts of the relational database model.

    Some refinements I'd recommend is to look at the domain model, and at least see if you can factor out separate data types into the "value" column; you might end up with "textValue", "moneyValue", "integerValue" and "dateValue". In the example you give, you might factor "address 1" into "housenumber" (as an integer) and "streetname".

    Having said all this - I don't think there's a better solution other than completely changing tack to a document-focused database.

提交回复
热议问题