Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Programming > Databases > General SQL Server Support

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-26-2008, 07:11 AM
amit@desiboy.com
 
Posts: n/a
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.

Reply With Quote
  #2 (permalink)  
Old 08-26-2008, 07:20 AM
amit@desiboy.com
 
Posts: n/a
Re: large data : how do you store multidimensional data ?

sorry the above example is a 2 dimensional. not multidimensional.
Reply With Quote
  #3 (permalink)  
Old 08-26-2008, 01:52 PM
Plamen Ratchev
 
Posts: n/a
Re: large data : how do you store multidimensional data ?

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
Reply With Quote
  #4 (permalink)  
Old 08-26-2008, 03:01 PM
Roy Harvey (SQL Server MVP)
 
Posts: n/a
Re: large data : how do you store multidimensional data ?

On Mon, 25 Aug 2008 23:11:42 -0700 (PDT), amit@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
Reply With Quote
  #5 (permalink)  
Old 08-26-2008, 11:15 PM
Erland Sommarskog
 
Posts: n/a
Re: large data : how do you store multidimensional data ?

Roy Harvey (SQL Server MVP) (roy_harvey@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, esquel@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

Reply With Quote
  #6 (permalink)  
Old 08-27-2008, 12:04 AM
--CELKO--
 
Posts: n/a
Re: large data : how do you store multidimensional data ?

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.
Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Programming > Databases > General SQL Server Support


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 02:11 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Send Money Online | Auto Insurence | Loans | Loan | Secured Loans



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114