Standard EAV schema : One column for Entity ID, one for Attribute ID, one for Value ID.
Historical EAV schema : Add an additional column(s) for times/date-ranges
At run time, certain rows will be excluded. There may be 0, 1, or many rows returned per entity, per attribute. We only want the most recent value for each attribute remaining.
Our current solution is using the SQL Server Rank() function to mark each row with a rank, and then in the where clause we have "and rank = 1".
However, performance is not satisfactory. During analysis we find that assigning the ranks is quite fast, however doing the where clause against the rank requires a second scan of the data, and keeps the entire data set in RAM.
What is the fastest way to rank the remaining attribute rows, and return only the latest?