Stored and Inherited Relations in Relational Databases

Natural Stored and Inherited
Relations
Witold Litwin
 Dauphine University
Witold.litwin@dauphine.psl.eu
Presentation at  EUSPN/ICTH 2021, Leuven, Belgium.
What’s Up ?
Presumably, everyone in this room is
familiar with some SQL DBS
A typical scheme of a stored relation
(SR), say R, with foreign keys is not only
what you were all told it is
 I.e., defines SR R only
It defines in fact a 
natural
 Stored and
Inherited Relation (SIR) R.
 
 
What’s Up ?
A typical query formulating as select-
project-join one to R, with joins being
equijoins over foreign and referenced
keys, formulates as select-project one
only to SIR R
The 
logical navigation free 
(LNF) query
to R in popular terms
 
 
I
s It Important?
LNF queries are substantially less
procedural in practice
There is no any additional data
definition work for the DBA
An old dream for the relational DBs
becomes true
 
 
What’s Up
We recall what SIRs are in general
We define 
natural 
SIRs
We show how the scheme of a
typical SR R with foreign keys
implicitly defines also natural SIR R
 On a 
SIR-enabled
 (relational) DBS
5
 
What’s Up
We outline how to make a popular DBS
SIR-enabled
We show that this could be  simple
We postulate that every major DBS
should become SIR-enabled “better
sooner than later”.
 
6
 
Present Foundations of RDBs
Relational database (DB) technology
is the core for any modern
databases:
 Client, Web, Cloud, Big Data…
 You name it
There are millions of relational DBs
around
7
 
Stored and Inherited Relation
 (SIR)
A (relational) DB consists at present from:
Some 
stored relations
 (SRs) with 
stored
attributes
 (SAs) only, also called 
base tables
 One cannot  calculate SA values from the DB
scheme
 Optionally, - also from 
views
 
With 
inherited attributes
 (IAs) only
IA-values calculate from the view scheme
Basically, calculate 
only
8
 
Stored and Inherited Relation
 (SIR)
A SIR R is an SR R enlarged with some IAs
 Every SR R tuple becomes sub-tuple of exactly
one SIR R tuple
 SIR R does not have any other tuples
 IAs calculate as if they were in view R defining
logically the same relation as SIR R
 Termed C-view R
IAs in a SIR form an 
Inheritance Expression
 (IE)
SR R may be, by default, referred to as R_  in SIR
R
As well as in C-view R scheme
[1] Litwin, W. SQL for Stored and Inherited Relations. 21
st
 Intl. Conf. on Enterprise Information Systems,
(ICEIS 2019), 
http://www.iceis.org/?y=2019
 , 12p.
9
 
Motivating Example : Codd’s ‘biblical’ S-P DB
 
10
 
 
S-P1 Scheme
Table S
  
Table P
   
Table SP
S#
  Char, 
  
P#
 Char,
   
S#
 Char,
SNAME Char,
 
PNAME Char,
  
P#
 Char,
STATUS Char,
 
COLOR  Char,              
 
QTY Int,  
CITY Char;                        WEIGHT Char,                      
 
 
 
 
Motivating Example : Codd’s ‘biblical’ S-P DB
 
11
 
 
S-P1 Scheme
Table S
  
Table P
   
Table SP
S#
  Char, 
  
P#
 Char,
   
S#
 Char,
SNAME Char,
 
PNAME Char,
  
P#
 Char,
STATUS Char,
 
COLOR  Char,              
 
QTY Int,  
CITY Char;                        WEIGHT Char,                      
 
 
 
 
SP
.
S# and SP.P# are 
foreign keys
 
Althougt
 none is a key of SP
S.S# and P.P# are
 referenced keys
These are primary keys
Motivating Example : Foreign Keys
 
12
 
 
Consider e.g., the query Q: select every
SNAME, QTY, PNAME where QTY < 300
SQL formulations of Q make sense only
because of the foreign keys.
Example
Suppose now S-P.SP SQL scheme as follows:
 
Create Table SP (S# Char 5, P# Char 5
, 
QTY INT,
Primary Key (S#, P#));
One may enlarge it to SIR SP with 
IE
 as follows:
Create Table SP (S# Char 5 
{SNAME, STATUS, S.CITY}
 
P# Char
5
 
{PNAME, COLOR, WEIGHT, P.CITY}
 QTY INT 
{From SP_ Left
Join S On (SP_.S# = S.S#) LEFT JOIN P On (SP_.P# = P.P#)}
Primary Key (S#, P#));
SP_ designates by default S-P.SP above
{ }
  are brackets around parts of the IE
Make SIRs simpler to implement
IE is 
red 
and 
Italic
 
for didactic purpose only
13
 
Example
Create Table SP (S# Char 5 
{SNAME, STATUS, S.CITY}
 
P# Char
5
 
{PNAME, COLOR, WEIGHT, P.CITY}
 QTY INT 
{From SP_ Left
Join S On (SP_.S# = S.S#) LEFT JOIN P On (SP_.P# = P.P#)}
Primary Key (S#, P#));
SIR SP is mathematically the same as C-view SP:
Create View SP AS Select SP_.S#, 
SNAME, STATUS, S.CITY,
SP_.P#, 
PNAME, COLOR, WEIGHT, P.CITY, 
QTY 
From SP_ Left
Join S On (SP_.S# = S.S#) LEFT JOIN P On SP_.P# = P.P#
;
o
SP_
 designates 
S-P.SP renamed so by default
o
From now on, S-P1 designates S-P with SIR SP
14
 
S-P1 DB with SIR SP
IA names and value are Italic
S-P2 Content
Table S 
     
Table P
S#
 
SNAME
 
STATUS 
 
CITY
  
P#      PNAME  COLOR    WEIGHT   CITY 
S1    
 
Smith
 
20
 
London
  
P1      Nut
 
    Red
 
12           Lon<don
S2
 
Jones
 
10
 
Paris
  
P2      Bolt
 
    Green
 
17           Paris
S3
 
Blake
 
30
 
Paris
  
P3     Screw 
 
     Blue
 
17            Oslo
S4
 
Clark
 
20
 
London
  
P4     Screw
 
     Red
 
14            London
S5
 
Adams
 
30 
 
Athens
  
P5     Cam
 
     Blue
 
12            Paris
 
     
P6     Cog
 
     Red
 
19            London
Table SP
S#
 
SNAMES
 
STATUS  
 
S.CITY      
 
P#
 
PNAME    COLOR   WEIGHT       P.CITY
 
 
    QTY
 
S1
 
Smith    
  
 
20
 
London   
 
P1
 
 Nut            Red          12
 
         London
 
    
300  
 
S1
 
Smith 
            
20
 
London    
 
P2
 
 Bolt           Green       17
 
         Paris         
200  
 
S1
 
 Smith      
 
20
 
London 
 
P3
 
 Screw        Blue          17
 
         Oslo 
 
    
400
S1
 
 Smith      
 
20
 
London 
 
P4 
 
 Screw        Red           14
 
         Londo
n     200  
 
S1
 
 Smith           20
 
London 
 
P5
 
Cam           Blue           12   
 
         Paris         
100
S1
 
 Smith           20
 
London 
 
P6
 
 Cog            Red           19
 
         London     
100
S2
 
 Jones      
 
10
 
 
Paris 
 
P1
 
Nut             Red            12
 
         London
     300  
 
 
S2
 
Jones             10          
         
Paris 
 
P2 
 
Bolt            Green        17
 
         Paris
          400 
S3
 
Blake      
 
30
 
 
Paris 
 
P2 
 
Bolt            Green        17
 
         Paris          
200 
S4
 
Clark      
 
20
 
London 
 
P2 
 
Bolt            Green        17
 
         Paris
          200 
S4
 
Clark      
 
20
 
London 
 
P4 
 
Screw         Red           14
 
         London
      300 
S4
 
Clark      
 
20                  London 
 
P5 
 
Cam           Blue          12             Paris
           400 
 
15
S-P DB with view SP
View SP
S#
 
SNAMES
 
STATUS  
 
S.CITY      
 
P#
 
PNAME    COLOR   WEIGHT       P.CITY 
 
    QTY
 
S1
 
Smith      
 
20
 
London   
 
P1
 
 Nut            Red          12
 
         London
 
    300  
 
S1
 
Smith             20
 
London    
 
P2
 
 Bolt           Green       17
 
         Paris         200  
 
S1
 
 Smith      
 
20
 
London 
 
P3
 
 Screw        Blue          17
 
         Oslo 
 
    400
S1
 
 Smith      
 
20
 
London 
 
P4 
 
 Screw        Red           14
 
         London     200  
 
S1
 
 Smith           20
 
London 
 
P5
 
Cam           Blue           12   
 
         Paris         100
S1
 
 Smith           20
 
London 
 
P6
 
 Cog            Red           19
 
         London     100
S2
 
 Jones      
 
10
 
Paris 
 
P1
 
Nut             Red            12
 
         London     300  
 
 
S2
 
Jones             10                   Paris 
 
P2 
 
Bolt            Green        17
 
         Paris          400 
S3
 
Blake      
 
30
 
Paris 
 
P2 
 
Bolt            Green        17
 
         Paris          200 
S4
 
Clark      
 
20
 
London 
 
P2 
 
Bolt            Green        17
 
         Paris          200 
S4
 
Clark      
 
20
 
London 
 
P4 
 
Screw         Red           14
 
         London      300 
S4
 
Clark      
 
20                  London 
 
P5 
 
Cam           Blue          12             Paris           400
 
16
SP
_
Why View SP for S-P ?
Our query Q to S-P with base tables only,
formulates as SQL select-project-join query:
Select SNAME, QTY, PNAME  
From SP Left Join S
On (SP.S# = S.S#) Left Join P On (SP.P# = P.P#
)
Where QTY < 300;
In 
red
 there is the 
logical navigation 
(LN) over S, SP
and P
Left joins are necessary since, basically,  there is no
referential integrity in S-P
17
 
Why View SP for S-P ?
With view SP used instead of S-P.SP, Q
formulates as the LNF SQL select-project:
Select 
SNAME
, 
QTY, PNAME
 
Where 
QTY
 
<
300 From SP;
Substantially less procedural formulation
 Fewer mandatory characters to type-in
18
 
Why SIR SP Instead of view SP ?
Given S-P1.SP instead of view SP in S-P, Q
would be:
Select 
SNAME
, 
QTY
, 
PNAME
 
Where QTY < 300
From SP;
Same thus except that QTY is an SA and SP is
a SIR
Who cares ?
19
 
Why SIR SP instead of View SP ?
IE
 in SIR SP is 
less procedural
 than view SP
 112 mandatory characters instead of 157
 Procedurality (so time) gain of almost 30 %
(157 – 112) / 157
 
Non-procedurality was a driving force for
Database Science
o
 For the relational model / Codasyl model in
particular
 For entire Computer Science, in fact
20
 
Can We Do Better ?
How far can we reduce the procedurality of IE
for SP scheme ?
Hurray! Typically to ZERO
   
Create Table SP  for SR SP
 
 may indeed suffice
as an 
implicit
 Create Table SP for SIR SP
 By inferring from it the 
explicit
 Create Table
SP for SIR SP
With every IA and From clause
21
 
How ?
E
very
 foreign key
 implicitly inherits as an
IA every non-key attribute of the
referenced relation
 With the same proper name and same
value for the same key value
In the nutshell, this usually defines for an
SR R with foreign keys its 
natural 
SIR R
Our SP is the natural SP (for SR SP and SP_)
22
 
How ?
Our implicit natural SIR SP scheme is the one of S-P.SP:
Create Table SP (S# Char 5, P# Char 5
, 
QTY INT, Primary Key
(S#, P#));
Our explicit natural SIR SP scheme is the example one:
Create Table SP (S# Char 5 
{SNAME, STATUS, S.CITY}
 
P# Char 5
{PNAME, COLOR, WEIGHT, P.CITY}
 QTY INT 
{From SP_ Left Join S On
(SP_.S# = S.S#) LEFT JOIN P On (SP_.P# = P.P#)}
 
Primary Key (S#, P#));
One can infer 
IAs
 from SYSTABLES of any popular DBS
See (easy) rules in the paper
23
 
SIR-enabled DBS
SIR-layer manages all SIRs
Internally calls existing (kernel) SQL
DBS (not SIR-enabled)
SP defined as presently, canonically
becomes internally
 Base table SP_ (S#, P#, QTY)
 C-view SP formed from 
{….}
 SIR-layer canonically directs every
(select) query to C-view SP
 Discussed 
LNF-queries
 are OK
 
24
SIR-layer
Kernel
SQL DBS
SIR-enabled DBS
Conclusion
 “Better late than never”, every DBS should
become SIR-enabled
 Able to manage natural SIRs
 
LNF queries should become a standard
 Queries with LN: – an exception
 For advanced clients
 Or in bad dream from the past
  
There are other benefits from SIRs we did
not speak about
  See the referenced papers
 
25
Conclusion
 
Likely, millions of DBAs,
clients developers… should
benefit from SIR-enabled
relational DBSs
 
26
Thanks
For
Your  Attention
            Witold LITWIN
  
      
Witold.litwin@dauphine.psl.eu
 
27
Slide Note
Embed
Share

Explore the concept of Stored and Inherited Relations (SIR) in relational databases, as discussed by Witold Litwin at Dauphine University. Discover how a typical scheme of a stored relation defines a natural SIR, leading to more efficient query formulations and less procedural querying processes. Learn about the importance of SIR-enabled databases and the role they play in modern database technology.

  • Relational Databases
  • Stored Relations
  • Inherited Attributes
  • Query Optimization
  • Database Technology

Uploaded on Sep 15, 2024 | 1 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Natural Stored and Inherited Relations Witold Litwin Dauphine University Witold.litwin@dauphine.psl.eu Presentation at EUSPN/ICTH 2021, Leuven, Belgium.

  2. Whats Up ? Presumably, everyone in this room is familiar with some SQL DBS A typical scheme of a stored relation (SR), say R, with foreign keys is not only what you were all told it is I.e., defines SR R only It defines in fact a natural Stored and Inherited Relation (SIR) R.

  3. Whats Up ? A typical query formulating as select- project-join one to R, with joins being equijoins over foreign and referenced keys, formulates as select-project one only to SIR R The logical navigation free (LNF) query to R in popular terms

  4. Is It Important? LNF queries are substantially less procedural in practice There is no any additional data definition work for the DBA An old dream for the relational DBs becomes true

  5. Whats Up We recall what SIRs are in general We define natural SIRs We show how the scheme of a typical SR R with foreign keys implicitly defines also natural SIR R On a SIR-enabled (relational) DBS 5

  6. Whats Up We outline how to make a popular DBS SIR-enabled We show that this could be simple We postulate that every major DBS should become SIR-enabled better sooner than later . 6

  7. Present Foundations of RDBs Relational database (DB) technology is the core for any modern databases: Client, Web, Cloud, Big Data You name it There are millions of relational DBs around 7

  8. Stored and Inherited Relation (SIR) A (relational) DB consists at present from: Some stored relations (SRs) with stored attributes (SAs) only, also called base tables One cannot calculate SA values from the DB scheme Optionally, - also from views With inherited attributes (IAs) only IA-values calculate from the view scheme Basically, calculate only 8

  9. Stored and Inherited Relation (SIR) A SIR R is an SR R enlarged with some IAs Every SR R tuple becomes sub-tuple of exactly one SIR R tuple SIR R does not have any other tuples IAs calculate as if they were in view R defining logically the same relation as SIR R Termed C-view R IAs in a SIR form an Inheritance Expression (IE) SR R may be, by default, referred to as R_ in SIR R As well as in C-view R scheme [1] Litwin, W. SQL for Stored and Inherited Relations. 21stIntl. Conf. on Enterprise Information Systems, (ICEIS 2019), http://www.iceis.org/?y=2019 , 12p. 9

  10. Motivating Example : Codds biblical S-P DB S-P1 Scheme Table S Table P Table SP S# Char, SNAME Char, STATUS Char, CITY Char; P# Char, PNAME Char, COLOR Char, WEIGHT Char, S# Char, P# Char, QTY Int, 10

  11. Motivating Example : Codds biblical S-P DB S-P1 Scheme Table S Table P Table SP S# Char, SNAME Char, STATUS Char, CITY Char; P# Char, PNAME Char, COLOR Char, WEIGHT Char, S# Char, P# Char, QTY Int, SP.S# and SP.P# are foreign keys Althougt none is a key of SP S.S# and P.P# are referenced keys These are primary keys 11

  12. Motivating Example : Foreign Keys Consider e.g., the query Q: select every SNAME, QTY, PNAME where QTY < 300 SQL formulations of Q make sense only because of the foreign keys. 12

  13. Example Suppose now S-P.SP SQL scheme as follows: Create Table SP (S# Char 5, P# Char 5, QTY INT, Primary Key (S#, P#)); One may enlarge it to SIR SP with IE as follows: Create Table SP (S# Char 5 {SNAME, STATUS, S.CITY} P# Char 5 {PNAME, COLOR, WEIGHT, P.CITY} QTY INT {From SP_ Left Join S On (SP_.S# = S.S#) LEFT JOIN P On (SP_.P# = P.P#)} Primary Key (S#, P#)); SP_ designates by default S-P.SP above { } are brackets around parts of the IE Make SIRs simpler to implement IE is red and Italic for didactic purpose only 13

  14. Example Create Table SP (S# Char 5 {SNAME, STATUS, S.CITY} P# Char 5 {PNAME, COLOR, WEIGHT, P.CITY} QTY INT {From SP_ Left Join S On (SP_.S# = S.S#) LEFT JOIN P On (SP_.P# = P.P#)} Primary Key (S#, P#)); SIR SP is mathematically the same as C-view SP: Create View SP AS Select SP_.S#, SNAME, STATUS, S.CITY, SP_.P#, PNAME, COLOR, WEIGHT, P.CITY, QTY From SP_ Left Join S On (SP_.S# = S.S#) LEFT JOIN P On SP_.P# = P.P#; o SP_ designates S-P.SP renamed so by default o From now on, S-P1 designates S-P with SIR SP 14

  15. S-P1 DB with SIR SP IA names and value are Italic S-P2 Content Table S S# S1 S2 S3 S4 S5 Table P P# PNAME COLOR WEIGHT CITY P1 Nut Red P2 Bolt Green P3 Screw Blue P4 Screw Red P5 Cam Blue P6 Cog Red SNAME Smith Jones Blake Clark Adams STATUS 20 10 30 20 30 CITY London Paris Paris London Athens 12 17 Paris 17 Oslo 14 London 12 Paris 19 London Lon<don Table SP S# S1 S1 S1 S1 S1 S1 S2 S2 S3 S4 S4 S4 SNAMES Smith Smith Smith Smith Smith Smith Jones Jones 10 Blake Clark Clark Clark STATUS 20 20 20 20 20 20 10 S.CITY London London London London London London Paris Paris Paris London London P# P1 P2 P3 P4 P5 P6 P1 P2 P2 P2 P4 P5 PNAME COLOR WEIGHT P.CITY Nut Red 12 Bolt Green 17 Screw Blue 17 Screw Red 14 Cam Blue 12 Cog Red Nut Red 12 Bolt Green 17 Bolt Green 17 Bolt Green 17 Screw Red 14 Cam Blue 12 QTY 300 London Paris 200 Oslo London 200 Paris 100 London 100 London Paris Paris 200 Paris London Paris 400 19 300 400 30 20 20 20 London 200 300 400 15

  16. S-P DB with view SP SP_ View SP S# S1 S1 S1 S1 S1 S1 S2 S2 S3 S4 S4 S4 SNAMES Smith Smith 20 Smith Smith Smith 20 Smith 20 Jones Jones 10 Paris Blake 30 Clark 20 Clark 20 Clark 20 London STATUS 20 S.CITY London London London London London London Paris P# P1 P2 P3 P4 P5 P6 P1 P2 P2 P2 P4 P5 PNAME COLOR WEIGHT P.CITY Nut Red 12 Bolt Green 17 Screw Blue 17 Screw Red 14 Cam Blue 12 Cog Red 19 Nut Red 12 Bolt Green 17 Bolt Green 17 Bolt Green 17 Screw Red 14 Cam Blue 12 Paris 400 QTY 300 London Paris 200 Oslo London 200 Paris 100 London 100 London 300 Paris 400 Paris 200 Paris 200 London 300 20 20 400 10 Paris London London 16

  17. Why View SP for S-P ? Our query Q to S-P with base tables only, formulates as SQL select-project-join query: Select SNAME, QTY, PNAME From SP Left Join S On (SP.S# = S.S#) Left Join P On (SP.P# = P.P#) Where QTY < 300; In red there is the logical navigation (LN) over S, SP and P Left joins are necessary since, basically, there is no referential integrity in S-P 17

  18. Why View SP for S-P ? With view SP used instead of S-P.SP, Q formulates as the LNF SQL select-project: Select SNAME, QTY, PNAME Where QTY < 300 From SP; Substantially less procedural formulation Fewer mandatory characters to type-in 18

  19. Why SIR SP Instead of view SP ? Given S-P1.SP instead of view SP in S-P, Q would be: Select SNAME, QTY, PNAME Where QTY < 300 From SP; Same thus except that QTY is an SA and SP is a SIR Who cares ? 19

  20. Why SIR SP instead of View SP ? IE in SIR SP is less procedural than view SP 112 mandatory characters instead of 157 Procedurality (so time) gain of almost 30 % (157 112) / 157 Non-procedurality was a driving force for Database Science o For the relational model / Codasyl model in particular For entire Computer Science, in fact 20

  21. Can We Do Better ? How far can we reduce the procedurality of IE for SP scheme ? Hurray! Typically to ZERO Create Table SP for SR SP may indeed suffice as an implicit Create Table SP for SIR SP By inferring from it the explicit Create Table SP for SIR SP With every IA and From clause 21

  22. How ? Every foreign key implicitly inherits as an IA every non-key attribute of the referenced relation With the same proper name and same value for the same key value In the nutshell, this usually defines for an SR R with foreign keys its natural SIR R Our SP is the natural SP (for SR SP and SP_) 22

  23. How ? Our implicit natural SIR SP scheme is the one of S-P.SP: Create Table SP (S# Char 5, P# Char 5, QTY INT, Primary Key (S#, P#)); Our explicit natural SIR SP scheme is the example one: Create Table SP (S# Char 5 {SNAME, STATUS, S.CITY} P# Char 5 {PNAME, COLOR, WEIGHT, P.CITY} QTY INT {From SP_ Left Join S On (SP_.S# = S.S#) LEFT JOIN P On (SP_.P# = P.P#)} Primary Key (S#, P#)); One can infer IAs from SYSTABLES of any popular DBS See (easy) rules in the paper 23

  24. SIR-enabled DBS SIR-layer manages all SIRs Internally calls existing (kernel) SQL DBS (not SIR-enabled) SP defined as presently, canonically becomes internally Base table SP_ (S#, P#, QTY) C-view SP formed from { .} SIR-layer canonically directs every (select) query to C-view SP Discussed LNF-queries are OK SIR-enabled DBS SIR-layer Kernel SQL DBS 24

  25. Conclusion Better late than never , every DBS should become SIR-enabled Able to manage natural SIRs LNF queries should become a standard Queries with LN: an exception For advanced clients Or in bad dream from the past There are other benefits from SIRs we did not speak about See the referenced papers 25

  26. Conclusion Likely, millions of DBAs, clients developers should benefit from SIR-enabled relational DBSs 26

  27. Thanks For Your Attention Witold LITWIN Witold.litwin@dauphine.psl.eu 27

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#