Post on 26-Dec-2015
transcript
Extensibility Tricks Extensibility Tricks and Tipsand Tips
Paul BrownChief Plumber
INFORMIX Software
2
useruser .conference.conferenceInformixInformix
What we will talk about:What we will talk about:
• Three Common Problems• Parts explosion or bill of materials
• Dynamic SQL in stored procedures
• Temporal data and temporal SQL
• Solutions Using OR Techniques• Explanation: How each solution works
• Demo: What each solution looks like
• Software: Where you can get it
• Notes on Philosophy• What this says about how to use OR technology
• Three Common Problems• Parts explosion or bill of materials
• Dynamic SQL in stored procedures
• Temporal data and temporal SQL
• Solutions Using OR Techniques• Explanation: How each solution works
• Demo: What each solution looks like
• Software: Where you can get it
• Notes on Philosophy• What this says about how to use OR technology
useruser .conference.conferenceInformixInformix
Parts Explosion/ Bill of MaterialsParts Explosion/ Bill of Materials
The ProblemThe Problem• Parts table, parent part columnParts table, parent part column
• ““How many parts in part X?” How many parts in part X?” style queriesstyle queries
• Only solution involves Only solution involves ‘walking’ the hierarchy in ‘walking’ the hierarchy in middle-ware or in an iterative middle-ware or in an iterative joinjoin
Relational SolutionRelational Solution• “Walk” the hierarchy
• Slow, cumbersome, code intensive
• Implementing acyclic constraint constraint very difficult
IdId P_IdP_Id NameName
DoorHingePanelLock
Frame6” Screw
JointDoor Knob
Lock4” Screw
1122334455667788991010
ØØ111111112222444444
1
2 3 4 5
6 7 8 9 10
useruser .conference.conferenceInformixInformix
Object-Relational SolutionObject-Relational Solution
Graph Theory Trick:Graph Theory Trick:• “Node” data type {“N.N.N.N”}
• Mathematical operators { <, <=, =, =>, > }
• Single method Incr()
Incr(N.N.N) = N.N.(N+1);
Implement as UDT:• Use B-tree to index Ids
• Primary key prevents cyclicity
• “How many parts make up the Lock?” query shown.
IdId NameName
DoorHingePanelLock
Frame6” Screw
JointDoor Knob
4” Screw
1.01.01.11.11.21.21.31.31.41.4
1.1.11.1.11.1.21.1.21.3.11.3.11.3.21.3.21.3.31.3.3
1.0
1.1 1.2 1.3 1.4
1.1.1 1.1.2 1.3.1 1.3.2 1.3.3
SELECT COUNT(*)
FROM Parts P1,
Parts P2
WHERE P1.Name = “Lock”
AND
( P2.Id BETWEEN P1.Id
AND Incr ( P1.Id )
);
useruser .conference.conferenceInformixInformix
Performance studyPerformance study
Experimental results• Implemented as relational
• Implemented as object-relational
• 10 level deep hierarchy, 6 wide
• “How many objects under ‘1.2.3’?”
5.5 Million vs.5.5 Million vs.
27K BufReads27K BufReads
287 Secs vs 287 Secs vs
4 Secs4 Secs
SELECT COUNT(*) FROM TestTable T WHERE T.Node BETWEEN ‘1.2.3’ AND Incr(‘1.2.3’);CREATE FUNCTION Under( Arg1 INTEGER )
RETURNING INTEGER;
DEFINE nRetCount INTEGER;
DEFINE nRows INTEGER;
LET nRetCount = 0;
CREATE TEMP TABLE _Under_Temp_1 ( Id INTEGER NOT NULL );
CREATE TEMP TABLE _Under_Temp_2 ( Id INTEGER NOT NULL );
INSERT INTO _Under_Temp_1 SELECT Id FROM TestTable WHERE Parent = Arg1;
LET nRows = DFINFO('sqlca.sqlerrd2');
WHILE (nRows > 0)
LET nRetCount = nRetCount + nRows;
DELETE FROM _Under_Temp_2 WHERE 1 = 1;
INSERT INTO _Under_Temp_2 SELECT * FROM _Under_Temp_1;
DELETE FROM _Under_Temp_1 WHERE 1 = 1;
INSERT INTO _Under_Temp_1 SELECT T.Id FROM _Under_Temp_2 N,
TestTable T
WHERE N.Id = T.Parent;
LET nRows = DFINFO('sqlca.sqlerrd2');
END WHILE;
DROP TABLE _Under_Temp_1; DROP TABLE _Under_Temp_2;
RETURN nRetCount;
END FUNCTION;
0
200
400
Relational Object-Relational
0
2000000
4000000
6000000
Relational Object-Relational
7
useruser .conference.conferenceInformixInformix
Dynamic SQL in Stored ProceduresDynamic SQL in Stored Procedures
• One of the MRF ( Most Requested Features)• “Variable Table/Column Names Please”• Something other DBMS products have
• Workarounds Laborious: • SYSTEM ( “CREATE PROC”)• Do it in the external program (client or app server)
• Solution Points to Bigger Issue• Using Extensibility in SPL• Other Examples: Isplit()
• One of the MRF ( Most Requested Features)• “Variable Table/Column Names Please”• Something other DBMS products have
• Workarounds Laborious: • SYSTEM ( “CREATE PROC”)• Do it in the external program (client or app server)
• Solution Points to Bigger Issue• Using Extensibility in SPL• Other Examples: Isplit()
EXECUTE FUNCTION Isplit(“Hello World”, “ “);
Hello
World
8
useruser .conference.conferenceInformixInformix
Architectural ModelArchitectural Model
EXEC()
TableRowCnt (Tname VARCHAR)RETURNS INTEGER DEFINE nRetVal INTEGER; DEFINE lvQuery LVARCHAR; LET lvQuery = “SELECT COUNT(*) FROM “ || Tname || “;” LET nRetVal = EXEC( lvQuery); RETURN nRetVal;
(1) EXECUTE FUNCTION TableRowCount ( “Foo” );
(2) EXEC(“SELECT COUNT(*) FROM Foo;”)
(3) Run Query
9
useruser .conference.conferenceInformixInformix
DEMO DEMO
10
useruser .conference.conferenceInformixInformix
Time and T-SQLTime and T-SQLTime and T-SQLTime and T-SQL
• SQL-92 Has “Atomic” and “Floating” Time• DATE and DATETIME• INTERVAL
• Other Time Concepts• Period: Fixed interval in the time line• Hard because of “Overlap()” queries
• SQL-92 Has “Atomic” and “Floating” Time• DATE and DATETIME• INTERVAL
• Other Time Concepts• Period: Fixed interval in the time line• Hard because of “Overlap()” queries
Time Line
Overlaps (F, G)Contained( D, E)
Contains (E, D)
A
B
C
D
E
F
G
After ( C, B )Before ( A, B )
11
useruser .conference.conferenceInformixInformix
Why is this tricky?Why is this tricky?
• Query Expressions are Awkward• Query Expressions are Awkward
• Indexing is a Big Problem• B-Tree < End, Start > or B-Tree < Start, End >• For many queries, planner must scan
• Indexing is a Big Problem• B-Tree < End, Start > or B-Tree < Start, End >• For many queries, planner must scan
SELECT T.Train_Id FROM Train_Schedules T WHERE NOT ( ( T.End < :StartTime ) OR ( T.Start > :StopTime ) );
SELECT T.Train_Id FROM Train_Schedules T WHERE NOT ( ( T.End < :StartTime ) OR ( T.Start > :StopTime ) );
12
useruser .conference.conferenceInformixInformix
Time and T-SQL: ORDBMS SolutionTime and T-SQL: ORDBMS SolutionTime and T-SQL: ORDBMS SolutionTime and T-SQL: ORDBMS Solution
• Period and DT_Period as New Types• Set of UDFs { Overlap(), etc } for queries• R-Tree indexing support functions
• Period and DT_Period as New Types• Set of UDFs { Overlap(), etc } for queries• R-Tree indexing support functions
CREATE TABLE Train_Schedule (Train Train_Id NOT NULL,Track Track_Id NOT NULL,When DT_Period NOT NULL );
CREATE TABLE Train_Schedule (Train Train_Id NOT NULL,Track Track_Id NOT NULL,When DT_Period NOT NULL );
Train Track When
Toot-1 102
Toot-1 103 07/07/2000 12:35:00 to 07/07/2000 12:40:00
Toot-2 102 07/07/2000 12:37:00 to 07/07/2000 12:45:00
07/07/2000 12:31:00 to 07/07/2000 12:35:00
13
useruser .conference.conferenceInformixInformix
Some Notes on PhilosophySome Notes on Philosophy
• Object-Relational Not Just Media Stuff• Uses in “Industrial” applications
• Extend SQL with new functionality
• Raises Abstraction Level in Data Model• Objects in a relational data model
• Standards Emerging: SQL-3, SQL-J/JDBC 2.0
• Object-Relational Not Just Media Stuff• Uses in “Industrial” applications
• Extend SQL with new functionality
• Raises Abstraction Level in Data Model• Objects in a relational data model
• Standards Emerging: SQL-3, SQL-J/JDBC 2.0
14
useruser .conference.conferenceInformixInformix
Where can I get this stuff?Where can I get this stuff?
• These Examples and More:http://www.iiug.org/software
http://www.informix.com/idn
http://examples.informix.com
• Books on these Topics:
Roy, Jacques. Server Side Programming in ‘C’: INFORMIX Dynamic Server Prentice Hall. 1999.
Brown, Paul. Developing Object-Relational Databases Prentice Hall. 2000.
Sanchez, Angela. INFORMIX Universal Server: Best Practices Prentice Hall. 1997.
• These Examples and More:http://www.iiug.org/software
http://www.informix.com/idn
http://examples.informix.com
• Books on these Topics:
Roy, Jacques. Server Side Programming in ‘C’: INFORMIX Dynamic Server Prentice Hall. 1999.
Brown, Paul. Developing Object-Relational Databases Prentice Hall. 2000.
Sanchez, Angela. INFORMIX Universal Server: Best Practices Prentice Hall. 1997.