Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

EAV or XML Expand / Collapse
Author
Message
Posted Thursday, December 12, 2013 3:23 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, October 17, 2014 6:13 PM
Points: 66, Visits: 204
I have a set of tables in database where I cannot change its structure. I need to create extensions to the tables by adding new attributes (columns). The list of columns and their data types is determined dynamically by the applications that use the database.

I thought of using an EAV approach for the extensions, or create a table with a XML column to store the variable extensions and maintain a relational structure. Another possibility is a hybrid approach where I would create an EAV for the metadata only, and use the XML for storing the data.

I would appreciate if someone could comments on the options or enlighten me with different ideas.
Post #1522507
Posted Thursday, December 12, 2013 4:03 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Thursday, October 9, 2014 1:02 PM
Points: 6,032, Visits: 5,284
I have been spending a lot of time playing with the XML data type in SQL lately. And I have been largely UNDERwhelmed with the performance. I would POC it both ways to see how it performs.

CEWII
Post #1522515
Posted Friday, December 13, 2013 3:56 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:47 AM
Points: 13,872, Visits: 28,270
I'm with Elliot. I've done lots of programming in and around XML on SQL Server. It's functional. But it's not terribly fast. If you're just talking, writing and reading this stuff in and out of the database as XML and then all parsing is done at the client side, yeah, that'll work. But if you're talking filtering and querying the XML, I think you'll be digging a pretty dark hole for yourself.

EAV structures can work, although they're hard to set up. I saw a discussion on it recently somewhere (or maybe I was involved in one at an event, I don't remember) where people were able to get EAV to work nicely. But it takes a bit of effort and some careful coding. Take your time and don't do crazy shortcuts around how SQL Server stores and accesses data because those almost never work out well.


----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server Query Performance Tuning
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1522623
Posted Friday, December 13, 2013 9:03 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, October 17, 2014 6:13 PM
Points: 66, Visits: 204
Grant, would it be possible to post a link to the event name or the document you saw, in case it is public domain? Thanks
Post #1522742
Posted Friday, December 13, 2013 11:05 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:47 AM
Points: 13,872, Visits: 28,270
I would if I remembered it. It might have been a conversation I had at SQL Saturday DC. I just don't recall, sorry.

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server Query Performance Tuning
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1522808
Posted Friday, December 13, 2013 7:40 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 8:30 PM
Points: 35,355, Visits: 31,896
N_Muller (12/12/2013)
I have a set of tables in database where I cannot change its structure. I need to create extensions to the tables by adding new attributes (columns). The list of columns and their data types is determined dynamically by the applications that use the database.

I thought of using an EAV approach for the extensions, or create a table with a XML column to store the variable extensions and maintain a relational structure. Another possibility is a hybrid approach where I would create an EAV for the metadata only, and use the XML for storing the data.

I would appreciate if someone could comments on the options or enlighten me with different ideas.


If the columns being added are not added by the whim of an end user, consider multiple "sister tables" in a star schema. Although that can add a bit o' complexity to code, it allows real data-typing of the new columns, can be fast as the wind, and also easily allows for DRI.

If you decide to go the EAV route and you have no "blob" data, read up on the SQL_VARIANT datatype which allows for some semblance of metadata preservation (I use it for column-level Audit tables).

I share Elliott's and Grant's observations on XML except I'll go several steps further. I feel that it's a grossly overused, over advertised, resource intensive, difficult to maintain, pipe clogging, bloated method that should be avoided in a database at any and all costs because it's worth avoiding.

Heh... strong letter to follow.



--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1522918
Posted Saturday, December 14, 2013 5:35 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, October 17, 2014 6:13 PM
Points: 66, Visits: 204
Thanks, everyone. In the end I'm using the EAV for metadata only. I created a stored procedure that runs every time a new attribute is created (trigger) to generate an alter view that returns all columns of the main table and the additional columns in the metadata EAV.
Post #1522998
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse