<s>
Entity	B-General_Concept
–	I-General_Concept
attribute	I-General_Concept
–	I-General_Concept
value	I-General_Concept
model	I-General_Concept
(	O
EAV	O
)	O
is	O
a	O
data	B-Application
model	I-Application
to	O
encode	O
,	O
in	O
a	O
space-efficient	O
manner	O
,	O
entities	O
where	O
the	O
number	O
of	O
attributes	O
(	O
properties	O
,	O
parameters	O
)	O
that	O
can	O
be	O
used	O
to	O
describe	O
them	O
is	O
potentially	O
vast	O
,	O
but	O
the	O
number	O
that	O
will	O
actually	O
apply	O
to	O
a	O
given	O
entity	O
is	O
relatively	O
modest	O
.	O
</s>
<s>
Such	O
entities	O
correspond	O
to	O
the	O
mathematical	O
notion	O
of	O
a	O
sparse	B-Algorithm
matrix	I-Algorithm
.	O
</s>
<s>
EAV	O
is	O
also	O
known	O
as	O
object	O
–	O
attribute	B-Application
–	I-Application
value	I-Application
model	O
,	O
vertical	O
database	O
model	O
,	O
and	O
open	B-General_Concept
schema	I-General_Concept
.	O
</s>
<s>
This	O
data	O
representation	O
is	O
analogous	O
to	O
space-efficient	O
methods	O
of	O
storing	O
a	O
sparse	B-Algorithm
matrix	I-Algorithm
,	O
where	O
only	O
non-empty	O
values	O
are	O
stored	O
.	O
</s>
<s>
In	O
an	O
EAV	O
data	B-Application
model	I-Application
,	O
each	O
attribute	B-Application
–	I-Application
value	I-Application
pair	I-Application
is	O
a	O
fact	O
describing	O
an	O
entity	O
,	O
and	O
a	O
row	O
in	O
an	O
EAV	O
table	O
stores	O
a	O
single	O
fact	O
.	O
</s>
<s>
The	O
attribute	O
or	O
parameter	O
:	O
typically	O
implemented	O
as	O
a	O
foreign	B-Application
key	I-Application
into	O
a	O
table	O
of	O
attribute	O
definitions	O
.	O
</s>
<s>
Consider	O
how	O
one	O
would	O
try	O
to	O
represent	O
a	O
general-purpose	O
clinical	O
record	O
in	O
a	O
relational	B-Application
database	I-Application
.	O
</s>
<s>
Clearly	O
creating	O
a	O
table	O
(	O
or	O
a	O
set	O
of	O
tables	O
)	O
with	O
thousands	O
of	O
columns	O
is	O
not	O
feasible	O
,	O
because	O
the	O
vast	O
majority	O
of	O
columns	O
would	O
be	O
null	B-Language
.	O
</s>
<s>
The	O
entries	O
shown	O
within	O
angle	O
brackets	O
are	O
references	O
to	O
entries	O
in	O
other	O
tables	O
,	O
shown	O
here	O
as	O
text	O
rather	O
than	O
as	O
encoded	O
foreign	B-Application
key	I-Application
values	O
for	O
ease	O
of	O
understanding	O
.	O
</s>
<s>
The	O
latter	O
are	O
particularly	O
useful	O
when	O
the	O
possible	O
values	O
are	O
known	O
to	O
be	O
limited	O
(	O
i.e.	O
,	O
enumerable	B-Language
)	O
.	O
</s>
<s>
For	O
clinical	O
findings	O
,	O
the	O
entity	O
is	O
the	O
patient	O
event	O
:	O
a	O
foreign	B-Application
key	I-Application
into	O
a	O
table	O
that	O
contains	O
at	O
a	O
minimum	O
a	O
patient	O
ID	O
and	O
one	O
or	O
more	O
time-stamps	O
(	O
e.g.	O
,	O
the	O
start	O
and	O
end	O
of	O
the	O
examination	O
date/time	O
)	O
that	O
record	O
when	O
the	O
event	O
being	O
described	O
happened	O
.	O
</s>
<s>
The	O
attribute	O
or	O
parameter	O
:	O
a	O
foreign	B-Application
key	I-Application
into	O
a	O
table	O
of	O
attribute	O
definitions	O
(	O
in	O
this	O
example	O
,	O
definitions	O
of	O
clinical	O
findings	O
)	O
.	O
</s>
<s>
The	O
"	O
entity	O
"	O
is	O
the	O
sale/transaction	O
id	O
—	O
a	O
foreign	B-Application
key	I-Application
into	O
a	O
sales	O
transactions	O
table	O
.	O
</s>
<s>
The	O
"	O
attribute	O
"	O
is	O
a	O
foreign	B-Application
key	I-Application
into	O
a	O
products	O
table	O
,	O
from	O
where	O
one	O
looks	O
up	O
description	O
,	O
unit	O
price	O
,	O
discounts	O
and	O
promotions	O
,	O
etc	O
.	O
</s>
<s>
It	O
follows	O
that	O
in	O
production	O
systems	O
,	O
allowing	O
direct	O
data	O
entry	O
into	O
an	O
EAV	O
table	O
would	O
be	O
a	O
recipe	O
for	O
disaster	O
,	O
because	O
the	O
database	B-General_Concept
engine	I-General_Concept
itself	O
would	O
not	O
be	O
able	O
to	O
perform	O
robust	O
input	O
validation	O
.	O
</s>
<s>
We	O
shall	O
see	O
later	O
how	O
it	O
is	O
possible	O
to	O
build	O
generic	B-Application
frameworks	I-Application
that	O
perform	O
most	O
of	O
the	O
tasks	O
of	O
input	O
validation	O
,	O
without	O
endless	O
coding	O
on	O
an	O
attribute-by-attribute	O
basis	O
.	O
</s>
<s>
In	O
more	O
general-purpose	O
settings	O
,	O
the	O
entity	O
is	O
a	O
foreign	B-Application
key	I-Application
into	O
an	O
"	O
objects	O
"	O
table	O
that	O
records	O
common	O
information	O
about	O
every	O
"	O
object	O
"	O
(	O
thing	O
)	O
in	O
the	O
database	O
–	O
at	O
the	O
minimum	O
,	O
a	O
preferred	O
name	O
and	O
brief	O
description	O
,	O
as	O
well	O
as	O
the	O
category/class	O
of	O
entity	O
to	O
which	O
it	O
belongs	O
.	O
</s>
<s>
In	O
the	O
EAV	O
table	O
itself	O
,	O
this	O
is	O
just	O
an	O
attribute	O
ID	O
,	O
a	O
foreign	B-Application
key	I-Application
into	O
an	O
Attribute	O
Definitions	O
table	O
,	O
as	O
stated	O
above	O
.	O
</s>
<s>
Also	O
,	O
it	O
is	O
not	O
convenient	O
to	O
store	O
large	O
binary	O
data	O
,	O
such	O
as	O
images	O
,	O
in	O
Base64	B-Protocol
encoded	O
form	O
in	O
the	O
same	O
table	O
as	O
small	O
integers	O
or	O
strings	O
.	O
</s>
<s>
Therefore	O
,	O
larger	O
systems	O
use	O
separate	O
EAV	O
tables	O
for	O
each	O
data	O
type	O
(	O
including	O
binary	B-General_Concept
large	I-General_Concept
objects	I-General_Concept
,	O
"	O
BLOBS	B-General_Concept
"	O
)	O
,	O
with	O
the	O
metadata	O
for	O
a	O
given	O
attribute	O
identifying	O
the	O
EAV	O
table	O
in	O
which	O
its	O
data	O
will	O
be	O
stored	O
.	O
</s>
<s>
EAV	O
,	O
as	O
a	O
general-purpose	O
means	O
of	O
knowledge	O
representation	O
,	O
originated	O
with	O
the	O
concept	O
of	O
"	O
association	B-Application
lists	I-Application
"	O
(	O
attribute	B-Application
–	I-Application
value	I-Application
pairs	I-Application
)	O
.	O
</s>
<s>
Commonly	O
used	O
today	O
,	O
these	O
were	O
first	O
introduced	O
in	O
the	O
language	O
LISP	B-Language
.	O
</s>
<s>
Attribute	B-Application
–	I-Application
value	I-Application
pairs	I-Application
are	O
widely	O
used	O
for	O
diverse	O
applications	O
,	O
such	O
as	O
configuration	O
files	O
(	O
using	O
a	O
simple	O
syntax	O
like	O
attribute	O
=	O
value	O
)	O
.	O
</s>
<s>
An	O
example	O
of	O
non-database	O
use	O
of	O
EAV	O
is	O
in	O
UIMA	B-Application
(	O
Unstructured	O
Information	O
Management	O
Architecture	O
)	O
,	O
a	O
standard	O
now	O
managed	O
by	O
the	O
Apache	B-Application
Foundation	O
and	O
employed	O
in	O
areas	O
such	O
as	O
natural	B-Language
language	I-Language
processing	I-Language
.	O
</s>
<s>
Software	O
that	O
analyzes	O
text	O
typically	O
marks	O
up	O
(	O
"	O
annotates	O
"	O
)	O
a	O
segment	O
:	O
the	O
example	O
provided	O
in	O
the	O
UIMA	B-Application
tutorial	O
is	O
a	O
program	O
that	O
performs	O
named-entity	B-General_Concept
recognition	I-General_Concept
(	O
NER	O
)	O
on	O
a	O
document	O
,	O
annotating	O
the	O
text	O
segment	O
"	O
President	O
Bush	O
"	O
with	O
the	O
annotation	O
–	O
attribute	B-Application
–	I-Application
value	I-Application
triple	O
(	O
Person	O
,	O
Full_Name	O
,	O
"	O
George	O
W	O
.	O
Bush	O
"	O
)	O
.	O
</s>
<s>
The	O
first	O
medical	O
record	O
systems	O
to	O
employ	O
EAV	O
were	O
the	O
Regenstrief	O
electronic	B-Application
medical	I-Application
record	I-Application
(	O
the	O
effort	O
led	O
by	O
Clement	O
MacDonald	O
)	O
,	O
William	O
Stead	O
and	O
Ed	O
Hammond	O
's	O
TMR	O
(	O
The	O
Medical	O
Record	O
)	O
system	O
and	O
the	O
HELP	O
Clinical	O
Data	O
Repository	O
(	O
CDR	O
)	O
created	O
by	O
Homer	O
Warner	O
's	O
group	O
at	O
LDS	O
Hospital	O
,	O
Salt	O
Lake	O
City	O
,	O
Utah	O
.	O
</s>
<s>
All	O
these	O
systems	O
,	O
developed	O
in	O
the	O
1970s	O
,	O
were	O
released	O
before	O
commercial	O
systems	O
based	O
on	O
E.F.	O
Codd	O
's	O
relational	B-Application
database	I-Application
model	O
were	O
available	O
,	O
though	O
HELP	O
was	O
much	O
later	O
ported	O
to	O
a	O
relational	O
architecture	O
and	O
commercialized	O
by	O
the	O
3M	O
corporation	O
.	O
</s>
<s>
A	O
group	O
at	O
the	O
Columbia-Presbyterian	O
Medical	O
Center	O
were	O
the	O
first	O
to	O
use	O
a	O
relational	B-Application
database	I-Application
engine	O
as	O
the	O
foundation	O
of	O
an	O
EAV	O
system	O
.	O
</s>
<s>
The	O
open-source	B-Application
clinical	O
study	O
data	O
management	O
system	O
of	O
Nadkarni	O
et	O
al	O
.	O
</s>
<s>
The	O
EAV/CR	O
framework	O
,	O
designed	O
primarily	O
by	O
Luis	O
Marenco	O
and	O
Prakash	O
Nadkarni	O
,	O
overlaid	O
the	O
principles	O
of	O
object	B-Language
orientation	I-Language
onto	O
EAV	O
;	O
it	O
built	O
on	O
Tom	O
Slezak	O
's	O
object	O
table	O
approach	O
(	O
described	O
earlier	O
in	O
the	O
"	O
Entity	O
"	O
section	O
)	O
.	O
</s>
<s>
(	O
While	O
most	O
vendor	O
database	O
schemas	O
are	O
proprietary	O
,	O
VistA	B-Application
,	O
the	O
system	O
used	O
throughout	O
the	O
United	O
States	O
Department	O
of	O
Veterans	O
Affairs	O
(	O
VA	O
)	O
medical	O
system	O
,	O
known	O
as	O
the	O
Veterans	O
Health	O
Administration	O
(	O
VHA	O
)	O
,	O
is	O
open-source	B-Application
and	O
its	O
schema	O
is	O
readily	O
inspectable	O
,	O
though	O
it	O
uses	O
a	O
MUMPS	B-Language
database	B-General_Concept
engine	I-General_Concept
rather	O
than	O
a	O
relational	B-Application
database	I-Application
.	O
)	O
</s>
<s>
In	O
a	O
simple	O
EAV	O
design	O
,	O
the	O
values	O
of	O
an	O
attribute	O
are	O
simple	O
or	O
primitive	O
data	O
types	O
as	O
far	O
as	O
the	O
database	B-General_Concept
engine	I-General_Concept
is	O
concerned	O
.	O
</s>
<s>
To	O
represent	O
substructure	O
,	O
one	O
incorporates	O
a	O
special	O
EAV	O
table	O
where	O
the	O
value	O
column	O
contains	O
references	O
to	O
other	O
entities	O
in	O
the	O
system	O
(	O
i.e.	O
,	O
foreign	B-Application
key	I-Application
values	O
into	O
the	O
objects	O
table	O
)	O
.	O
</s>
<s>
One	O
approach	O
to	O
EAV/CR	O
is	O
to	O
allow	O
columns	O
to	O
hold	O
JSON	B-General_Concept
structures	O
,	O
which	O
thus	O
provide	O
the	O
needed	O
class	O
structure	O
.	O
</s>
<s>
For	O
example	O
,	O
PostgreSQL	B-Application
,	O
as	O
of	O
version	O
9.4	O
,	O
offers	O
JSON	B-General_Concept
binary	O
column	O
(	O
JSONB	O
)	O
support	O
,	O
allowing	O
JSON	B-General_Concept
attributes	O
to	O
be	O
queried	O
,	O
indexed	O
and	O
joined	O
.	O
</s>
<s>
In	O
the	O
words	O
of	O
Prof	O
.	O
Dr.	O
Daniel	O
Masys	O
(	O
formerly	O
Chair	O
of	O
Vanderbilt	O
University	O
's	O
Medical	O
Informatics	O
Department	O
)	O
,	O
the	O
challenges	O
of	O
working	O
with	O
EAV	O
stem	O
from	O
the	O
fact	O
that	O
in	O
an	O
EAV	O
database	O
,	O
the	O
"	O
physical	O
schema	O
"	O
(	O
the	O
way	O
data	O
are	O
stored	O
)	O
is	O
radically	O
different	O
from	O
the	O
"	O
logical	B-Application
schema	I-Application
"	O
–	O
the	O
way	O
users	O
,	O
and	O
many	O
software	O
applications	O
such	O
as	O
statistics	O
packages	O
,	O
regard	O
it	O
,	O
i.e.	O
,	O
as	O
conventional	O
rows	O
and	O
columns	O
for	O
individual	O
classes	O
.	O
</s>
<s>
The	O
process	O
of	O
doing	O
this	O
,	O
called	O
pivoting	B-Application
,	O
is	O
important	O
enough	O
to	O
be	O
discussed	O
separately	O
.	O
)	O
</s>
<s>
Metadata	O
helps	O
perform	O
the	O
sleight	O
of	O
hand	O
that	O
lets	O
users	O
interact	O
with	O
the	O
system	O
in	O
terms	O
of	O
the	O
logical	B-Application
schema	I-Application
rather	O
than	O
the	O
physical	O
:	O
the	O
software	O
continually	O
consults	O
the	O
metadata	O
for	O
various	O
operations	O
such	O
as	O
data	O
presentation	O
,	O
interactive	O
validation	O
,	O
bulk	O
data	O
extraction	O
and	O
ad	O
hoc	O
query	O
.	O
</s>
<s>
EAV	O
systems	O
trade	O
off	O
simplicity	O
in	O
the	O
physical	O
and	O
logical	B-Application
structure	I-Application
of	O
the	O
data	O
for	O
complexity	O
in	O
their	O
metadata	O
,	O
which	O
,	O
among	O
other	O
things	O
,	O
plays	O
the	O
role	O
that	O
database	O
constraints	O
and	O
referential	B-General_Concept
integrity	I-General_Concept
do	O
in	O
standard	O
database	O
designs	O
.	O
</s>
<s>
The	O
structure	O
of	O
the	O
metadata	O
is	O
complex	O
enough	O
that	O
it	O
comprises	O
its	O
own	O
subschema	O
within	O
the	O
database	O
:	O
various	O
foreign	B-Application
keys	I-Application
in	O
the	O
data	O
tables	O
refer	O
to	O
tables	O
within	O
this	O
subschema	O
.	O
</s>
<s>
This	O
subschema	O
is	O
standard-relational	O
,	O
with	O
features	O
such	O
as	O
constraints	O
and	O
referential	B-General_Concept
integrity	I-General_Concept
being	O
used	O
to	O
the	O
hilt	O
.	O
</s>
<s>
This	O
Schema	O
information	O
may	O
then	O
be	O
used	O
by	O
the	O
EAV	O
database	B-General_Concept
engine	I-General_Concept
to	O
dynamically	O
re-organize	O
its	O
internal	O
table	O
structure	O
for	O
best	O
efficiency	O
.	O
</s>
<s>
Validation	O
metadata	O
include	O
data	O
type	O
,	O
range	O
of	O
permissible	O
values	O
or	O
membership	O
in	O
a	O
set	O
of	O
values	O
,	O
regular	O
expression	O
match	O
,	O
default	O
value	O
,	O
and	O
whether	O
the	O
value	O
is	O
permitted	O
to	O
be	O
null	B-Language
.	O
</s>
<s>
In	O
Web	O
browsers	O
,	O
both	O
JavaScript	B-Language
and	O
VBScript	B-Application
have	O
an	O
Eval( )	O
function	O
that	O
can	O
be	O
leveraged	O
for	O
this	O
purpose	O
.	O
</s>
<s>
The	O
availability	O
of	O
open-source	B-Application
frameworks	O
that	O
can	O
be	O
studied	O
and	O
modified	O
for	O
individual	O
needs	O
can	O
go	O
a	O
long	O
way	O
in	O
avoiding	O
wheel	O
reinvention	O
.	O
</s>
<s>
EAV	O
modeling	O
,	O
under	O
the	O
alternative	O
terms	O
"	O
generic	O
data	O
modeling	O
"	O
or	O
"	O
open	B-General_Concept
schema	I-General_Concept
"	O
,	O
has	O
long	O
been	O
a	O
standard	O
tool	O
for	O
advanced	O
data	O
modelers	O
.	O
</s>
<s>
Also	O
,	O
the	O
employment	O
of	O
EAV	O
does	O
not	O
preclude	O
the	O
employment	O
of	O
traditional	O
relational	B-Application
database	I-Application
modeling	O
approaches	O
within	O
the	O
same	O
database	O
schema	O
.	O
</s>
<s>
Because	O
the	O
correctness	O
and	O
consistency	O
of	O
metadata	O
is	O
critical	O
to	O
the	O
correct	O
operation	O
of	O
an	O
EAV	O
system	O
,	O
the	O
system	O
designer	O
wants	O
to	O
take	O
full	O
advantages	O
of	O
all	O
of	O
the	O
features	O
that	O
RDBMSs	O
provide	O
,	O
such	O
as	O
referential	B-General_Concept
integrity	I-General_Concept
and	O
programmable	O
constraints	O
,	O
rather	O
than	O
having	O
to	O
reinvent	O
the	O
RDBMS-engine	O
wheel	O
.	O
</s>
<s>
Commercial	O
electronic	B-Application
health	I-Application
record	I-Application
Systems	O
(	O
EHRs	B-Application
)	O
use	O
row-modeling	O
for	O
classes	O
of	O
data	O
such	O
as	O
diagnoses	O
,	O
surgical	O
procedures	O
performed	O
on	O
and	O
laboratory	O
test	O
results	O
,	O
which	O
are	O
segregated	O
into	O
separate	O
tables	O
.	O
</s>
<s>
In	O
each	O
table	O
,	O
the	O
"	O
entity	O
"	O
is	O
a	O
composite	O
of	O
the	O
patient	O
ID	O
and	O
the	O
date/time	O
the	O
diagnosis	O
was	O
made	O
(	O
or	O
the	O
surgery	O
or	O
lab	O
test	O
performed	O
)	O
;	O
the	O
attribute	O
is	O
a	O
foreign	B-Application
key	I-Application
into	O
a	O
specially	O
designated	O
lookup	O
table	O
that	O
contains	O
a	O
controlled	O
vocabulary	O
-	O
e.g.	O
,	O
ICD-10	O
for	O
diagnoses	O
,	O
Current	O
Procedural	O
Terminology	O
for	O
surgical	O
procedures	O
,	O
with	O
a	O
set	O
of	O
value	O
attributes	O
.	O
</s>
<s>
However	O
,	O
to	O
capture	O
data	O
on	O
parameters	O
that	O
are	O
not	O
always	O
defined	O
in	O
standard	O
vocabularies	O
,	O
EHRs	B-Application
also	O
provide	O
a	O
"	O
pure	O
"	O
EAV	O
mechanism	O
,	O
where	O
specially	O
designated	O
power-users	O
can	O
define	O
new	O
attributes	O
,	O
their	O
data	O
type	O
,	O
maximum	O
and	O
minimal	O
permissible	O
values	O
(	O
or	O
permissible	O
set	O
of	O
values/codes	O
)	O
,	O
and	O
then	O
allow	O
others	O
to	O
capture	O
data	O
based	O
on	O
these	O
attributes	O
.	O
</s>
<s>
The	O
typical	O
case	O
for	O
using	O
the	O
EAV	B-General_Concept
model	I-General_Concept
is	O
for	O
highly	O
sparse	O
,	O
heterogeneous	O
attributes	O
,	O
such	O
as	O
clinical	O
parameters	O
in	O
the	O
electronic	B-Application
medical	I-Application
record	I-Application
(	O
EMRs	O
)	O
,	O
as	O
stated	O
above	O
.	O
</s>
<s>
Even	O
where	O
they	O
are	O
encountered	O
,	O
a	O
set	O
of	O
EAV	O
tables	O
is	O
not	O
the	O
only	O
way	O
to	O
address	O
sparse	O
data	O
:	O
an	O
XML-based	O
solution	O
(	O
discussed	O
below	O
)	O
is	O
applicable	O
when	O
the	O
maximum	O
number	O
of	O
attributes	O
per	O
entity	O
is	O
relatively	O
modest	O
,	O
and	O
the	O
total	O
volume	O
of	O
sparse	O
data	O
is	O
also	O
similarly	O
modest	O
.	O
</s>
<s>
"	O
Dynamic	O
"	O
means	O
that	O
new	O
classes	O
and	O
attributes	O
need	O
to	O
be	O
continually	O
defined	O
and	O
altered	O
to	O
represent	O
an	O
evolving	O
data	B-Application
model	I-Application
.	O
</s>
<s>
Note	O
that	O
an	O
EAV	O
data	B-Application
model	I-Application
is	O
not	O
essential	O
here	O
,	O
but	O
the	O
system	O
designer	O
may	O
consider	O
it	O
an	O
acceptable	O
alternative	O
to	O
creating	O
,	O
say	O
,	O
sixty	O
or	O
more	O
tables	O
containing	O
a	O
total	O
of	O
not	O
more	O
than	O
two	O
thousand	O
rows	O
.	O
</s>
<s>
Generic	B-Application
frameworks	I-Application
that	O
utilize	O
attribute	O
and	O
attribute-grouping	O
metadata	O
address	O
the	O
former	O
but	O
not	O
the	O
latter	O
limitation	O
;	O
their	O
use	O
is	O
more	O
or	O
less	O
mandated	O
in	O
the	O
case	O
of	O
mixed	O
schemas	O
that	O
contain	O
a	O
mixture	O
of	O
conventional-relational	O
and	O
EAV	O
data	O
,	O
where	O
the	O
error	O
quotient	O
can	O
be	O
very	O
significant	O
.	O
</s>
<s>
The	O
conversion	O
operation	O
is	O
called	O
pivoting	B-Application
.	O
</s>
<s>
Pivoting	B-Application
is	O
not	O
required	O
only	O
for	O
EAV	O
data	O
but	O
also	O
for	O
any	O
form	O
of	O
row-modeled	O
data	O
.	O
</s>
<s>
(	O
For	O
example	O
,	O
implementations	O
of	O
the	O
Apriori	B-Algorithm
algorithm	I-Algorithm
for	O
Association	O
Analysis	O
,	O
widely	O
used	O
to	O
process	O
supermarket	O
sales	O
data	O
to	O
identify	O
other	O
products	O
that	O
purchasers	O
of	O
a	O
given	O
product	O
are	O
also	O
likely	O
to	O
buy	O
,	O
pivot	O
row-modeled	O
data	O
as	O
a	O
first	O
step	O
.	O
)	O
</s>
<s>
Many	O
database	B-General_Concept
engines	I-General_Concept
have	O
proprietary	O
SQL	O
extensions	O
to	O
facilitate	O
pivoting	B-Application
,	O
and	O
packages	O
such	O
as	O
Microsoft	O
Excel	O
also	O
support	O
it	O
.	O
</s>
<s>
The	O
circumstances	O
where	O
pivoting	B-Application
is	O
necessary	O
are	O
considered	O
below	O
.	O
</s>
<s>
However	O
,	O
the	O
structure	O
of	O
EAV	O
data	B-Application
model	I-Application
is	O
a	O
perfect	O
candidate	O
for	O
Relational	O
Division	O
,	O
see	O
relational	B-Algorithm
algebra	I-Algorithm
.	O
</s>
<s>
Each	O
statement	O
retrieves	O
a	O
large	O
amount	O
of	O
data	O
,	O
and	O
the	O
hash	O
tables	O
help	O
carry	O
out	O
the	O
pivoting	B-Application
operation	O
,	O
which	O
involves	O
placing	O
a	O
value	O
for	O
a	O
given	O
attribute	O
instance	O
into	O
the	O
appropriate	O
row	O
and	O
column	O
.	O
</s>
<s>
Obviously	O
,	O
no	O
matter	O
what	O
approaches	O
you	O
take	O
,	O
querying	O
EAV	O
will	O
not	O
be	O
as	O
fast	O
as	O
querying	O
standard	O
column-modeled	O
relational	O
data	O
for	O
certain	O
types	O
of	O
query	O
,	O
in	O
much	O
the	O
same	O
way	O
that	O
access	O
of	O
elements	O
in	O
sparse	B-Algorithm
matrices	I-Algorithm
are	O
not	O
as	O
fast	O
as	O
those	O
on	O
non-sparse	O
matrices	O
if	O
the	O
latter	O
fit	O
entirely	O
into	O
main	O
memory	O
.	O
</s>
<s>
(	O
Sparse	B-Algorithm
matrices	I-Algorithm
,	O
represented	O
using	O
structures	O
such	O
as	O
linked	O
lists	O
,	O
require	O
list	O
traversal	O
to	O
access	O
an	O
element	O
at	O
a	O
given	O
X-Y	O
position	O
,	O
while	O
access	O
to	O
elements	O
in	O
matrices	O
represented	O
as	O
2-D	O
arrays	O
can	O
be	O
performed	O
using	O
fast	O
CPU	O
register	O
operations	O
.	O
)	O
</s>
<s>
Originally	O
postulated	O
by	O
Maier	O
,	O
Ullman	O
and	O
Vardi	O
,	O
the	O
"	O
Universal	O
Data	B-Application
Model	I-Application
"	O
(	O
UDM	O
)	O
seeks	O
to	O
simplify	O
the	O
query	O
of	O
a	O
complex	O
relational	O
schema	O
by	O
naive	O
users	O
,	O
by	O
creating	O
the	O
illusion	O
that	O
everything	O
is	O
stored	O
in	O
a	O
single	O
giant	O
"	O
universal	O
table	O
"	O
.	O
</s>
<s>
Apart	O
from	O
the	O
way	O
in	O
which	O
data	O
is	O
explicitly	O
modeled	O
(	O
UDM	O
simply	O
uses	O
relational	O
views	O
to	O
intercede	O
between	O
the	O
user	O
and	O
the	O
database	O
schema	O
)	O
,	O
EAV	O
differs	O
from	O
Universal	O
Data	B-Application
Models	I-Application
in	O
that	O
it	O
also	O
applies	O
to	O
transactional	O
systems	O
,	O
not	O
only	O
query	O
oriented	O
(	O
read-only	O
)	O
systems	O
as	O
in	O
UDM	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
phrase	O
"	O
lithium	B-Language
"	O
can	O
refer	O
either	O
to	O
the	O
medication	O
(	O
which	O
is	O
used	O
to	O
treat	O
bipolar	O
disorder	O
)	O
,	O
or	O
a	O
laboratory	O
assay	O
for	O
lithium	B-Language
level	O
in	O
the	O
patient	O
's	O
blood	O
.	O
</s>
<s>
(	O
The	O
blood	O
level	O
of	O
lithium	B-Language
must	O
be	O
monitored	O
carefully	O
:	O
too	O
much	O
of	O
the	O
drug	O
causes	O
severe	O
side	O
effects	O
,	O
while	O
too	O
little	O
is	O
ineffective	O
.	O
)	O
</s>
<s>
An	O
Open	B-General_Concept
Schema	I-General_Concept
implementation	O
can	O
use	O
an	O
XML	B-Protocol
column	O
in	O
a	O
table	O
to	O
capture	O
the	O
variable/sparse	O
information	O
.	O
</s>
<s>
Similar	O
ideas	O
can	O
be	O
applied	O
to	O
databases	O
that	O
support	O
JSON-valued	O
columns	O
:	O
sparse	O
,	O
hierarchical	O
data	O
can	O
be	O
represented	O
as	O
JSON	B-General_Concept
.	O
</s>
<s>
If	O
the	O
database	O
has	O
JSON	B-General_Concept
support	O
,	O
such	O
as	O
PostgreSQL	B-Application
and	O
(	O
partially	O
)	O
SQL	O
Server	O
2016	O
and	O
later	O
,	O
then	O
attributes	O
can	O
be	O
queried	O
,	O
indexed	O
and	O
joined	O
.	O
</s>
<s>
Note	O
that	O
there	O
are	O
two	O
ways	O
in	O
which	O
XML	B-Protocol
or	O
JSON	B-General_Concept
data	O
can	O
be	O
stored	O
:	O
one	O
way	O
is	O
to	O
store	O
it	O
as	O
a	O
plain	O
string	O
,	O
opaque	O
to	O
the	O
database	O
server	O
;	O
the	O
other	O
way	O
is	O
to	O
use	O
a	O
database	O
server	O
that	O
can	O
"	O
see	O
into	O
"	O
the	O
structure	O
.	O
</s>
<s>
Building	O
an	O
application	O
that	O
has	O
to	O
manage	O
data	O
gets	O
extremely	O
complicated	O
when	O
using	O
EAV	B-General_Concept
models	I-General_Concept
,	O
because	O
of	O
the	O
extent	O
of	O
infrastructure	O
that	O
has	O
to	O
be	O
developed	O
in	O
terms	O
of	O
metadata	O
tables	O
and	O
application-framework	O
code	O
.	O
</s>
<s>
Using	O
XML	B-Protocol
solves	O
the	O
problem	O
of	O
server-based	O
data	O
validation	O
(	O
which	O
must	O
be	O
done	O
by	O
middle-tier	O
and	O
browser-based	O
code	O
in	O
EAV-based	O
frameworks	O
)	O
,	O
but	O
has	O
the	O
following	O
drawbacks	O
:	O
</s>
<s>
XML	B-Protocol
schemas	O
are	O
notoriously	O
tricky	O
to	O
write	O
by	O
hand	O
,	O
a	O
recommended	O
approach	O
is	O
to	O
create	O
them	O
by	O
defining	O
relational	O
tables	O
,	O
generating	O
XML-schema	O
code	O
,	O
and	O
then	O
dropping	O
these	O
tables	O
.	O
</s>
<s>
Because	O
the	O
validation-associated	O
metadata	O
is	O
required	O
to	O
be	O
stored	O
in	O
multiple	O
relational	O
tables	O
in	O
a	O
normalized	O
design	O
,	O
a	O
GUI	O
application	O
that	O
ties	O
these	O
tables	O
together	O
and	O
enforces	O
the	O
appropriate	O
metadata-consistency	O
checks	O
is	O
the	O
only	O
practical	O
way	O
to	O
allow	O
entry	O
of	O
attribute	O
information	O
,	O
even	O
for	O
advanced	O
developers	O
-	O
even	O
if	O
the	O
end-result	O
uses	O
XML	B-Protocol
or	O
JSON	B-General_Concept
instead	O
of	O
separate	O
relational	O
tables	O
.	O
</s>
<s>
The	O
server-based	O
diagnostics	O
that	O
result	O
with	O
an	O
XML/JSON	O
solution	O
if	O
incorrect	O
data	O
is	O
attempted	O
to	O
be	O
inserted	O
(	O
e.g.	O
,	O
range	O
check	O
or	O
regular-expression	O
pattern	O
violations	O
)	O
are	O
cryptic	O
to	O
the	O
end-user	O
:	O
to	O
convey	O
the	O
error	O
accurately	O
,	O
one	O
would	O
,	O
at	O
the	O
least	O
,	O
need	O
to	O
associate	O
a	O
detailed	O
and	O
user-friendly	O
error	O
diagnostic	O
with	O
each	O
attribute	O
.	O
</s>
<s>
Sarka	O
's	O
work	O
,	O
however	O
,	O
proves	O
the	O
viability	O
of	O
using	O
an	O
XML	B-Protocol
field	O
instead	O
of	O
type-specific	O
relational	O
EAV	O
tables	O
for	O
the	O
data-storage	O
layer	O
,	O
and	O
in	O
situations	O
where	O
the	O
number	O
of	O
attributes	O
per	O
entity	O
is	O
modest	O
(	O
e.g.	O
,	O
variable	O
product	O
attributes	O
for	O
different	O
product	O
types	O
)	O
the	O
XML-based	O
solution	O
is	O
more	O
compact	O
than	O
an	O
EAV-table-based	O
one	O
.	O
</s>
<s>
(	O
XML	B-Protocol
itself	O
may	O
be	O
regarded	O
as	O
a	O
means	O
of	O
attribute	B-Application
–	I-Application
value	I-Application
data	O
representation	O
,	O
though	O
it	O
is	O
based	O
on	O
structured	O
text	O
rather	O
than	O
on	O
relational	O
tables	O
.	O
)	O
</s>
<s>
There	O
exist	O
several	O
other	O
approaches	O
for	O
the	O
representation	O
of	O
tree-structured	O
data	O
,	O
be	O
it	O
XML	B-Protocol
,	O
JSON	B-General_Concept
or	O
other	O
formats	O
,	O
such	O
as	O
the	O
nested	O
set	O
model	O
,	O
in	O
a	O
relational	B-Application
database	I-Application
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
database	O
vendors	O
have	O
begun	O
to	O
include	O
JSON	B-General_Concept
and	O
XML	B-Protocol
support	O
into	O
their	O
data	O
structures	O
and	O
query	O
features	O
,	O
like	O
in	O
IBM	B-Application
Db2	I-Application
,	O
where	O
XML	B-Protocol
data	O
is	O
stored	O
as	O
XML	B-Protocol
separate	O
from	O
the	O
tables	O
,	O
using	O
XPath	B-Language
queries	O
as	O
part	O
of	O
SQL	O
statements	O
,	O
or	O
in	O
PostgreSQL	B-Application
,	O
with	O
a	O
JSON	B-General_Concept
data	O
type	O
that	O
can	O
be	O
indexed	O
and	O
queried	O
.	O
</s>
<s>
These	O
developments	O
accomplish	O
,	O
improve	O
or	O
substitute	O
the	O
EAV	B-General_Concept
model	I-General_Concept
approach	O
.	O
</s>
<s>
The	O
uses	O
of	O
JSON	B-General_Concept
and	O
XML	B-Protocol
are	O
not	O
necessarily	O
the	O
same	O
as	O
the	O
use	O
of	O
an	O
EAV	B-General_Concept
model	I-General_Concept
,	O
though	O
they	O
can	O
overlap	O
.	O
</s>
<s>
XML	B-Protocol
is	O
preferable	O
to	O
EAV	O
for	O
arbitrarily	O
hierarchical	O
data	O
that	O
is	O
relatively	O
modest	O
in	O
volume	O
for	O
a	O
single	O
entity	O
:	O
it	O
is	O
not	O
intended	O
to	O
scale	O
up	O
to	O
the	O
multi-gigabyte	O
level	O
with	O
respect	O
to	O
data-manipulation	O
performance	O
.	O
</s>
<s>
XML	B-Protocol
is	O
not	O
concerned	O
per-se	O
with	O
the	O
sparse-attribute	O
problem	O
,	O
and	O
when	O
the	O
data	B-Application
model	I-Application
underlying	O
the	O
information	O
to	O
be	O
represented	O
can	O
be	O
decomposed	O
straightforwardly	O
into	O
a	O
relational	O
structure	O
,	O
XML	B-Protocol
is	O
better	O
suited	O
as	O
a	O
means	O
of	O
data	O
interchange	O
than	O
as	O
a	O
primary	O
storage	O
mechanism	O
.	O
</s>
<s>
When	O
such	O
a	O
scenario	O
holds	O
,	O
the	O
use	O
of	O
datatype-specific	O
attribute	B-Application
–	I-Application
value	I-Application
tables	O
that	O
can	O
be	O
indexed	O
by	O
entity	O
,	O
by	O
attribute	O
,	O
and	O
by	O
value	O
and	O
manipulated	O
through	O
simple	O
SQL	O
statements	O
is	O
vastly	O
more	O
scalable	O
than	O
the	O
use	O
of	O
an	O
XML	B-Protocol
tree	O
structure	O
.	O
</s>
<s>
An	O
alternative	O
approach	O
to	O
managing	O
the	O
various	O
problems	O
encountered	O
with	O
EAV-structured	O
data	O
is	O
to	O
employ	O
a	O
graph	B-Application
database	I-Application
.	O
</s>
<s>
The	O
issue	O
of	O
table	O
joins	O
are	O
addressed	O
by	O
providing	O
graph-specific	O
query	O
languages	O
,	O
such	O
as	O
Apache	B-Application
TinkerPop	O
,	O
or	O
the	O
OpenCog	B-Application
atomspace	O
pattern	O
matcher	O
.	O
</s>
<s>
Another	O
alternative	O
is	O
to	O
use	O
SPARQL	B-Language
store	O
.	O
</s>
<s>
PostgreSQL	B-Application
version	O
9.4	O
includes	O
support	O
for	O
JSON	B-General_Concept
binary	O
columns	O
(	O
JSONB	O
)	O
,	O
which	O
can	O
be	O
queried	O
,	O
indexed	O
and	O
joined	O
.	O
</s>
<s>
A	O
DB	O
schema	O
based	O
on	O
JSONB	O
always	O
has	O
fewer	O
tables	O
:	O
one	O
may	O
nest	O
attribute	B-Application
–	I-Application
value	I-Application
pairs	I-Application
in	O
JSONB	O
type	O
fields	O
of	O
the	O
Entity	O
table	O
.	O
</s>
<s>
Sparse	O
columns	O
optimize	O
the	O
storage	O
of	O
NULL	B-Language
values	O
(	O
which	O
now	O
take	O
up	O
no	O
space	O
at	O
all	O
)	O
and	O
are	O
useful	O
when	O
the	O
majority	O
records	O
in	O
a	O
table	O
will	O
have	O
NULL	B-Language
values	O
for	O
that	O
column	O
.	O
</s>
<s>
In	O
addition	O
,	O
the	O
contents	O
of	O
all	O
sparse	O
columns	O
in	O
a	O
particular	O
row	O
of	O
a	O
table	O
can	O
be	O
collectively	O
aggregated	O
into	O
a	O
single	O
XML	B-Protocol
column	O
(	O
a	O
column	O
set	O
)	O
,	O
whose	O
contents	O
are	O
of	O
the	O
form	O
[xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1]*....	O
</s>
<s>
This	O
has	O
the	O
interesting	O
consequence	O
that	O
the	O
SQL	O
statement	O
SELECT	O
*	O
from	O
<tablename>	O
will	O
not	O
return	O
the	O
individual	O
sparse	O
columns	O
,	O
but	O
concatenate	O
all	O
of	O
them	O
into	O
a	O
single	O
XML	B-Protocol
column	O
whose	O
name	O
is	O
that	O
of	O
the	O
column	O
set	O
(	O
which	O
therefore	O
acts	O
as	O
a	O
virtual	O
,	O
computed	O
column	O
)	O
.	O
</s>
<s>
Addition	O
of	O
new	O
attributes	O
–	O
one	O
of	O
the	O
primary	O
reasons	O
an	O
EAV	B-General_Concept
model	I-General_Concept
might	O
be	O
sought	O
–	O
still	O
requires	O
a	O
DBA	O
.	O
</s>
<s>
Many	O
cloud	B-Architecture
computing	I-Architecture
vendors	O
offer	O
data	O
stores	O
based	O
on	O
the	O
EAV	B-General_Concept
model	I-General_Concept
,	O
where	O
an	O
arbitrary	O
number	O
of	O
attributes	O
can	O
be	O
associated	O
with	O
a	O
given	O
entity	O
.	O
</s>
<s>
Google	O
lets	O
you	O
operate	O
on	O
the	O
data	O
using	O
a	O
subset	O
of	O
SQL	O
;	O
Microsoft	O
offer	O
a	O
URL-based	O
querying	O
syntax	O
that	O
is	O
abstracted	O
via	O
a	O
LINQ	B-Language
provider	O
;	O
Amazon	O
offer	O
a	O
more	O
limited	O
syntax	O
.	O
</s>
<s>
An	O
EAV	O
approach	O
is	O
justified	O
only	O
when	O
the	O
attributes	O
that	O
are	O
being	O
modeled	O
are	O
numerous	O
and	O
sparse	O
:	O
if	O
the	O
data	O
being	O
captured	O
does	O
not	O
meet	O
this	O
requirement	O
,	O
the	O
cloud	B-Architecture
vendors	I-Architecture
 '	O
default	O
EAV	O
approach	O
is	O
often	O
a	O
mismatch	O
for	O
applications	O
that	O
require	O
a	O
true	O
back-end	O
database	O
(	O
as	O
opposed	O
to	O
merely	O
a	O
means	O
of	O
persistent	O
data	O
storage	O
)	O
.	O
</s>
