oracle spatial für dbas - doag.org · pdf fileoracle bi suite, ebusiness suite,...

35
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Oracle Spatial für DBAs Was sollte man wissen? Carsten Czarski Consulting Member of technical Staff Oracle Application Express Oracle Deutschland B.V. & Co KG

Upload: lenguyet

Post on 19-Mar-2018

220 views

Category:

Documents


2 download

TRANSCRIPT

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Oracle Spatial für DBAs Was sollte man wissen?

Carsten Czarski Consulting Member of technical Staff Oracle Application Express Oracle Deutschland B.V. & Co KG

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Oracle: Offene Geodaten-Plattform

• Native Datentypen in der Datenbank

– Vektordaten und Rasterdaten (Satellitenbilder)

– Offene Zugriffe mit SQL, Java, .NET, ...

– Enge Integration zwischen Sachdaten und Geodaten

• Offen und Standardkonform

– Unterstützt von allen GIS-Systemen

SQL

SQL

“Spatial enabled”

Business Intelligence

Eigene Abfragen

GIS 2

GIS 1

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Punkte Linien Polygone

Rasterdaten

Topologien

3D f1

f2 n1 n2

e1

e2 e3

e4

Netzwerke

Geocoding Routing

Web Services (OGC)

Geocoding Routing

Spatial and Graph

Oracle Locator und Oracle Spatial

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Oracle Geodaten-Plattform: Die Strategie

• Location-Enabling der Oracle-Produkte

– Basis: Locator, Spatial and Graph, FMW MapViewer

– Beispiele: Oracle BI Suite, eBusiness Suite, Primavera, OTM, Oracle Event Processing und mehr ...

• Intensive Partnerschaften

– In Deutschland und weltweit

– ISV, SI, Datenlieferanten

• Commitment zu Standards

– OGC, SQL, ISO TC-211, TC-204

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Oracle Spatial: Entwicklung der Funktionalität

Oracle8i Spatial

•Coordinate Transformation

•Linear Referencing

Ora

cle

7

Kein

e G

eodate

n-

Funktionalit

ät

• Network Data Model (Routing)

• Geocoding

• Raster Data Management

1998 2001 2003

Oracle9i Spatial

•Data type: SDO_GEOMETRY

•R-Tree Indexing

•Topology/Distance Operators

2008

Oracle10g Spatial

• 3D-Support

• Google Integration

Oracle11g Spatial

2013

Oracle12c Spatial

• NURBS

• Raster Algebra

• HTML5 Maps

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Oracle Spatial-Technologie Lizensierung

• Oracle Locator

– Alle Editionen (XE, SE-1, SE-2, PE, SE, EE)

• Oracle Spatial

– Lizenzpflichtige Option (EE) Geocoding, Rasterdaten, Topology Data Model, Network Data Model, Linear Referencing …

• Oracle MapViewer

– Oracle Fusion Middleware - Alle Editionen

• Welche Funktionen enthält der "Locator"? Oracle Spatial Developers' Guide, App. B

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Oracle Spatial – Schema MDSYS

• MDSYS ist das Systemschema für Oracle Spatial

– Hält Metadaten für Oracle Spatial und Logik für den Umgang mit Geodaten

– Im Schema MDSYS werden keine Geodaten abgelegt

– Account sollte immer LOCKED sein

• Sowohl Locator (alle Editionen) als auch Spatial & Graph nutzen MDSYS

– Vorhandensein von MDSYS kein Indiz für Spatial & Graph Option

– Spatial & Graph sowie Locator können manuell deinstalliert und installiert werden

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Oracle Spatial - Datentyp SDO_GEOMETRY

ID NAME GRENZE NUMBER VARCHAR2 SDO_GEOMETRY

Tabelle Gemeinde

SDO_GTYPE NUMBER SDO_SRID NUMBER SDO_POINT SDO_POINT_TYPE SDO_ELEM_INFO SDO_ELEM_INFO_ARRAY SDO_ORDINATES SDO_ORDINATE_ARRAY

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Punkt

Polygon Polygon

"mit Loch"

Oracle Spatial: OGC Simple Features Geometrische Elemente

Linenzug

Optimiertes

Polygon

Kreisbogen Zus.ges.

Linienzug

Parametrisierte

Kurve

Zus.Ges.

Polygon

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Wie werden Geodaten tatsächlich gespeichert ...?

SQL> select column_name, data_type from user_tab_columns where table_name='M_ADMIN_AREA4' COLUMN_NAME DATA_TYPE -------------------- -------------------- FEATURE_ID NUMBER : : COUNTRY_CODE_3 VARCHAR2 GEOMETRY SDO_GEOMETRY

SDO_GTYPE NUMBER SDO_SRID NUMBER SDO_POINT SDO_POINT_TYPE SDO_ELEM_INFO SDO_ELEM_INFO_ARRAY SDO_ORDINATES SDO_ORDINATE_ARRAY

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Wie werden Geodaten tatsächlich gespeichert ...?

SQL> select column_name, data_type, hidden_column, qualified_col_name from user_tab_cols 2 where table_name='M_ADMIN_AREA4 COLUMN_NAME DATA_TYPE HID QUALIFIED_COL_NAME -------------------- -------------------- --- ----------------------------------- AREA_ID NUMBER NO AREA_ID : COUNTRY_CODE_3 VARCHAR2 NO COUNTRY_CODE_3 GEOMETRY SDO_GEOMETRY NO GEOMETRY SYS_NC00008$ NUMBER YES "GEOMETRY"."SDO_GTYPE" SYS_NC00009$ NUMBER YES "GEOMETRY"."SDO_SRID" SYS_NC00010$ NUMBER YES "GEOMETRY"."SDO_POINT"."X" SYS_NC00011$ NUMBER YES "GEOMETRY"."SDO_POINT"."Y" SYS_NC00012$ NUMBER YES "GEOMETRY"."SDO_POINT"."Z" SYS_NC00013$ SDO_ELEM_INFO_ARRAY YES "GEOMETRY"."SDO_ELEM_INFO" SYS_NC00014$ SDO_ORDINATE_ARRAY YES "GEOMETRY"."SDO_ORDINATES"

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Wie werden Geodaten tatsächlich gespeichert ...?

SQL> select column_name, data_type, hidden_column, qualified_col_name from user_tab_cols 2 where table_name='M_ADMIN_AREA4 COLUMN_NAME DATA_TYPE HID QUALIFIED_COL_NAME -------------------- -------------------- --- ----------------------------------- AREA_ID NUMBER NO AREA_ID : COUNTRY_CODE_3 VARCHAR2 NO COUNTRY_CODE_3 GEOMETRY SDO_GEOMETRY NO GEOMETRY SYS_NC00008$ NUMBER YES "GEOMETRY"."SDO_GTYPE" SYS_NC00009$ NUMBER YES "GEOMETRY"."SDO_SRID" SYS_NC00010$ NUMBER YES "GEOMETRY"."SDO_POINT"."X" SYS_NC00011$ NUMBER YES "GEOMETRY"."SDO_POINT"."Y" SYS_NC00012$ NUMBER YES "GEOMETRY"."SDO_POINT"."Z" SYS_NC00013$ SDO_ELEM_INFO_ARRAY YES "GEOMETRY"."SDO_ELEM_INFO" SYS_NC00014$ SDO_ORDINATE_ARRAY YES "GEOMETRY"."SDO_ORDINATES"

SQL> select column_name, segment_name from user_lobs 2 where table_name='M_ADMIN_AREA4' COLUMN_NAME SEGMENT_NAME ---------------------------------------- ------------------------------ "GEOMETRY"."SDO_ELEM_INFO" SYS_LOB0001917944C00013$$ "GEOMETRY"."SDO_ORDINATES" SYS_LOB0001917944C00014$$

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Wieviel Platz verbrauchen meine Geometry-Tabellen ...?

http://sql-plsql-de.blogspot.co.uk/2009/01/wie-gro-ist-eigentlich-eine-tabelle.html

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Wieviel Platz verbrauchen meine Geometry-Tabellen ...?

http://sql-plsql-de.blogspot.co.uk/2009/01/wie-gro-ist-eigentlich-eine-tabelle.html

SQL> select segment_name, segment_type, alloc_bytes 2 from table (get_space_info('M_ADMIN_AREA4')) SEGMENT_NAME SEGMENT_TYPE ALLOC_BYTES -------------------------------- --------------- ----------- M_ADMIN_AREA4 TABLE 23068672 SYS_LOB0001917944C00013$$ LOBSEGMENT 65536 SYS_LOB0001917944C00014$$ LOBSEGMENT 66060288 SYS_IL0001917944C00013$$ LOBINDEX 65536 SYS_IL0001917944C00014$$ LOBINDEX 65536

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Wichtig im Geodaten-Umfeld: Gültige Geometrien ...?

• Geometrie-Objekte (vor allem Polygone) können ungültig sein

– Selbstkreuzende Polygone

– Richting der Stützpunkte ist falsch

– Doppelte Stützpunkte

• Ungültige Polygone können zu falschen Ergebnissen führen

– Algorithmen für räumliche Funktionen werden "aufs Kreuz gelegt"

– Gültigkeit der Geometrien regelmäßig prüfen bzw. sicherstellen

– SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT

– Trigger, Scheduler-Jobs, etc.

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Ungültige Geometrien in einer Tabelle

• Ungültige Geometrien

SQL> select substr(sdo_geom.validate_geometry_with_context(geometry,1), 1, 6), count(*) from m_admin_area3 group by substr(sdo_geom.validate_geometry_with_context(geometry,1), 1, 6); SUBSTR(SDO_GEOM.VALIDATE COUNT(*) ------------------------ ---------- TRUE 528 13356 14 2 Zeilen ausgewählt.

$ oerr ora 13356 13356, 00000, "adjacent points in a geometry are redundant" // *Cause: There are repeated points in the sequence of coordinates. // *Action: Remove the redundant point.

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Räumliche Funktionen in SQL

• Topologische Operatoren

– Inside Contains

– Touch Disjoin

– Covers Covered By

– Equal Overlap Boundary

• Distanz-Operatoren – Within Distance

– Nearest Neighbor

Inside

Within Distance

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Räumliche SQL-Abfragen

• Welche Bundesländer grenzen an NRW?

• Abfrageoptimierung durch räumlichen Index

select l1.name from laender l1, laender l2 where l2.name='NRW' and sdo_relate( l1.grenze, l2.grenze, 'mask=touch' )='TRUE'

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Räumliche SQL-Abfragen

• Welche Kunden mit Umsatz sind in Brandenburg? select name, umsatz from customers c, geo_laender gl where sdo_anyinteract(c.geometry, gl.geometry) = 'TRUE' and gl.feature_name='Brandenburg' and umsatz is not null and umsatz > 0 NAME UMSATZ ------------------------------ ---------- Freie Tanke 4876 Marhoul 4798 Tankstelle Schönefeld 4598 Tankstelle Dreieck Havelland 7896 : :

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

a

b

c

d a b c d

Zeiger auf Geometrien

R

S

R S

root

root

Spatial Index: Aufbau des R-Tree-Index

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Spatial-Index: Primär- und Sekundärfilter

Geodaten Reduced

Data Set

Secondary

Filter

Spatial

Functions

Exact

Result

Set

Primary

Filter

Spatial

Index

Optimizer-"Shortcut": SDO_FILTER

Index-Lookup Berechnungen (CPU!)

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Spatial-Operator: Die Reihenfolge der Spalten ist wichtig!

• Spatial-Operatoren nehmen zwei Geometry-Parameter

– 1. Parameter: Tabellenspalte, in der gesucht wird – muss Spatial-Indiziert sein!

– 2. Parameter: Geometry-Objekt, anhand dessen gesucht wird.

• Selektivität beachten!

select name, umsatz from customers c, geo_laender gl where sdo_anyinteract(c.geometry, gl.geometry) = 'TRUE' NAME UMSATZ ------------------------------ ---------- Freie Tanke 4876 Marhoul 4798 : :

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Der Spatial Index ist ein Domain Index

• Domain Indexes nutzen das Extensible Indexing Framework

• Mythen und Fakten zu Domain Indexes ...

– Domain Indizes bringen Einschränkungen mit sich (bspw. Partitioning)

– Domain Indizes sind nicht zwingend asynchron (Oracle TEXT: Ja, Spatial: Nein)

– Domain Indizes bringen Domain-Spezifische Parameter mit

– Domain Indizes legen ihre Daten in Tabellen ab

create index sx_geodaten on geodaten_tabelle (spalte) indextype is mdsys.spatial_index

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

• Spatial Tabelle ohne Index sind möglich, meist aber sinnlos!

– Spatial-Operatoren (räumliche Suche) nicht möglich

• Voraussetzungen für einen Spatial Indix – Spatial-Metadaten für die Tabelle in USER_SDO_GEOM_METADATA

– Alle Geometrien müssen das gleiche Koordinatensystem (SRID) haben

– Unterschiedliche Geometrietypen (Punkte, Linien, Polygone) aber möglich

Besonderheiten des Spatial Index

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Tuning des Spatial Index – einige Hinweise ...

• Wenn die Tabelle nur Punkte enthält:

– Index mit Parameter LAYER_GTYPE=POINT erzeugen

– Indexstrukturen kompakter, da bekannt ist, dass nur Punkte vorliegen

– Fehler beim Versuch, etwas anderes zu speichern

• Sehr große Indizes

– Index mit Parameter SDO_NON_LEAF_TBL= TRUE

– Leaf Tabellen können von Baum-Tabellen getrennt werden

– Baum-Tabellen in SGA pinnen; bessere Nutzung des Hauptspeichers

• Schnellerer Indexaufbau

– Index mit Parameter MEMORY=XXX erzeugen

– Achtung: nicht mehr als 20% des Hauptspeichers verwenden

http://docs.oracle.com/database/121/SPATL/GUID-BB6D7C9E-277B-4F49-BDD4-539CFE88D12C.htm#SPATL1019

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Spatial Indizes: Was bedeuten diese MDRT-Tabellen?

SQL> select * from tab where tname like 'MDRT%'; TNAME TABTYPE CLUSTERID ------------------------------ ------- ---------- MDRT_137CA8F$ TABLE MDRT_137CA9D$ TABLE MDRT_137E53A$ TABLE : :

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Spatial Indizes: Was bedeuten diese MDRT-Tabellen?

SQL> select * from tab where tname like 'MDRT%'; TNAME TABTYPE CLUSTERID ------------------------------ ------- ---------- MDRT_137CA8F$ TABLE MDRT_137CA9D$ TABLE MDRT_137E53A$ TABLE : :

SQL> select tname, index_name from tab, user_sdo_index_info 2 where sdo_index_table = tname; TNAME INDEX_NAME ------------------------------ -------------------------------- MDRT_1E2FA2$ BAUBLOECKE_SIND MDRT_137E54E$ EBA_SPATIAL_ADDRESSES_SX MDRT_137E53A$ EBA_SPATIAL_AOI_SX MDRT_137E547$ EBA_SPATIAL_IMAGES_SX MDRT_1388BD0$ GEOMSX MDRT_B8760D$ IDX_BOX_HEALTH_POS_GEO MDRT_B875FF$ IDX_BOX_HEALTH_TRACK_GEO : :

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Spatial in Aktion erleben – mit APEX

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

DBMS_APPLICATION_INFO: Mehr Information für den DBA

• DBMS_APPLICATION_INFO

– SET_ACTION, SET_CLIENT_INFO, SET_MODULE, SET_SESSION_LONGOPS

• Öffentlich aufrufbar: PL/SQL, SQL, Java, Node.js, .NET, PHP, ... begin dbms_application_info.set_module( module_name => 'REPORTING', action_name => 'MONTHLY_CUST_REPORT' ); end;

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Mehr Information für den DBA

• DBMS_APPLICATION_INFO

– SET_ACTION, SET_CLIENT_INFO, SET_MODULE, SET_SESSION_LONGOPS

• Für alle Datenbank-Interfaces: PL/SQL, SQL, Java, Node.js, .NET, PHP, ... var oracledb = require('oracledb'); oracledb.getConnection( { user : "scott", password : "tiger", connectString : "sccloud033:1521/orcl" }, function(err, connection) { connection.module = 'REPORTING'; connection.action = 'MONTHLY_CUST_REPORT'; if (err) {console.error(err.message); return;} :

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Wie waren die Antwortzeiten ...?

02/09/2014

Oracle Confidential - Internal

select application_id, trunc(view_date), min(elapsed_time), max(elapsed_time), avg(elapsed_time), count(elapsed_time) from apex_workspace_activity_log where application_id not between 4000 and 9000 and view_date > sysdate - 3 group by application_id, trunc(view_date) order by 2 desc, 1 APPLICATION_ID TRUNC(VIEW_DATE) MIN(ELAPSED_TIME) MAX(ELAPSED_TIME) AVG(ELAPSED_TIME) COUNT(ELAPSED_TIME) -------------- ------------------- ----------------- ----------------- ----------------- ------------------- 124 18.04.2016 00:00:00 ,12052 ,124283 ,1224015 2 133 18.04.2016 00:00:00 ,004959 ,387387 ,069769 8 135 18.04.2016 00:00:00 ,011634 ,089108 ,052876556 9 149 18.04.2016 00:00:00 ,033442 ,10295 ,068196 2 176 18.04.2016 00:00:00 ,106777 ,496537 ,26442 4 178 18.04.2016 00:00:00 ,055692 ,154607 ,071076167 12 180 18.04.2016 00:00:00 ,004097 ,275007 ,04766672 189 222 18.04.2016 00:00:00 ,085705 ,103666 ,0946855 2 500 18.04.2016 00:00:00 ,00292 ,308159 ,024554742 392 135 17.04.2016 00:00:00 ,009952 ,161646 ,063078625 8 1801 17.04.2016 00:00:00 ,217515 ,32039 ,2689525 2 500 15.04.2016 00:00:00 ,01486 ,125769 ,052149333 3 12 Zeilen ausgewählt.

"Gestern abend lief die Reporting-Seite langsam ..."

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Match APEX-Antwortzeiten zu SQL-Executions

32

select sql_text, last_active_time, module, action from v$sql where module like '%APEX:APP 4800%'; SQL LAST_ACT MODULE ACTION --------------------------------------------- -------- -------------------- ---------------------------------- begin declare function render ( p_r ... 05 10:12 APEX:APP 4800:4000 Processes - point: BEFORE_BOX_BO select /* APEX50e56242 */ ... 05 10:12 APEX:APP 4800:4000 PAGE 4000 SELECT T.TEMPLATE_BODY1||I.PROMPT||T.TEM ... 05 10:13 APEX:APP 4800:4000 PAGE 4000 declare function x return boolean is beg ... 05 10:13 APEX:APP 4800:4000 Processes - point: BEFORE_BOX_BO select /* APEX 4800P4000f */ substr(appl ... 05 10:12 APEX:APP 4800:4000 Processes - point: BEFORE_BOX_BO SELECT NULL FROM WWV_FLOW_COMPANIES WHER ... 05 10:13 APEX:APP 4800:4000 Processes - point: BEFORE_BOX_BO select "NEWS_TEXT", "CREA ... 05 10:13 APEX:APP 4800:7000 Processes - point: BEFORE_BOX_BO select /* APEXd1fbde */ tag, ... 05 10:12 APEX:APP 4800:4000 Processes - point: BEFORE_BOX_BO : : : :

"Gestern abend lief die Reporting-Seite langsam ..."

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Spatial in Aktion erleben – mit APEX

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

Spatial in Aktion erleben – mit APEX

Copyright © 2014 Oracle and/or its affiliates. All rights reserved.

[email protected] http://blogs.oracle.com/apexcommunity_deutsch http://sql-plsql-de.blogspot.com Twitter: @cczarski