473,408 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Moving from narrow to wide tables

Hi all,

I have begun the slow process of shuffling data from about 125 narrow
tables into a single wide table and I am seeking some insight on the
'fastest way.' The narrow tables are all of the following
configuration:

===
Table "cal_0800_time"
Column | Type | Modifiers
-----------+--------------------------+-----------
timestamp | timestamp with time zone |
value | double precision |
Indexes: cal_0805_time__timestamp

Table "cal_5v_dig_rl"
Column | Type | Modifiers
-----------+--------------------------+-----------
timestamp | timestamp with time zone |
value | double precision |
Indexes: cal_5v_dig_rl__timestamp
===

As it stands, the timestamps are not unique but they should be in the
new table. I envision something like:

===
CREATE TABLE app_id_800 (
timestamp timestamp with time zone PRIMARY KEY
CHECK (timestamp BETWEEN '2003-08-13 02:10:00 +0' AND now()),
cal_5v_dig_rl float,
...
);
===

Followed by:

===
newtelemetry=> EXPLAIN ANALYZE INSERT INTO app_id_800(timestamp) SELECT
DISTINCT timestamp FROM cal_0800_time WHERE timestamp BETWEEN
'2004-02-21 0:00:00 +0' AND '2004-02-21 12:00:00 +0';NOTICE: QUERY
PLAN:

Subquery Scan *SELECT* (cost=0.00..11542.36 rows=1134 width=8) (actual
time=0.50..1786.02 rows=36219 loops=1)
-> Unique (cost=0.00..11542.36 rows=1134 width=8) (actual
time=0.47..907.77 rows=36219 loops=1)
-> Index Scan using cal_0800_time__timestamp on cal_0800_time
(cost=0.00..11514.01 rows=11341 width=8) (actual time=0.46..812.19
rows=37920 loops=1)
Total runtime: 23162.90 msec

EXPLAIN

newtelemetry=> EXPLAIN ANALYZE UPDATE app_id_800 SET cal_ccd_temp =
cal_ccd_temp.value FROM cal_ccd_temp WHERE app_id_800.timestamp BETWEEN
'2004-02-21 00:00:00 +0' AND '2004-02-21 12:00:00 +0' AND
app_id_800.timestamp = cal_ccd_temp.timestamp;
NOTICE: QUERY PLAN:

Nested Loop (cost=0.00..6.89 rows=1 width=538) (actual
time=1.34..5215.49 rows=37920 loops=1)
-> Index Scan using app_id_800_pkey on app_id_800 (cost=0.00..3.02
rows=1 width=522) (actual time=0.82..1727.18 rows=36219 loops=1)
-> Index Scan using cal_ccd_temp__timestamp on cal_ccd_temp
(cost=0.00..3.86 rows=1 width=16) (actual time=0.04..0.05 rows=1
loops=36219)
Total runtime: 33979.31 msec

EXPLAIN

.... 125 more UPDATE app_id_800 SET commands ...
===

The trouble is that this is taking a very long time when the time
interval increases. The total time for the one insert and 125 updates
(as above) is about 2-4 hrs for 1 day of data (~80K rows).

===
newtelemetry=> EXPLAIN ANALYZE INSERT INTO app_id_800(timestamp) SELECT
DISTINCT timestamp FROM cal_0800_time WHERE timestamp BETWEEN
'2004-02-21 0:00:00 +0' AND '2004-02-22 00:00:00 +0';
NOTICE: QUERY PLAN:

Subquery Scan *SELECT* (cost=0.00..40791.96 rows=4013 width=8) (actual
time=0.89..4397.78 rows=72448 loops=1)
-> Unique (cost=0.00..40791.96 rows=4013 width=8) (actual
time=0.85..2614.95 rows=72448 loops=1)
-> Index Scan using cal_0800_time__timestamp on cal_0800_time
(cost=0.00..40691.63 rows=40130 width=8) (actual time=0.85..2399.50
rows=101072 loops=1)
Total runtime: 55945.59 msec

EXPLAIN
newtelemetry=> EXPLAIN ANALYZE UPDATE app_id_800 SET cal_ccd_temp =
cal_ccd_temp.value FROM cal_ccd_temp WHERE app_id_800.timestamp BETWEEN
'2004-02-21 00:00:00 +0' AND '2004-02-22 00:00:00 +0' AND
app_id_800.timestamp = cal_ccd_temp.timestamp;
NOTICE: QUERY PLAN:

Nested Loop (cost=0.00..6.89 rows=1 width=538) (actual
time=1.08..13235.47 rows=101072 loops=1)
-> Index Scan using app_id_800_pkey on app_id_800 (cost=0.00..3.02
rows=1 width=522) (actual time=0.55..3647.76 rows=72448 loops=1)
-> Index Scan using cal_ccd_temp__timestamp on cal_ccd_temp
(cost=0.00..3.86 rows=1 width=16) (actual time=0.05..0.07 rows=1
loops=72448)
Total runtime: 68472.13 msec

EXPLAIN
===

Any ideas on wow can I speed this along? I have 4 months of data an
counting :(

Cheers,
Randall


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #1
0 1421

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

Similar topics

1
by: Ben M. | last post by:
Greetings all, This should be an easy task, and Im sure it is, but as many times as I have tried, I cant seem to get this to work properly. We changed ISPs recently from a shared host to a...
0
by: Csaba Gabor | last post by:
Hi, I have a wide table (horizontally overflows the page). With a lot of wide entries, the narrow ones are getting squashed. How can I set a minimum width in IE (since it doesn't like my...
7
by: Michael Deathya | last post by:
Hi, I am pulling over 400 different metrics from an Excel spreadsheet into Access (97). Conceptually, each row represents a single set of these 400 metrics. However, because of the 255 column...
1
by: Andy | last post by:
Can I mix wide and narrow character output to stdout? I seem to remember hearing this was not supported before but I can't find any reference to such a restriction now I actually need to do it! It...
2
by: fuzzybr80 | last post by:
I am using MySQL 5.0 with a number of innodb tables whose ibdata files are growing quite quickly and filling up the /var partition (file is /var/mysql/ibdata1). Earlier on I followed instructions...
4
by: thinktwice | last post by:
i'm using VC++6 IDE i know i could use macros like A2T, T2A, but is there any way more decent way to do this?
8
by: xmllmx | last post by:
It seems true, but I can't find any exact statement on this in the C or C++ standard. The C and C++ standard states: "__FILE_ The presumed name of the source file (a character string...
224
by: Jon Slaughter | last post by:
Sorry for all the cross posting but I'm interesting in getting a serious discussion about how usenet has become lately. Many people are moving away from usenet because of all the spam and cooks...
3
by: c0l0nelFlagg | last post by:
I have a moving dispatcher database. There are 99 drivers, 99 loaders, and 50 different vehicles. The scheduler database is built on a 13 4 week month year so that it can be used repeatedly in any...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.