Creating High Performance Spatial Databases with SQL Server 2008 Alastair Aitchison.

Slides:



Advertisements
Similar presentations
Session 2Introduction to Database Technology Data Types and Table Creation.
Advertisements

4/14/ :52 PM DBI405 Troubleshooting SQL Server Spatial Query Performance: A Deep Dive into Spatial Indexing Michael Rys Principal Program Manager.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
Project Management Database and SQL Server Katmai New Features Qingsong Yao
Spatial queries in SQL Server 2008 SQL Bits III – 13 th September 2008.
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
DT211 Stage 2 Databases Lab 1. Get to know SQL Server SQL server has 2 parts: –A client, running on your machine, in the lab. You access the database.
Databases Tutorial 2 Further Select Statements. Objectives for Week Data types Sort retrieved data Formatting output.
1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management.
Denny Cherry twitter.com/mrdenny.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
Chris Cummings.  Traffic cameras recording targets and retrieving them  Cameras track targets and the data needs to be recorded, but how are you supposed.
Introduction to SQL  SQL or sequel  It is a standardised language with thousands of pages in the standard  It can be in database system through GUI,
Oracle Data Definition Language (DDL)
Overview SQL Server 2008 Overview Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP, MCTS Microsoft Web Development MCP ITIL.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
PostgreSQL and relational databases As well as assignment 4…
Oracle Data Block Oracle Concepts Manual. Oracle Rows Oracle Concepts Manual.
Copyright © Curt Hill Index Creation SQL.
The State of PostGIS Paul Ramsey Paul Ramsey
Virtual techdays INDIA │ august 2010 Developing with SQL Server Spatial & Deep Dive into Spatial Indexing Pinal Dave │ Mentor, Solid Quality Mentors.
Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Module 5 Planning for SQL Server® 2008 R2 Indexing.
SQL Server Indexes Indexes. Overview Indexes are used to help speed search results in a database. A careful use of indexes can greatly improve search.
Table Indexing for the.NET Developer Denny Cherry twitter.com/mrdenny.
SQL access and working with ST_Geometry Functions
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
11 3 / 12 CHAPTER Databases MIS105 Lec15 Irfan Ahmed Ilyas.
Pasewark & Pasewark 1 Access Lesson 3 Creating Queries Microsoft Office 2007: Introductory.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
DAT602 Database Application Development Lecture 2 Review of Relational Database.
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes.
Visual Programing SQL Overview Section 1.
1 DBS201: More on SQL Lecture 3. 2 Agenda How to use SQL to update table definitions How to update data in a table How to join tables together.
Table Creation / Data Types. A Data type is... Specifies what kind of information a column will hold so that the system will know how the data is to be.
IMS 4212: Data Modeling—Attributes and Domains 1 Dr. Lawrence West, Management Dept., University of Central Florida Attributes and Domains.
SQL SERVER DAYS 2011 Table Indexing for the.NET Developer Denny Cherry twitter.com/mrdenny.
Creating and Populating a MS SQLServer Database Presented By: Dr. Adam P. Anthony.
Recent spatial work by Jim Gray and Alex Szalay Bob Mann.
SQL Server 2005: Extending the Type System with XML.
Session 1 Module 1: Introduction to Data Integrity
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
Understand Tables and How to Create Them Database Administration Fundamentals LESSON 2.2.
1 MySQL and SQL. 2 Topics  Introducing Relational Databases  Terminology  Managing Databases MySQL and SQL.
Dr Greg Low Working with SQL Server Spatial Data DAT33 3.
IS6146 Databases for Management Information Systems Lecture 3: SQL III – The DDL Rob Gleasure robgleasure.com.
GEOGRAPHY DATATYPES in SQL Server by jared nielsen linkedin.com/nielsendata.
DATABASES Define Software that can hold large amounts of data and allow users to retrieve specific information quickly. (Access, Oracle, etc.) Data is.
DAT319 - Building Location-Aware Applications in SQL Server 2008: Introducing the Spatial Data Type Michael Rys Principal Program Manager SQL Server Engine,
Spatial Data and Windows Azure SQL Database
Creating Database Objects
Fun with SQL Server Spatial Data
TABLES AND INDEXES Ashima Wadhwa.
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Indexing Goals: Store large files Support multiple search keys
Practical Office 2007 Chapter 10
Understanding & Using Spatial Data Features in SQL Server
Data Definition and Data Types
Database application MySQL Database and PhpMyAdmin
Using SQL Server through Command Prompt
Developing with SQL Server Spatial: Deep Dive into Spatial Indexing
DATABASE SQL= Structure Query Language مبادئ قواعد بيانات
Spatial Data Types And Indexing SQL Server 2008
Migrating a Disk-based Table to a Memory-optimized one in SQL Server
Fun with SQL Server Spatial Data
Database Management System
Creating Database Objects
SQL (Structured Query Language)
Introduction to SQL Server and the Structure Query Language
Presentation transcript:

Creating High Performance Spatial Databases with SQL Server 2008 Alastair Aitchison

About Me Consultant, Trainer, Author, and Housedad

Session Plan Do you need geometry and geography? Constructing a spatial index (the theory) Filtering spatial query results (the practice) Optimising spatial queries

The “Two-Column” Model CREATE TABLE Customers ( Name varchar(32), Address varchar(255), Lat float, Long float );

Point-in-Polygon SELECT * FROM Customers WHERE Lat BETWEEN LtMin AND LtMax AND Long BETWEEN LnMin AND LnMax (LtMin, LnMin) (LtMax, LnMax)

Calculating Distance SELECT * ACOS( SIN(Lat1) * SIN(Lat2) + COS(Lat1) * COS(Lat2) * COS(Lon2 - Lon1) ) (Lat1, Lon1) (Lat2, Lon2)

“Two-Column” Model Limitations Only stores points Calculations on flat plane or perfect sphere Limited range of methods

SQL Server 2008 Points, Linestrings, Polygons Accurate calculations – Ellipsoid model (geography) – Flat plane (geometry) Full complement of spatial methods – Intersects, Contains, Crosses, Touches – Distance, Length, Area – DE-9IM

Do You Need geometry / geography? Not all “spatial” apps need spatial datatypes Example: Store locator “two column”geometry / geography SimpleComplex ApproximateAccurate FAST!SLOW!

Session Plan Do you need geometry and geography? Constructing a spatial index (the theory) Filtering spatial query results (the practice) Optimising spatial queries 

Querying geometry and geography SELECT * WHERE A.STIntersects(B) = 1 Primary Filter (Based on Index) – Approximate – Fast – Superset of actual results Secondary Filter (Based on Table) – Refine results of primary filter – Accurate

Assigning Order to Spatial Data B-Tree indexing for linearly ordered data – decimal, float, money etc. – numeric order – char, varchar, nvarchar etc. – alphabetic order – datetime, date, time etc. – chronological order How do we assign order to spatial data?

The Multi-Level Grid

From Grid to Index Covered, partially covered, or touched cells Maximise accuracy - Minimise index size Three Rules – Covering Rule – Deepest-Cell Rule – Cells Per Object Rule

Covering Rule “If a grid cell is completely covered by a geometry, don’t further subdivide that cell.”

Deepest-Cell Rule “Once a cell has been subdivided, only store the intersecting cell(s) at the deepest grid level.”

Cells Per Object Rule “If subdividing a cell would exceed the maximum allowed number of cells for each object, do not subdivide the cell.”

Session Plan Do you need geometry and geography? Constructing a spatial index (the theory) Filtering spatial query results (the practice) Optimising spatial queries  

Creating a Spatial Index I CREATE TABLE Grid ( id char(1), shape geometry, CONSTRAINT [idxGridCluster] PRIMARY KEY CLUSTERED ( id ASC ) );

Add Some Points To The Table INSERT INTO Grid VALUES ('A', geometry::Point(0.5, 2.5, 0)), ('B', geometry::Point(2.5, 1.5, 0)), ('C', geometry::Point(3.25, 0.75, 0)), ('D', geometry::Point(3.75, 2.75, 0));

Creating a Spatial Index II CREATE SPATIAL INDEX idxGrid ON Grid(shape) USING GEOMETRY_GRID WITH ( BOUNDING_BOX = (0, 0, 4096, 4096), GRIDS = ( LEVEL_1 = MEDIUM, LEVEL_2 = MEDIUM, LEVEL_3 = MEDIUM, LEVEL_4 = MEDIUM), CELLS_PER_OBJECT = 16); -- Each L1 cell is 512 x Each L2 cell is 64 x Each L3 cell is 8 x 8 -- Each L4 cell is 1 x 1

Grid Level 4 A B C D

Finding Intersecting Points geometry = 'POLYGON (( , , , , )) '; SELECT * FROM Grid WHERE = 1;

Execution Plan With Spatial Index

sp_help_spatial_geometry_index EXEC = = = = 'POLYGON (( , , , , ))';

Number_Of_ObjectCells_ In_Level4_In_Index A B D C 4

Number_Of_ObjectCells_ In_Level4_For_QuerySample 9

Compare the Grid Cells A B C D

Percentage_Of_Rows_ NotSelected_By_Primary_Filter 25% A D B C

Number_Of_Rows_ Selected_By_Primary_Filter A 3 D B C

Percentage_Of_Primary_Filter_ Rows_Selected_By_Internal_Filter A D B C 33

Number_Of_Times_ Secondary_Filter_Is_Called A D B C 2

Number_Of_Rows_Output A B D C 2

Primary_Filter_Efficiency A D 66 B C

Internal_Filter_Efficiency A D 50 B C

Session Plan Do you need geometry and geography? Constructing a spatial index (the theory) Filtering spatial query results (the practice) Optimising spatial queries   

Making Sure the Index Is Used Use a Supported Method – STIntersects() – STContains(), STWithin(), STTouches() – STDistance() – Filter() Syntax must be A.STIntersects(B) = 1 Upgrade to SP1 Use a HINT where necessary

Making the Index Effective Three possible outcomes: – Preselection (Internal Filter) – Discarding (Primary Filter) – Secondary Filter Adjust Index Settings to fit data in the column and typical query samples

Improving Performance Make bounding box as tight as possible Grid Resolution ↑... Cells Per Object ↑ Multiple Indexes (may need HINT) Use non-spatial predicates Reduce unnecessary detail Experiment!

Want To Know More? Beginning Spatial with SQL Server 2008 MSDN Spatial Forum Forums/en-US/sqlspatial/threads

A Practical Demonstration Geonames export 6.9 million points Search for those in Newport Without Index: ~100 rows. 12,391,230 secs With Index: ~100 rows. < 1 sec