You are here: Re: Database suggestion « PHP Programming Language « IT news, forums, messages
Re: Database suggestion

Posted by Mikhail Kovalev on 12/05/07 18:09

On 5 Des, 18:26, Norman Peelman <npeel...@cfl.rr.com> wrote:
> Mikhail Kovalev wrote:
> > On 5 Des, 14:11, "C. (http://symcbean.blogspot.com/)"
> > <colin.mckin...@gmail.com> wrote:
> >> On 5 Dec, 11:13, Mikhail Kovalev <mikhail_kova...@mail.ru> wrote:
>
> >>> Hi.
> >>> I work with recursive array trees of 10-20 levels in PHP. So far I
> >>> have been using serialize() to store the arrays, generating files 5+
> >>> MB large, which take 10-15 seconds to unserialize and about tenfold of
> >>> RAM! I've been adviced to use MySQL (relational db's), but are there
> >>> any other options beside that and var_export/include? Something that
> >>> works in a similar way as MySQL when adding a new element without
> >>> loading the whole database itself...
> >>> Thanks!
> >> Any relational DB can model a hierarchical data structure - at the
> >> simplest level:
>
> >> node_id unique identifier, not null
> >> parent_node null
> >> payload whatever
>
> >> But getting the threaded structure is a bit tricky -
>
> >> SELECT parent.node_id as Parent_node_id, parent.payload as
> >> parent_payload,
> >> child.node_id as child_node_id, child.payload as child_payload
> >> FROM mytable parent, mytable child
> >> WHERE child.parent_node=parent.node_id
> >> AND parent.node_id=$start_here
>
> >> .. i.e. by explicitly declaring aliases for each level in the tree you
> >> can get the sub-nodes, but when you don't know how deep the tree is,
> >> its not possible to return the whole structure in a single query using
> >> standard SQL. Oracle allows you to compose queries returning
> >> representations of hierarchical data (have a google for 'connect by' &
> >> 'start with') but thats rather non-standard.
>
> > I don't know how deep the tree is, but I don't need to return the
> > whole structure in a single query. Alas, I don't know the nature of
> > MySQL
>
> > At this moment everything I do with my structure happens by calling
> > addresses
> > See my reply to The Natural Philosopher.
> > Here's an example with one node at top level and it's childs:
>
> > 112 (10)
> > 225 (3)
> > 930 (1)
> > 11 (5)
>
> > $array[112][COUNT] = 10;
> > $array[112][NEXT][225][COUNT] = 3;
> > $array[112][NEXT][225][NEXT][930][COUNT] = 1;
> > $array[112][NEXT][225][NEXT][930][NEXT] = array();
> > $array[112][NEXT][11][COUNT] = 5;
> > $array[112][NEXT][11][NEXT] = array();
>
> > An address is an array, f ex array(112, 225, 930)
>
> > I then use the following mechanism:
>
> > // retrieves a node with its two values as an array(COUNT, NEXT)
> > // NEXT contain further childs, but i dont use them
> > // array_1 is the whole structure, and array_2 is the address
> > function function_7($array_1, $array_2) { return eval('retur
> > $array_1'.function_8($array_2).';'); }
>
> > // array(112, 225, 930) becomes "[112][NEXT][225][NEXT][930]"
> > function function_8($array_1) { return implode('[NEXT]',
> > array_map('function_9', $array_1)); }
>
> > function function_9($integer_1) { return '['.$integer_1.']'; }
>
> > // saves a value array_3 to an address array_2 in structure array_1
> > function function_10($array_1, $array_2, $array_3)
> > {
> > eval('$array_1'.function_8($array_2).' = $array_3;');
> > return $array_1;
> > }
>
> Tried to look up on Markov chains... are any of your addresses
> duplicated? ie: can you have an address like 112, 225, 112 ?
>
> Norm

Yes. Any id can be child or parent of any other id or itself and any
way around.
I'm only interested in how many times a given sequence occurs.
For example, if I was to record this sequence (112, 225, 930) (the
example above doesn't show it), it would look like this:

Split by length from 1 to the size of the sequence itself (3)
112
225
930
112, 225
225, 930
112, 225, 930

I use those as addresses to add count values to make this structure.

112 (1)
225 (1)
930 (1)
225 (1)
930 (1)
930 (1)

If I now add another sequence 700, 112, 112, 225, the table changes
to:

112 (3)
225 (2)
930 (1)
112 (1)
225 (1)
225 (2)
930 (1)
930 (1)
700 (1)
112 (1)
112 (1)
225 (1)

So from this I know that (112) occurs 3 times (in both sequences that
have been added), (112, 225) occurs 2 times, and (700, 112, 112)
occurs 1 times etc.

I have another file which translates id's to other variables.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация