Verifying the Relationship

One mistake most new developers make is using the wrong table or dataset as a reference. In the SELECT() of a reference record, the developer usually needs to traverse through existing relationships to get to the correct referential record. Ockham’s Razor does not usually apply when querying the appropriate data structures and tables.

Consider a setup whereby a data structure exists simply to limit indexes of a much larger dataset. These instances happen in software design where there are an infinite number of choices, yet only a few apply in a given context. This happens when larger and more complex sites attempt to normalize their data using existing structures.

One example might be a data structure holding names of populated places; there are several contextual lenses that may be applied to a list of places; niche communities (mining, tech centers) versus metropolitan areas, farming communities, localized references (The 818, NoHo, SoHo), etc. The placement of these contexts by definition is a limiting factor on the referential entities. The referential entities are lessened to only items fitting inside that contextual lens. The contextual lens adds a layer of complexity that must be appropriately handled. When a contextual lens of a natural disaster or power outage is applied, the list of matching populated places shrinks even further.

The contexts may limit the referenceable entities by size, culture, socioeconomics, geography, natural disasters, and more. It is important to recognize when SELECT()s are made within a particular lens.

The contexts placed on the list of populated places limits the returned results, but should not be the referenced data itself. Many developers fall into the trap of using the contextual index rather than the logical relationship. The correct relationship is to the original populated place record, rather than the contextual lens record.

This particular skill is one that can be very tough to learn, as programmers usually work with predefined data sets instead of the full data set. The class() options fed to the function() are, by definition, limited and not the correct reference. The mistake is understandable as years of experience has helped to recognize the occurence of the relational flaw. It takes skill to understand the differences between the programmatic and logical relationships.

The most important question to ask one’s self when writing a query is: “What do I actually want to reference?” Once that question is answered, then start working through the relationships to get to the tables in the WHERE() clause. This tidbit addresses one of the most basic flaws in queries and relationships encountered by newer developers.


Posted

in

,

by