473,386 Members | 1,733 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,386 software developers and data experts.

Building dynamic contents from database

Hi,

My problem is rather complex. I will try to explain it clearly (I hope !)

Sorry for my poor english.

I'm tracking change of state for entities (something than can be
monitored.)

The set of states are limited (state1 to state5.)

A table is storing the current state for each entities, and another
table is storing the history when state change. A function, taking
two arguments (name, state) is provided to take care of updating
both table automatically.

For example:

The table 'current_state':

name | state | date
----------------------------------------
foo | state2 | <date since this state>
bar | state3 | ' ' '
baz | state2 | ' ' '

The table 'history_state':

name | state | from_date | to_date
------------------------------------
foo | state2 | <date> | <date>
foo | state1 | <date> | <date>
bar | state4 | <date> | <date>
....
foo | state3 | <date> | <date>

To get a complete history for a specific entity, I've to make an UNION
from the two tables (Is it a current practice to split history/current ?)

Now, I want to define periods of time where the state is "logically"
forced to 'state0' (where 'state0' mean something like "don't care".)

Here is the table, 'override_state':

name | from_date | to_date
---------------------------
foo | <date> | <date>
foo | <date> | <date>
baz | <date> | <date>
bar | <date> | <date>

Each entry give a date interval where state must be considered as
'state0' whatever the current state is. The period for a same entity
can overlap, and can eventually be infinite (by NULLing to_date.)

I'm able to create a view that show current state (from 'state0' to
'state5'), but I don't see how to build a more complex view to be able
for example to query history by taking this new information into
account..

I think I've 3 possibilities:

- run a external process that connect to database at each date from
override_state (at from_date and to_date), and update history_state
and current_state accordingly to provide at all time the corrected
information. The problem here is to rely to an external process (and
probably need lock in case where update occur at the same time..)

- don't use view, but only stored procedure and give access to table
through "dynamic" table by joining the 3 tables with long
computation. The problem is that I want the fastest access.. and
this is not really the case of this method.

- or run a stored procedure before each access to table history_state
or current_state. The problem is that it is costly in time too.

Here is a complete example for a single entity 'foo':

* Since 10:00, the state is 'state1'
* At 11:00, the state change to 'state2'
* At 12:00, the state change to 'state3'

In the meantime, the table 'override_state' has 3 entries for 'foo':

* between 10:15 and 10:45
* between 10:30 and 11:10
* between 11:55 and 12:00

Thus, consulting the database at 11:30 should show the following:

current_state

name | state | since
----------------------
foo | state2 | 11:10

history_state

name | state | from | to
------------------------------
foo | state0 | 10:15 | 11:10
foo | state1 | 10:00 | 10:15
And at 13:00:

current_state

name | state | since
----------------------
foo | state3 | 12:00

history_state

name | state | from | to
------------------------------
foo | state0 | 11:55 | 12:00
foo | state1 | 11:10 | 11:55
foo | state0 | 10:15 | 11:10
foo | state1 | 10:00 | 10:15

Note: The current system (without this table 'override_state') give
1 millions of row for history, 5000 entries in current table, and 25
states information per second are fed to database (calling the
function described at start of this post.)

--
Frédéric Jolliton
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #1
2 1537
> name | state | from_date | to_date
------------------------------------
foo | state2 | <date> | <date>
foo | state1 | <date> | <date>
bar | state4 | <date> | <date>
...
foo | state3 | <date> | <date>


I would consider using only 1 table, where a NULL to_date indicates the
current state, and you have a compound index on (name, to_date) to support
querying for current state. Perhaps you could use a partial index as well to
speed up those queries, but I haven't yet explored that feature of
PostgreSQL.

--
Scott Ribe
sc********@killerbytes.com
http://www.killerbytes.com/
(303) 665-7007 voice
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

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

Nov 12 '05 #2
Scott Ribe <sc********@killerbytes.com> writes:
name | state | from_date | to_date
------------------------------------
foo | state2 | <date> | <date>
foo | state1 | <date> | <date>
bar | state4 | <date> | <date>
...
foo | state3 | <date> | <date>


I would consider using only 1 table, where a NULL to_date indicates the
current state, and you have a compound index on (name, to_date) to support
querying for current state. Perhaps you could use a partial index as well to
speed up those queries, but I haven't yet explored that feature of
PostgreSQL.


Well.. There is already several indexes (choosed accordingly to
performance test). And, also, table current contains some fields not
found in history, so only 1 table for both type of information is not
ideal.

--
Frédéric Jolliton

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

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

Nov 12 '05 #3

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

Similar topics

0
by: Frederic Jolliton | last post by:
Hi, My problem is rather complex. I will try to explain it clearly (I hope !) Sorry for my poor english. I'm tracking change of state for entities (something than can be monitored.) The...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
2
by: Mong | last post by:
Hi, I've developed an ASP.net application for an intranet site. Users will be identified using Windows authentication and they will belong to one of two roles, Admin or Users. The application...
0
by: | last post by:
Hi, I am just progamming using asp.net, and I want create a usercontrol to display some dynamic(from database) contents. Is this possible? Is there any sample code ? Thanks in advance! ...
12
by: scottrm | last post by:
Is there a way to generate a list of say textbox controls dynamically at run time, based on say a value coming out of a database which could vary each time the code is run. In traditional asp you...
1
by: Robert McLay | last post by:
I have been trying to build python on Cray X1. As far as I can tell it does not support dynamic loading. So the question is: How to build 2.4 without dynamic loading? That is: can I build...
3
by: Dave | last post by:
I have an old web app that ues an Access database and ASP 3.0. I need to build an INSERT statement based on the contents of a form. What is the best way to handle blank text boxes that are...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
14
by: Gilles Ganault | last post by:
Hi One of the ways to raise performance for PHP apps is to separate static contents from dynamic contents, so that the former can be compiled once into cache. Can someone give me a simple...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...

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.