473,473 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

large data : how do you store multidimensional data ?

assume we have 10,000 cities. imagine those distance calculating
tables, where city A (row) to city Z (col) would equal a float value.
city Z (row) to city Z(col) would be 0. The only problem is our table
is not A-Z with a 26x26 table. It's 10,000 x 10,000 .

How can you store this data in a sql table efficiently ?

Thanks in advance.

Aug 26 '08 #1
5 4022
sorry the above example is a 2 dimensional. not multidimensional.
Aug 26 '08 #2
This is a typical undirected cyclic graph. Each edge represents a
two-way relationship. You normally store it as pairs from_city/to_city
and the distances between the pairs. When you need to find a path
between cities you convert it to digraph where each edge becomes two
directed edges, so (cityA, cityB) becomes (cityA, cityB) and (cityB, cityA).

--
Plamen Ratchev
http://www.SQLStudio.com
Aug 26 '08 #3
On Mon, 25 Aug 2008 23:11:42 -0700 (PDT), am**@desiboy.com wrote:
>assume we have 10,000 cities. imagine those distance calculating
tables, where city A (row) to city Z (col) would equal a float value.
city Z (row) to city Z(col) would be 0. The only problem is our table
is not A-Z with a 26x26 table. It's 10,000 x 10,000 .

How can you store this data in a sql table efficiently ?
I would want the Cities table to have an INT column as the key. Then
the CityDistance table would be three columns, (CityA, CityB,
Distance), where CityA, CityB is an ordered pair, probably CityA <
CityB for the ordering. Indexing depends on how you want to access
the data.

On the other hand, if this is really cities and distances, and the
distances are direct (as opposed to by road, for example), it might be
more efficient to add latitude and longitude to the Cities table and
calculate the distance on the fly. You might want to explore the
geospatial features introduced in SQL Server 2008 in that case.

Roy Harvey
Beacon Falls, CT
Aug 26 '08 #4
Roy Harvey (SQL Server MVP) (ro********@snet.net) writes:
I would want the Cities table to have an INT column as the key. Then
the CityDistance table would be three columns, (CityA, CityB,
Distance), where CityA, CityB is an ordered pair, probably CityA <
CityB for the ordering. Indexing depends on how you want to access
the data.
I would suggest that querying is a lot easier if you store both pairs,
even if this means that it takes up twice as much as space. Also, depending
on what's actually is those tables, it can be a good idea to store
the "self-pairs" (cityA, cityA) as well.

We did something like this with exchange rates and they were stored by
day, so the table became really huge. What we did later was to identify
that were a lot of exchange rates that no one would ever query about.
So we added a flag on currencies to mark them as "important" and then
we only saved and computed FX rates that involved at least on important
currency. (All self-pairs were still included.) I mention this, in case
it's applicable to Amit's business problem.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Aug 26 '08 #5
On Aug 26, 1:11 am, a...@desiboy.com wrote:
assume we have 10,000 cities. imagine those distance calculating
tables, where city A (row) to city Z (col) would equal a float value.
city Z (row) to city Z(col) would be 0. The only problem is our table
is not A-Z with a 26x26 table. It's 10,000 x 10,000 .

How can you store this data in a sql table efficiently ?

Thanks in advance.
1) If you really want the distance as a column in the table, then:

CREATE TABLE OneWayTrips
(first_city_code INTEGER NOT NULL,
second_city_code INTEGER NOT NULL,
distance FLOAT NOT NULL,
CHECK (first_city_code < second_city_code) ,
PRIMARY KEY (first_city_code, second_city_code) );

Now do everything off of a VIEW with an INSTEAD OF TRIGGER for
insertions, and updates and deletes.

CREATE VIEW Trips (first_city_code, second_city_code, distance)
AS
SELECT first_city_code, second_city_code, distance
FROM OneWayTrips
UNION ALL
SELECT second_city_code, first_city_code, distance
FROM OneWayTrips
UNION ALL
SELECT first_city_code, first_city_code, 0.00
FROM OneWayTrips
UNION ALL
SELECT second_city_code, second_city_code, distance
FROM OneWayTrips;

2) Otherwise:

CREATE TABLE Cities
(city_code INTEGER NOT NULL PRIMARY KEY,
longitude FLOAT NOT NULL,
latitude FLOAT NOT NULL);

Compute the distance with the usual formulas.
Aug 26 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jason Murry | last post by:
I have a camera system (Axis) which stores JPG via FTP 1-10fps. There is also a motion jpg live stream. I am trying to store these images either in JPG or in video format so they can be...
0
by: Constandinos Mavromoustakis | last post by:
CFP: CLADE 2004-Challenges of Large Applications in Distributed Environments ------------------------------------------------- PhD student - Dept.Informatics at Aristotle University of...
4
by: Michael Kirchner | last post by:
Hi everybody The output of my multiple dimension array is quite confusing. Im declaring an array, store some values in it and then I save the array in a session variable. On an other page I...
11
by: CSN | last post by:
Is it possible to iterate over an array in plpgsql? Something like: function insert_stuff (rel_ids int) .... foreach rel_ids as id insert into table (rel_id, val) values (id, 5);
6
by: Greg | last post by:
I am working on a project that will have about 500,000 records in an XML document. This document will need to be queried with XPath, and records will need to be updated. I was thinking about...
5
by: Louis LeBlanc | last post by:
Hey folks. I'm new to the list, and not quite what you'd call a DB Guru, so please be patient with me. I'm afraid the lead up here is a bit verbose . . . I am working on an application that...
2
by: Henrik | last post by:
im reciving an error when i tries to read multidimensional XML data, into my system. I'm receving the same errors discriped at: http://support.microsoft.com/default.aspx?scid=kb;en-us;325695...
6
by: Kyle Teague | last post by:
What would give better performance, serializing a multidimensional array and storing it in a single entry in a table or storing each element of the array in a separate table and associating the...
3
by: luftikus143 | last post by:
Hi there, I need to store three pieces of data - a result of a SQL query - in a multidimensional array, but don't really succeed. Sometimes it works, but then the output doesn't work accordingly....
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.