> I have been looking at sub-values and trying to understand how,
> when and why they would be used.
A simple example...
Imagine I have a very simple order processing system in which the data I
record for each order is the date, the customer, the products and
quantities. The product and quantity fields will be multi-valued and
associated.
So far, so good. Now imagine that every time I sell something, I need to
record the serial numbers of the items. This new field will be multi-valued
by product, each value containing the serial numbers as sub-values.
> I also got the impression you could have up to 9 levels of sub-values
> (a sub-value of a sub-value?).
No. The original Pick definition of the data model has fields (attributes),
value, and sub-values. There are two other mark characters defined; the item
(record) mark that is used in real Pick systems to separate records in some
way internally but is almost unused in other systems, and the text mark that
is typically used to break long text fields into short parts of line
wrapping, etc.
UniVerse defined four more mark characters to allow sub-sub-values,
sub-sub-sub-values, sub-sub-sub-sub-values and sub-sub-sub-sub-sub-values
but I have never seen this used.
We do have an application that we produced for a client that effectively
uses text marks to create sub-sub-values but this level of separation of the
data is rare - probably largely because you need to think in five
dimensions!!! There is, of course, no reason why you cannot go on breaking
the data down with your own delimiters in any way that fits your needs but
the QMBasic language will not have anything better than the FIELD() function
to tear it apart.
Martin Phillips
Ladybridge Systems Ltd
17b Coldstream Lane, Hardingstone, Northampton, NN4 6DB
+44-(0)1604-709200
> For instance, the QUERY processor only properly handles
> Fields and values; It does not go lower.
The QM query processor does try to get the subvalues properly paired up. I
haven't looked at this recently but I think that we do a better job than
some of our competitors.
> There is a command to read an individual value (READV), but no
> command to read a subvalue.
In many ways, I really wish that READV did not exist. Without understanding
that the file system works at the record level and hence READV actually
reads the whole record, extracts the item and discards the rest, it is very
tempting for a programmer who wants two fields from a big record to think
that using two READVs will be the best way to do it. WRITEV is even worse!
> As far as I know, no multivalue implementation can do an
> exploding sort on sub-values, but all can do it on values.
Dare I say it..... QM does. (Though a quick experiment shows something
slightly odd going on with a single valued I-type in the query that I tried.
We will investigate this).
The "something odd" turned out to be a fault in a dictionary item that used
SUM() where SUMMATION() would be needed if there were both value and
subvalue marks in the item to be summed.
So, QM does do exploded sorts on subvalued data.
To my knowledge, D3 AQL is completely oblivious to subvalues.
> Martin wrote:
> > In many ways, I really wish that READV did not exist.
> > Without understanding that the file system works at
> > the record level and hence READV actually reads the
> > whole record, extracts the item and discards the rest,
> > it is very tempting for a programmer who wants two
> > fields from a big record to think that using two
> > READVs will be the best way to do it. WRITEV is even
> > worse!
>
> Yep, it's pretty useless. I just picked it as an an xample of
how the
> system support falls away as you go deeper down the delimiters
list.
The rule of thumb is to use READV for one atb but READ for any
more. I haven't seen the assembler code in D3 for READV but I
have to believe that it's been optimized to scan frames (SIDD
mnemonic?) and to retrieve only the attribute required. A full
GetItem operation followed by a parse would be an obvious waste
of resources. I would hope other MV products are similarly
optimized.
> In general would you agree that it's good practice to try to
keep the
> database within the standard 3 dimensions?
MV people know this but Dave may not: For item keys which
can't/shouldn't include system delimiters, almost all
applications make use of alphanumerics as delimiters. Examples:
ORDER*SEQUENCE
GLACCT_MONTH_TRANSID
TRANSCODE~TIMESTAMP
Apps also include these structures in multi-valued data:
001 CUSTID
002 DATE]DATE
003 TRANSID~TIME]TRANSID~TIME
That structure should have TIME as a separate dependent
attribute, or use subvalues instead of the tilde, but when
structures get more complex there's absolutely nothing wrong with
getting REC<3,2> and then using FIELD or OCONV functions to parse
out the desired sub sub sub parameter.
Most MV developers do stick to system delimiters as much as
possible but if you need to go deeper, just pick a delimiter that
doesn't clash with data and make sure the app understands the
structure.
In general, subvalues are usually used for data that will not be
queried by the command processor. As mentioned for D3 above,
this is because the query processor most MV variants does not
understand subvalues, and it's a bit frustrating to store data
elegantly for BASIC but not be able to query it in a report. QM
does not have this limitation. YMMV but for cross-platform
support I still don't use subvalued data for queries. However,
subvalues work well for many other purposes, including
"internal-only structures" and for data that needs to be used
with a GUI and you want to provide metadata to external clients
on a per-field basis. Again, YMMV.
HTH
Tony Gravagno
Nebula Research and Development
TG@ remove.pleaseNebula-RnD.com
Nebula R&D sells mv.NET and other Pick/MultiValue products
worldwide, and provides related development and training services
New version of NebulaXLite now available for QM.
Makes extensive use of sub-values :)
Generate rich, attractive spreadsheets from BASIC.
remove.pleaseNebula-RnD.com/products/xlite.htm
I limit myself to "just multi-values", not sub-values, because "lists"
are a very, very powerful data type. If we are going to add to the
simplicity of a single value in a "slot" then it makes sense to choose
one or more powerful data types that really do make software
development easier, more maintainable, etc.
Adding lists (multivalues) can definitely make things easier,
particularly if you compare the implementation of an ordered list
(some would say that is redundant, but we know it isn't) in MV to an
ordered list in an RDBMS. If we have a wide list -- require an arity
to our list that is > 1 -- then we could make another table, but
associations can make it easy enough to have a nested table or nested
"wide list" easy enough.
If we add subvalues to that mix, it might add simplicity, but can also
add unnecessary complexity. At that point it it is likely, but not
necessarily, easier for the long haul to split out a table.
Lists? Yes. All other types of structures, including associations and
sub-values? Maybe, but choose carefully or you can dig yourself into a
more complex, rather than simpler, solution. I give some associations
a thumbs up, but to date have never chosen to use sub-values. cheers!
--dawn
--
Dawn M. Wolthuis
Take and give some delight today
>
> YMMV, but if you are going to limit yourself to "just multi-values",
> why not just use flat SQL tables?
>
Because "flat" SQL tables don't support multivalues! Well, some do in
the form of VARRAY or nested tables, but the query language support is
very painful. QM and other multivalue products support multivalues
very well, but not so well for sub-values.
--
Ashley Chapman