Subject | Re: FIRST 1 question |
---|---|
Author | russellbelding |
Post date | 2006-06-09T20:58:51Z |
Thanks Alan and Adam.
The "Natural ordering" has been identified with the order a table's
records happen to be on disk, and if an "Order By" is missing from a
select statement then the select statement will act as if "order by
Natural" was written, understanding there is no "natural" ordering
that can be used in a statement. Is this correct?
The natural ordering of a table is affected only by insertions and
deletions on the table. Is this correct?
It was suggested that immediately following a backup and restore the
natural ordering is the primary key ordering. Is this correct?
I had a misunderstanding in my thinking that an unspecified order
assumed the primary key order. That I understand now is wrong.
Thanks
Russell
--- In firebird-support@yahoogroups.com, "Alan McDonald" <alan@...>
wrote:
The "Natural ordering" has been identified with the order a table's
records happen to be on disk, and if an "Order By" is missing from a
select statement then the select statement will act as if "order by
Natural" was written, understanding there is no "natural" ordering
that can be used in a statement. Is this correct?
The natural ordering of a table is affected only by insertions and
deletions on the table. Is this correct?
It was suggested that immediately following a backup and restore the
natural ordering is the primary key ordering. Is this correct?
I had a misunderstanding in my thinking that an unspecified order
assumed the primary key order. That I understand now is wrong.
Thanks
Russell
--- In firebird-support@yahoogroups.com, "Alan McDonald" <alan@...>
wrote:
>primary
> In the database is
> ATable with fields FIELD_PK, FIELD2, .... and FIELD_PK is the
> key field.therefore
>
> In a stored procedure I use
> select FIRST 1 FIELD_PK from ATABLE
> where FIELD2 > 0
>
> Can I be certain that this selection is the same as
> select FIRST 1 FIELD_PK from ATABLE
> where FIELD2 > 0
> order by FIELD_PK?
>
>
> NO. The SP select statement does not use an ORDER BY clause and
> NATURAL order will be used. That means that the record (s) will beretrieved
> in order of where they are on the data page. Since records can bedeleted
> and their space taken up again by older records, an newer record(higher PK)
> may well appear before an older record (lower PK).order the
> Perhaps straight after a backup/restore cycle, you may see natural
> same as PK order but there are no guarantees within theimplementation.
> That's why there is an ORDER BY clause in the SQL standard.
> Alan
>