Go to content Go to navigation and search

Home

Current Oracle Spatial Blog Articles

    Convert Single Geometry to Multi-part Geometry in Oracle Spatial
    Optimized Rectangle to 5 Point Polygon
    Centroid Package now supports Y ordinate seeding
    Convert GeoJSON document to Sdo_Geometry objects
    Implementation Of Travelling Salesman Problem
    Create Polygon From Bearings And Distances
    Function That Returns a Compass Point From a Whole Circle Bearing
    Playing around with Centroids by using different seed values
    GeoRaptor 4.x Update 2
    Simple Oracle C Sprintf or Java String.format
    Some Oriented Point Functions
    Extracting Inner Rings Changed Ordinate Ordering: A Trap For Players Who Don't Read Documentation!
    PLS-00306: wrong number or types of arguments in call to 'SDO_GEOMETRY'
    Converting Google Earth Formatted Longitude/Latitude points to decimal degrees
    Oracle Business Intelligence Warehousing and Analytics - Spatial Summit
    How far inside, is inside? Measuring actual distance.
    Noding and building a polygon from single, overlapping linestrings
    Analyzing Spatial Query Performance Improvements in Oracle Spatial and Graph 12c Through Cross-Vendor Comparison
    ST_VertexN / ST_PointN - Extracting a specific point from any geometry
    Convert Single Point stored in SDO_ORDINATES to SDO_POINT_TYPE
    Aggregate APPEND Islands and XOR polygons
    Circular Arcs in Geodetic Polygons
    Some SDO_GEOMETRY/DIMINFO handling functions
    Applying And Extending Oracle Spatial - Book Released
    Changing all DIMINFO sdo_tolerance values for all metadata records in one go.
    Building Polygons from Incomplete Linestrings using ST_PolygonBuilder
    Computing Cardinal Directions to nearby geometries
    Intersecting two aggregated polygon layers with SC4O
    Spatial and Oracle 12c
    Update Triggers and SDO_GEOMETRY Equality
    Duplicate Geometry data and Data Models
    CENTROID package update
    How to calculate cumulative length of a linestring
    Useful Package of Wrapper Functions for Sdo_Util.AffineTransforms
    Compute Location from known Lat/Long point using delta easting and northing in miles
    SDO_AGGR_SET_UNION
    Sorting SDO_GEOMETRY data using the ORDER BY clause of a SELECT statement
    Creating linestrings from points
    Rounding Coordinates or Ordinates in SDO_GEOMETRY
    Effects of Sdo_Geometry Ordinate Precision on Performance
    Effects of Sdo_Geometry Ordinate Precision on Storage
    The Spatial filtering of geometries: The effect of tolerances on relationships
    Application of Delaunay Triangulation and Inverse Distance Weighting (IDW) in Oracle for Soils Interpolation
    Selecting all SDO_GTYPE values for all tables/sdo_geometry columns in a schema
    CENTROID package - Tips for Use
    Announcing the Spatial Companion For Oracle (SC4O)
    Filtering Rings (Oracle Spatial)
    Splitting a polygon using one or more linestrings
    isValid, isSimple, Dimension and CoordDim methods for SDO_Geometry
    Line Merging or Collecting lines together: ST_LineMerger
    ST_DeleteVertex for Oracle SDO_Geometry based on Jaspa/JTS
    3D/4D and SRID aware Conversion functions for SDO_Geometry: WKT and EWKT
    Topological vs Non-Topological Simplification/Generalization of Aggregated Area Geometies in Oracle
    Filtering very short linestrings via bitmap function index
    CENTROID For Oracle
    Gridding a sdo_geometry line/polygon object (Oracle)
    Finding centre and radius of a circular geometry
    Constraining geometry type for sdo_geometry column in a table.
    CASE Statements and SDO_GEOMETRY
    The Power of Constraints and Indexes for Spatial Constraints: stopping duplicate points
    Replacement for SDO_GEOM.RELATE - ST_Relate based on JTS
    Changing Oracle Spatial Index Parameters on existing index
    Writing Excel Spreadsheets files from within the Oracle database using Java and PL/SQL
    Writing xSV (eg csv) files from within the Oracle database using Java and PL/SQL
    A simple spike finder for Spatial/Locator
    JTS Java class compilation for 11g and above
    Random Spatial Search Procedure
    Geometry Snapping using JTS in Oracle
    Exposing JTS's MinimumBoundingCircle functionality
    Exposing JTS's Densifier functionality
    Using JTS's Comparison Functions - HausdorffSimilarityMeasure & AreaSimilarityMeasure with SDO_GEOMETRY
    Free JTS-based Area/Length Functions
    Handy way of systematically fixing polygon geometries with 13349 and other errors
    Standalone CENTROID package now available for download
    Free Union, Intersection, Xor and Difference Functions for Oracle Locator - Part 4 Processing Geodetic data
    Configurable Buffer: JTS and Oracle
    Free Union, Intersection, Xor and Difference Functions for Oracle Locator - Part 3
    Free Union, Intersection, Xor and Difference Functions for Oracle Locator - Part 2
    Free Union, Intersection, Xor and Difference Functions for Oracle Locator - Part 1
    Building Lines into Polygons in Oracle Locator / Spatial
    Finding Intersection Points between Line and Polygon
    SDO2GeoJSON
    Free version of sdo_length
    Alternative to my SQL based GetNumRings function
    External Tables and SDO_Geometry data.
    layer_gtype keyword issue when indexing linear data on 11g
    String Tokenizer for Oracle
    Free Aggregate Method for Concatenating 2D Lines in Oracle Locator 10g
    Reducing 5 Vertex Polygon to Optimized Rectangle
    Square Buffer
    Converting decimal seconds to string
    SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT - 13356 Issues
    Valid conversion unit values for Oracle sdo_geom.sdo_length()
    Removing Steps in Gridded Vector Data - SmoothGrid for Oracle
    Oracle Spatial DISJOINT search/filtering
    Creating SDO_Geometry from geometric data recorded in the columns of a table
    Concave Hull Geometries in Oracle 11gR2
    Projecting SDO_GEOM_METADATA DIMINFO XY ordinates
    Instantiating MDSYS.VERTEX_TYPE
    New PL/SQL Packages - Rotate oriented point
    GeoRaptor Development Team
    Fast Refreshing Materialized View Containing SDO_GEOMETRY and SDO_GEOM.SDO_AREA function
    Performance of PL/SQL Functions using SQL vs Pure Code
    Implementing the BEST VicGrid Projection in Oracle 10gR2
    Making Sdo Geometry Metadata Update Generic Code
    ORA-13011 errors when using SDO_GEOM.VALIDATE_LAYER_WITH_CONTEXT()
    Extract Polygons from Compound Polygon
    Detecting sdo_geometries with compound (3-point Arcs) segments
    GEOMETRY_COLUMNS for Oracle Spatial
    Convert GML to SDO_Geometry in Oracle 10gR2
    Spatial Sorting of Data via Morton Key
    Swapping Ordinates in an SDO_GEOMETRY object
    New To_3D Function
    Extend (Reduce/Contract/Skrink) Function for Oracle
    Loading and Processing GPX 1.1 files using Oracle XMLDB
    Loading Spatial Data from an external CSV file in Oracle
    Calling the Oracle Spatial shapefile loader from within the Oracle database itself
    Implementing SDO_VertexUpdate/ST_VertexUpdate for Oracle
    Implementing SDO_RemovePoint/ST_RemovePoint for Oracle
    Implementing SDO_AddPoint/ST_AddPoint for Oracle
    ESRI ArcSDE Exverted and Inverted Polygons and Oracle Spatial
    Funky Fix Ordinates By Formula
    Implementing a SetPoint/ST_SetPoint function in Oracle
    Implementing an ST_SnapToGrid (PostGIS) function for Oracle Spatial
    Generating random point data
    Implementing an Affine/ST_Affine function for Oracle Spatial
    Implementing a Scale/ST_Scale function for Oracle Spatial
    Implementing a Parallel/ST_Parallel function for linestring data for Oracle Spatial
    Implementing a Rotate/ST_Rotate function for Oracle Spatial
    Limiting table list returned when connecting to Oracle Database using ODBC
    ST_Azimuth for Oracle: AKA Cogo.Bearing
    Implementing a Translate/ST_Translate/Move function for Oracle Spatial
    Elem_Info_Array Processing: An alternative to SDO_UTIL.GetNumRings and querying SDO_ELEM_INFO itself
    Minumum Bounding Rectangle (MBR) Object Type for Oracle
    How to extract elements from the result of an sdo_intersection of two polygons.
    How to restart a database after failed parameter change
    Fixing failed spatial indexes after import using data pump
    generate_series: an Oracle implementation in light of SQL Design Patterns
    Multi-Centroid Shootout
    Oracle Spatial Centroid Shootout
    On the use of ROLLUP in Oracle SELECT statements
    Surrounding Parcels
    Spatial Pipelining
    Using Oracle's SDO_NN Operator - Some examples
    Converting distances and units of measure in Oracle Locator
    Split Sdo_Geometry Linestring at a known point
    Forcing an Sdo_Geometry object to contain only points, lines or areas
    Unpacking USER_SDO_GEOM_METADATA's DIMINFO structure using SQL
    Generating multi-points from single point records in Oracle Spatial
    Object Tables of Sdo_Geometry
    Oracle Locator vs Oracle Spatial: A Reflection on Oracle Licensing of the SDO_GEOM Package
    FAST REFRESHing of Oracle Materialized Views containing Sdo_Geometry columns
    Australian MGA/AMG Zone Calculation from geographic (longitude/latitude) data
    Loading Shapefiles (SHP) into Oracle Spatial
    Oracle Spatial Mapping and Map Rendering Performance Tips
    The significance of sdo_lb/sdo_ub in USER_SDO_GEOM_METDATA: Do I need it?
    Oracle Spatial Forum - Melbourne April 2007
    Layer_GTypes for spatial indexes
    Oracle's SQL/MM Compliant Types
    Tips and Tricks

Search

    Browse

RSS / Atom

Email me

textpattern

Creative Commons License
All Blog Articles, Data Models and Free Source Code by Simon Greener, The SpatialDB Advisor is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Fast Refreshing Materialized View Containing SDO_GEOMETRY and SDO_GEOM.SDO_AREA function

Saturday March 13 2010 at 07:22

KeywordsFast Refresh Materialized View Spatial Oracle
Summary

This article considers some of the issues that need to be faced when fast refreshing Materialized Views with Spatial (Sdo_Geometry columns).

The following series of blog articles by Rob van Wijk are an excellent resource and should be read by those reading this article.

Sven commented on my article about Materialized Views containing SDO_GEOMETRY data. He still had some issues so he pointed me to a posting he had made on the Oracle Spatial OTN forum.

I repeat the posting I made on that forum here to complete my response to Sven’s original comment on this website. While my answer doesn’t shows that he cannot include the SDO_GEOM.SDO_AREA in an MV that he wants to FAST REFRESH, it does highlight how to go about solving problems in relation to FAST REFRESHing SDO_GEOMETRY based tables.

Original Posting

Sven’s posting on the OTN website included this example:

  1. /* First create the table */
  2. CREATE TABLE MUSCLE_PSOAS (
  3.   MUSCLE_PSOASID   NUMBER(38),
  4.   RL4AXIALCONTOUR  MDSYS.SDO_GEOMETRY)
  5. --
  6. /* Now the primary key */
  7. CREATE UNIQUE INDEX MUSCLE_PSOAS_PK ON MUSCLE_PSOAS (MUSCLE_PSOASID);
  8. --
  9. /* Now the materialized view */
  10. CREATE MATERIALIZED VIEW MV_DERIVED_MUSCLE_PSOAS
  11. BUILD IMMEDIATE REFRESH FORCE ON COMMIT WITH PRIMARY KEY
  12. AS
  13.    SELECT MP.MUSCLE_PSOASID,
  14.           SDO_GEOM.SDO_AREA (mp.RL4AxialContour, 0.005) rl4area,
  15.           mp.rowid AS mp_rowid
  16.      FROM muscle_psoas mp;

I responded by taking his example and processing it to discover what the problem.

My Response

  1. /* First create the table */
  2. CREATE TABLE MUSCLE_PSOAS (
  3.   MUSCLE_PSOASID   NUMBER(38),
  4.   RL4AXIALCONTOUR  MDSYS.SDO_GEOMETRY)
  5. --
  6. /* Now the primary key */
  7. CREATE UNIQUE INDEX MUSCLE_PSOAS_PK ON MUSCLE_PSOAS (MUSCLE_PSOASID);
  8. --
  9. /* Now the materialized view */
  10. CREATE MATERIALIZED VIEW MV_DERIVED_MUSCLE_PSOAS
  11. BUILD IMMEDIATE REFRESH FORCE ON COMMIT WITH PRIMARY KEY
  12. AS
  13.    SELECT MP.MUSCLE_PSOASID,
  14.           SDO_GEOM.SDO_AREA (mp.RL4AxialContour, 0.005) rl4area,
  15.           mp.rowid AS mp_rowid
  16.      FROM muscle_psoas mp;
  1. /* First create the table */
  2. CREATE TABLE MUSCLE_PSOAS (
  3.   MUSCLE_PSOASID   NUMBER(38),
  4.   RL4AXIALCONTOUR  MDSYS.SDO_GEOMETRY
  5. );
  6. --
  7.  CREATE TABLE succeeded.
  8. --
  9. /* Now the primary key */
  10. ALTER TABLE MUSCLE_PSOAS ADD CONSTRAINT MUSCLE_PSOAS_PK PRIMARY KEY (MUSCLE_PSOASID);
  11. -- ALTER TABLE MUSCLE_PSOAS succeeded.
  12. --
  13. /* Now the MV log */
  14. /* To support all DML (INSERT, UPDATE and DELETE) for FAST REFRESH you must include SEQUENCE and "INCLUDING NEW VALUES" in the MV log. */
  15. CREATE MATERIALIZED VIEW LOG ON MUSCLE_PSOAS
  16.      WITH SEQUENCE, PRIMARY KEY, ROWID
  17.      INCLUDING NEW VALUES;
  18. -- CREATE MATERIALIZED succeeded.
  19. --
  20. /* Now create the materialized view
  21.  * Note: Build with REFRESH COMPLETE
  22.  *       in order to have the MV built and be able to
  23.  *       query the MV_CAPABILITIES_TABLE
  24.   */
  25. CREATE MATERIALIZED VIEW MV_DERIVED_MUSCLE_PSOAS
  26. BUILD IMMEDIATE
  27. REFRESH COMPLETE
  28. WITH PRIMARY KEY
  29. AS
  30.    SELECT mp.rowid AS mp_rowid,
  31.           MP.MUSCLE_PSOASID,
  32.           SDO_GEOM.SDO_AREA (mp.RL4AxialContour, 0.005) rl4area
  33.      FROM muscle_psoas mp;
  34. -- CREATE MATERIALIZED succeeded.
  35. --
  36. DELETE FROM MV_CAPABILITIES_TABLE;
  37. -- 20 rows deleted
  38. --
  39. COMMIT;
  40. -- commited
  41. --
  42. EXECUTE dbms_mview.explain_mview('MV_DERIVED_MUSCLE_PSOAS');
  43. -- anonymous block completed
  44. --
  45. SELECT capability_name,
  46.        possible,
  47.        related_text,
  48.        msgtxt
  49.   FROM MV_CAPABILITIES_TABLE
  50.  WHERE capability_name NOT LIKE '%PCT%'
  51.    AND capability_name NOT LIKE 'PCT%'
  52.    AND capability_name NOT LIKE '%REWRITE%'
  53.    AND capability_name NOT LIKE 'REWRITE%'
  54.  ORDER BY seq;
  55. --
  56. CAPABILITY_NAME                POSSIBLE RELATED_TEXT MSGTXT
  57. ------------------------------ -------- ------------ ------------------------------------------------------------
  58. REFRESH_COMPLETE               Y        NULL         NULL
  59. REFRESH_FAST                   N        NULL         NULL
  60. REFRESH_FAST_AFTER_INSERT      N        NULL         mv REFERENCES PL/SQL FUNCTION that maintains state
  61. REFRESH_FAST_AFTER_ONETAB_DML  N        NULL         see the reason why REFRESH_FAST_AFTER_INSERT IS disabled
  62. REFRESH_FAST_AFTER_ANY_DML     N        NULL         see the reason why REFRESH_FAST_AFTER_ONETAB_DML IS disabled
  63. --
  64. /* Drop objects */
  65. DROP MATERIALIZED VIEW MV_DERIVED_MUSCLE_PSOAS;
  66. -- DROP MATERIALIZED VIEW succeeded.
  67. --
  68. DROP TABLE MUSCLE_PSOAS;
  69. -- DROP TABLE MUSCLE_PSOAS succeeded.

Note that the problem is with the SDO_GEOM.SDO_AREA PL/SQL function as can be seen in the result text (“mv references PL/SQL function that maintains state”) above.

How can one get it to work?

Final Solution

This is how I did it.

  1. /* First create the table */
  2. CREATE TABLE MUSCLE_PSOAS (
  3.   MUSCLE_PSOASID    NUMBER(38),
  4.   rl4area           NUMBER,
  5.   RL4AXIALCONTOUR   MDSYS.SDO_GEOMETRY
  6. );
  7. -- CREATE TABLE succeeded.
  8. --
  9. /* Now the primary key */
  10. ALTER TABLE MUSCLE_PSOAS ADD CONSTRAINT MUSCLE_PSOAS_PK PRIMARY KEY (MUSCLE_PSOASID);
  11. -- ALTER TABLE MUSCLE_PSOAS succeeded.
  12. --
  13. /* Create Sequence */
  14. CREATE SEQUENCE MUSCLE_PSOAS_PK_SEQ;
  15. -- Create Sequence succeeded.
  16. --
  17. /* Create Trigger for PK and Area */
  18. CREATE OR REPLACE TRIGGER MUSCLE_PSOAS_PK_SEQ
  19. BEFORE INSERT OR UPDATE ON MUSCLE_PSOAS
  20. FOR each ROW
  21. BEGIN
  22.   IF inserting THEN
  23.     IF :NEW.MUSCLE_PSOASID IS NULL THEN
  24.        SELECT MUSCLE_PSOAS_PK_SEQ.NEXTVAL INTO :NEW.MUSCLE_PSOASID FROM dual;
  25.     END IF;
  26.   END IF;
  27.   IF :NEW.rl4area IS NULL AND :NEW.RL4AXiALCONTOUR IS NOT NULL THEN
  28.      :NEW.rl4area := MDSYS.SDO_GEOM.SDO_AREA(:NEW.RL4AxialContour, 0.005);
  29.   END IF;
  30. END;
  31. /
  32. -- TRIGGER MUSCLE_PSOAS_PK_SEQ compiled
  33. SHOW errors
  34. -- No Errors.
  35. --
  36. /* Now the MV log */
  37. /* To support all DML (INSERT, UPDATE and DELETE) for FAST REFRESH you must include SEQUENCE and "INCLUDING NEW VALUES" in the MV log. */
  38. CREATE MATERIALIZED VIEW LOG ON MUSCLE_PSOAS
  39.      WITH SEQUENCE, PRIMARY KEY, ROWID
  40.      INCLUDING NEW VALUES;
  41. -- CREATE MATERIALIZED succeeded.
  42. --
  43. /* Now create the materialized view */
  44. CREATE MATERIALIZED VIEW MV_DERIVED_MUSCLE_PSOAS
  45. BUILD IMMEDIATE
  46. REFRESH FAST ON COMMIT
  47. WITH PRIMARY KEY
  48. AS
  49.    SELECT mp.rowid AS mp_rowid,
  50.           MP.MUSCLE_PSOASID,
  51.           mp.rl4area
  52.      FROM muscle_psoas mp;
  53. -- CREATE MATERIALIZED succeeded.
  54. --
  55. DELETE FROM MV_CAPABILITIES_TABLE;
  56. -- 14 rows deleted
  57. --
  58. COMMIT;
  59. -- commited
  60. --
  61. EXECUTE dbms_mview.explain_mview('MV_DERIVED_MUSCLE_PSOAS');
  62. -- anonymous block completed
  63. --
  64. SELECT capability_name,
  65.        possible,
  66.        related_text,
  67.        msgtxt
  68.   FROM MV_CAPABILITIES_TABLE
  69.  WHERE capability_name NOT LIKE '%PCT%'
  70.    AND capability_name NOT LIKE 'PCT%'
  71.    AND capability_name NOT LIKE '%REWRITE%'
  72.    AND capability_name NOT LIKE 'REWRITE%'
  73.  ORDER BY seq;
  74. --
  75. CAPABILITY_NAME                POSSIBLE RELATED_TEXT   MSGTXT
  76. ------------------------------ -------- -------------- ---------
  77. REFRESH_COMPLETE               Y        NULL           NULL
  78. REFRESH_FAST                   Y        NULL           NULL
  79. REFRESH_FAST_AFTER_INSERT      Y        NULL           NULL
  80. REFRESH_FAST_AFTER_ONETAB_DML  Y        NULL           NULL
  81. REFRESH_FAST_AFTER_ANY_DML     Y        NULL           NULL
  82. --
  83. /* Drop objects */
  84. DROP MATERIALIZED VIEW LOG ON MUSCLE_PSOAS;
  85. -- DROP MATERIALIZED VIEW succeeded.
  86. --
  87. DROP MATERIALIZED VIEW MV_DERIVED_MUSCLE_PSOAS;
  88. -- DROP MATERIALIZED VIEW succeeded.
  89. --
  90. DROP TABLE MUSCLE_PSOAS;
  91. -- DROP TABLE MUSCLE_PSOAS succeeded.
  92. --
  93. DROP SEQUENCE MUSCLE_PSOAS_PK_SEQ;
  94. -- DROP SEQUENCE MUSCLE_PSOAS_PK_SEQ succeeded.

Note that the value of the POSSIBLE column for the REFRESH_FAST CAPABILITY_NAME means the MV is fast refreshable.

Final Comments with Methodology

So, while this approach won’t let you generate the area on the fly (for this you need to use an ordinary view) it shows that you can fast refresh an MV that contains an SDO_GEOMETRY object. The way I go about building build fast refreshable MVs is:

1. Initially create the materialized view as “BUILD IMMEDIATE REFRESH COMPLETE”;
2. Then use DBMS_MVIEW.EXPLAIN_MVIEW in conjunction with querying the MV_CAPABILITIES_TABLE, to work out if the MV is capable of REFRESH FAST;
3. If it is not, play around until you get the required Y against the REFRESH_FAST CAPABILITY_NAME. But don’t forget to read the documentation!
4. When you finally get the required Y, rebuild the MV using your desired BUILD IMMEDIATE REFRESH FAST parameters.

regards
Simon

Creative Commons License

post this at del.icio.uspost this at Diggpost this at Technoratipost this at Redditpost this at Farkpost this at Yahoo! my webpost this at Windows Livepost this at Google Bookmarkspost this to Twitter

Comment [2]

In your example, what is the value of having the mview at all?

(after looking at this example, I’m seriously considering adding insert/update triggers to a couple of my tables to generate values derived from spatial values)

— Justin · 16 December 2010, 18:40 · #

Justin,

Not my example: I was responding to a question about fast refresh on TechNet.

I have used fast and full refresh materialzed views to synchronise a production and distribution database. The benefit in this case was that no programming wsa needed: everything ws declarative. A benefit that flows on from this is that when the replication fails the reporting as to why is in the relevant internal Oracle metadata tables which the DBA can use to fix and restart. If custom code fails the path from the break to the fix can be convoluted with responsibility being passed from one to another.

In summary, no matter the database: Avoid custom code if a declarative out-of-the-box solution is available

Simon

Simon Greener · 16 December 2010, 23:56 · #