Download Information On Demand Using the Power of Integrated Information

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
DB2 Express-C 9:
Querying XML - It's just data after all...
Kitman Cheung
[email protected]
http://www-306.ibm.com/software/data/db2/express/
© 2005 IBM Corporation
Agenda
 IBM Supports for the PHP community:
– DB2 Express-C 9: What is it?
– Partnership with Zend
 DB2 9 features and tools
 PHP development with DB2 9
 Building Web Services: SQL/XML and XQuery in DB2 9 pureXML
 DB2 Health Web Service – an sample application built with DB2
9 pureXML and open source technologies.
2
DB2 Express-C – If you haven’t heard…
 DB2 Express for Open Community.
 It isn’t open source, but do you really care?? After all, IT’S FREE!!
– Free to download.
– Free to develop on.
– Free to deploy into production.
– Free to bundle with you application.
– In one word, it is “FREE”!
 Download site: http://www-306.ibm.com/software/data/db2/express/download.html
 Restriction?!? I guess there are a couple:
– 2 Processors with 4 GB of RAM, no limit of DISK SIZE!!
 Full featured, Enterprise ready, Relation / XML hybrid data store!
 When you need to, you pay for support…
 Goal Is to build a community of users with DB2 their database of choice.
 100,000 downloads since the start of the program (02/2006)
3
DB2 9 – Some of the features…
 pureXML: native XML with advanced query support.
 Autonomic features:
–
–
–
–
Automated Maintenance – statistic collection, table reorganization, backup.
Automated Memory Management (Self-tuning memory management).
Automated Storage Management.
Advisors for performance tuning (Configuration and SQL tuning).
 Security features
– LDAP and kerberos supports.
– LBAC – Label based access control (option)
 Row based Compression (option) – 70% saving in storage.
 Data Partitioning:
– Hash partitioning (DB2 9 ESE with DPF*): evenly distribute data onto multiple server to
take advantage of parallel I/O.
– Range partitioning (Table partition): capability to attach / detach a portion of a large table.
– Multi-Dimensional Clustering: Store data that is related logically in close physical
proximity.
* DB2 9 Extended Server Edition with Data Partitioning Feature
4
Demo 0: Checking out DB2 9
 Graphical administration interface
– Configuration and Design Advisors
– Visual Explain
 Developer Workbench
5
DB2 – Performance Tuning
 Configuration Advisor:
– DB2 is great because it is highly configurable… DB2 is painful because it is highly
configurable…
– 7 simple questions and 2 seconds later… 100+ parameters tuned.
250
%-age of DBA tuned
200
150
100
50
0
OLTP 32 bit
OLTP 64bit
Global inve stment bank A Global inve stment bank B
Workloads
DBA tuned
6
Advisor as percentage of tuned
Default configuration
DB2 – Performance Tuning (cont’d)
 Visual Explain – helps with manual SQL tuning.
 Design Advisor
–
Helps you with your database design.
–
Give the advisor your SQL workload, and it will tell you what database object to create and what benefit to expect.
Performance improvement
120%
Relative Workload execution time
DB2 Design Advisor
100%
Recommendation
summary:
80%
 20 new indexes
84.54%
time
reduction
60%
 4 new partitioning keys
40%
 2 new MQTs
20%
6.46x
faster
0%
Baseline
7
 6 new MDC dimensions
New design
DB2 Developer Workbench
 Eclipse-based IDE
 XML Query Builder
 SQL Query Builder
 Stored Procedure Builder
8
DB2 for PHP: What IBM is doing for the community?
 Express-C program
 Zend Core for IBM v1.5
 Open source contribution:
– Ibm_db2 – native PHP driver
– PDO_INFORMIX – PDO driver extension for Informix server.
– PDO_IBM – PDO driver extension for DB2 family of product.
 Zend Framework partnership
 Eclipse-based IDE
 App Dev supports:
–
PHP
–
Ruby on Rails
–
Perl
–
Python
–
JDBC
–
ODBC
–
.NET
 DB2 Express Forum
 DB2 Express Wiki
9
Setting up PHP with DB2
 Zend Core for IBM v1.5, integrated installation:
–
PHP 5.1.4
–
Apache 2
–
IBM DB2 Express-C 9
 Manual Setup:
– Download and install DB2 Express-C 9
(http://www-306.ibm.com/software/data/db2/express/)
– PHP on Windows:
1.
2.
Download ibm_db2 driver from http://pecl4win.php.net/ext.php/php_ibm_db2.dll
In the php.ini file, add the following lines:
extension=php_ibm_db2.dll
ibm_db2.instance_name=DB2
– PHP on Linux:
1.
2.
3.
Download ibm_db2 driver source from http://pecl.php.net/package/ibm_db2
Compile…
In the php.ini file, add the following lines:
extension=ibm_db2.so
ibm_db2.instance_name=db2inst1
10
Demo 1: getting started…
 db2_connect
 db2_exec
 db2_prepare and db2_execute
11
XML is everywhere…
Some Industry specific XML format:
 FIXML (Financial Information eXchange Markup Language)
– Real time security transaction
 MISMO (Mortgage Indust. Standard Maintenance Org’n)
– Mortgage information standard.
 ACORD (Association for Cooperative Operations Research and
Development)
– Insurance industry standard.
 FpML (Financial products Markup Language)
– Standard for trading financial derivative.
12
Financial Data (FIXML)
Buying 1000 Shares of IBM Stock..
8=FIX.4.2^9=251^35=D^49=AFUNDMGR^56=ABROKER^34=2
^52=20030615-01:14:49^11=12345^1=111111^63=0^64=2003
0621^21=3^110=1000^111=50000^55=IBM^48=459200101^22=
1^54=1^60=2003061501:14:4938=5000^40=1^44=15.75^15=USD
^59=0^10=127
Old FIX
Protocol
New FIXML
Protocol
extensible
lower appl development &
maintenance cost
13
Working with these documents…
 Standardized, precise way for companies to exchange
information.
 These document formats are complete. It enables
interoperability needed for webservice-based applications.
 Necessary evils:
– Documents are HUGE!
– Documents are constantly evolving.
– Partial document retrieval is important.
 DB2 Express-C 9 can help.
14
pureXML in DB2 9
SQL Person… "I see a
world class RDBMS that
also supports XML"
DB2 with
XML Support
XML Person… “I see a world
class XML repository that also
supports SQL"
XML integrated in all facets of DB2!
New XML applications benefit from:
• Ability to seamlessly leverage relational investment
• Proven Infrastructure that provides enterprise-class capabilities
15
pureXML: Interesting features…
 XML data type is not a CLOB in your RDMS:
– DB2 9 stores XML data natively in a hierarchical format.
– It’s kind of like a DOM inside your database engine.
– Better support for searching.
 XML Indexing:
– XPath pattern indexing.
– Does not require enforcement of a schema
 “Schema agnostic” XML column
– Any XML data be stored in a column, as long as it is well formed.
– High performance without tying a schema to a column.
– Validation is the user’s choice.
 SQL/XML and XQUERY supports.
16
pureXML: XPath Pattern based Indexing
 Will index all documents in a single XML column regardless of
schema version.
 Indexing using pattern described by standard XPath expression.
 Example:
CREATE INDEX nativein.country
ON nativein.customer(doc)
GENERATE KEY USING XMLPATTERN
'/customer/phones/phone/countryCode‘
as SQL DOUBLE;
17
pureXML: “Schema Agnostic” XML column
 XML column does not require documents to conform to a
schema.
 Document validation is supported, but not required, on INSERT.
 Schema evolution is quick and simple:
– Adding a new element type is significantly simpler than “shredding”.
– Unlike traditional implementation, performance benefits of indexes is
not affected.
 ACORD uses multiple schema versions at the same time.
 Allow “on-demand”, “just-in-time”, “real-time” schema upgrade…
18
Demo 2: Schema Evolution…
 Sample v1.0
 Sample v1.1
19
pureXML: SQL/XML and XQUERY supports
 DB2 9 provides support for:
– W3C XQUERY standard (Nov ’06)
– SQL/XML extension to the SQL 99 standard
 With these 2 querying standards, you can use manipulate
relational and XML data seamlessly and interchangably.
 Most XML access only requires a portion of the entire XML
document.
 Instead of retrieving full XML document and parsing using DOM
(or SimpleXML), you can retrieve only the portion you need
directly from the database.
– Performance gain by eliminating the need of parsing in the php layer.
– Performance gain by reducing network traffic
* The example provided in the following portion will work against the SAMPLE database
provided with DB2 Express-C 9
20
pureXML: SQL/XML Support
 DB2 function: XMLTABLE
– Creating a temporary SQL table using XML data.
(http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.apdv.embed.doc/doc/c0023903.htm)
SELECT * FROM XMLTABLE(
XMLNAMESPACES (DEFAULT 'http://posample.org'),
'db2-fn:xmlcolumn("CUSTOMER.INFO")/customerinfo'
COLUMNS
"CID" VARCHAR (50) PATH '@Cid’,
"NAME" VARCHAR (50) PATH 'name',
"PHONE" VARCHAR (50) PATH 'phone [ @type = "work"]'
) AS T
21
pureXML: SQL/XML Support
 DB2 function: XMLEXISTS
– A predicate that test if an XQuery expression returns a sequence.
(http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.admin.doc/doc/r0022228.htm )
SELECT CID, INFO
FROM CUSTOMER WHERE
XMLEXISTS(
'declare default element namespace
"http://posample.org";
$d/customerinfo [ ./name = "Kathy Smith"]'
passing INFO as "d")
22
pureXML: SQL/XML Support
 DB2 function: XMLELEMENT / XMLATTRIBUTES
– Creating XML segment/document with SQL data.
(http://www-128.ibm.com/developerworks/db2/library/techarticle/dm-0511melnyk/#concat)
SELECT XMLELEMENT(
NAME "Emp",
XMLATTRIBUTES(
E.EMPNO, E.FIRSTNME ||' '|| E.LASTNAME AS "name"
)
)
AS "XMLData"
FROM EMPLOYEE E WHERE E.EDLEVEL = 12
23
pureXML: XQUERY support
 db2-fn:sqlquery
– Retrieve an XML document using SQL. Then processing it with an
XQuery expression
SELECT * FROM TABLE(
values(xmlquery('
declare boundary-space strip;
declare default element namespace "http://posample.org";
db2-fn:sqlquery(“
SELECT INFO FROM CUSTOMER WHERE CID = 1001“
)/customerinfo/name
' returning sequence))
) AS T1
** Reference for DB2 XQuery support:
http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.xquery.doc/xqrcontainer.html
24
pureXML: XQUERY support
 db2-fn:xmlcolumn
– Retrieve all XML document from an XML column. Then processing it
with an XQuery expression
SELECT * FROM TABLE(
values(xmlquery('
declare boundary-space strip;
declare default element namespace "http://posample.org";
db2-fn:xmlcolumn("CUSTOMER.INFO")/customerinfo[ ./name = "Jim
Noodle"]
' returning sequence))
) AS T1
25
pureXML: XQUERY support
 FLWOR
– One of the most useful XQuery statement.
select * from table (
values(XMLQUERY('
declare boundary-space strip;
declare default element namespace "http://posample.org";
<product_list> {
for $p in db2-fn:xmlcolumn("PRODUCT.DESCRIPTION")/product
let $tax := 0.05
where $p/description/price > 5.00
order by $p/pid
return
(
$p/pid,
$p/description/name,
$p/description/price,
<tax>
$p/description/price * $tax
</tax>
)
} </product_list>
' RETURNING SEQUENCE))
) as t1
26
Demo 3: SQL/XML & XMLQUERY
1. Using XMLTABLE to return XML data as a Result Set
2. JOIN with XMLTABLE
3. Returning SQL data in a larger XML document.
27
Demo 4: Building an Application.
 DB2 Health Monitoring Service:
– PHP based web service using SQL/XML to retrieve data from DB2 9
database.
– SimpleXML & DOM for some post processing.
– WSDL-SOAP services using NuSOAP
 DB2 Monitoring GUI:
– DOJO AJAX toolkit
28
Health Monitoring Service – SQL/XML Example…
 DB2 health monitor reports database “health” through Table Functions.
 Using DB2 9 XML support, SQL data from these functions are converted
to XML documents served up as a web service.
SELECT
XMLSERIALIZE( CONTENT
XMLELEMENT(
NAME "HealthAlert",
XMLATTRIBUTES(
t.HI_ID as "hiIdentifier",
t.HI_ALERT_STATE_DETAIL as "hiAlertState",
t.HI_VALUE as "hiValue",
t.HI_TIMESTAMP as "hiTimestamp"
),
XMLELEMENT(
NAME "DB2_Object",
XMLATTRIBUTES(
t.DB_NAME as "name",
'database' as "type"
)
),
XMLELEMENT(
NAME "HiAdditionalInfo",
t.HI_ADDITIONAL_INFO
),
XMLELEMENT(
NAME "HiFormulaValue",
t.HI_FORMULA
)
)
AS CLOB (32000)
)
AS "ALERT"
FROM table (health_db_hi('', -1)) as t
29
30
THE END
Kitman Cheung
DB2 Linux / Open Source
IBM
[email protected]
31
32
33
34
35
Last minutes notes… borrowing Wez’s “telephone call” analogy
 I have a PDO related question and I want to ask Wez…
 So I can up my friend… ring-ring…
36
Related documents