pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Constraint ordering
4+ messages / 4 participants
[nested] [flat]

* Constraint ordering
@ 2022-04-09 14:42 Perry Smith <pedz@easesoftware.com>
  2022-04-09 15:01 ` Re: Constraint ordering David G. Johnston <david.g.johnston@gmail.com>
  2022-04-09 15:05 ` Re: Constraint ordering Ron <ronljohnsonjr@gmail.com>
  0 siblings, 2 replies; 4+ messages in thread

From: Perry Smith @ 2022-04-09 14:42 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

I think (hope) I’ve made a bad assumption.  I have my DB with one table with two constraint on new entries.  The “first” is for the parent and basename be unique.  The “second” is that the devno and inode are unique if it is a directory.

When I was doing my early testing, the parent+basename constraint would fire first if it needed to.  Now that I’m doing a longer test run, the second constraint is firing at a time that I wasn’t expecting.  I’m debugging but it takes time to hit this again.

My assumption was if the error reported back that the “second" constraint failed that the “first” constraint passed.  But I bet that isn’t a valid assumption at all.

All that to ask: is there a predictable ordering of constraints?

Thank you,
Perry

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Constraint ordering
  2022-04-09 14:42 Constraint ordering Perry Smith <pedz@easesoftware.com>
@ 2022-04-09 15:01 ` David G. Johnston <david.g.johnston@gmail.com>
  2022-04-09 15:07   ` Re: Constraint ordering Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 4+ messages in thread

From: David G. Johnston @ 2022-04-09 15:01 UTC (permalink / raw)
  To: Perry Smith <pedz@easesoftware.com>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

On Sat, Apr 9, 2022 at 7:43 AM Perry Smith <pedz@easesoftware.com> wrote:

> I think (hope) I’ve made a bad assumption.  I have my DB with one table
> with two constraint on new entries.  The “first” is for the parent and
> basename be unique.  The “second” is that the devno and inode are unique if
> it is a directory.
>
> When I was doing my early testing, the parent+basename constraint would
> fire first if it needed to.  Now that I’m doing a longer test run, the
> second constraint is firing at a time that I wasn’t expecting.  I’m
> debugging but it takes time to hit this again.
>
> My assumption was if the error reported back that the “second" constraint
> failed that the “first” constraint passed.  But I bet that isn’t a valid
> assumption at all.
>
> All that to ask: is there a predictable ordering of constraints?
>
>
If you cannot find documentation describing constraint ordering rules then
there are none.  It isn't something a production application should rely
upon.  And for testing you should just ensure that any given test case only
violates one of those constraints at a time when you are testing to see
that they fire.

I'm not aware of any documentation describing constraint evaluation order.

David J.

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Constraint ordering
  2022-04-09 14:42 Constraint ordering Perry Smith <pedz@easesoftware.com>
  2022-04-09 15:01 ` Re: Constraint ordering David G. Johnston <david.g.johnston@gmail.com>
@ 2022-04-09 15:07   ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2022-04-09 15:07 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Perry Smith <pedz@easesoftware.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Sat, Apr 9, 2022 at 7:43 AM Perry Smith <pedz@easesoftware.com> wrote:
>> All that to ask: is there a predictable ordering of constraints?

> I'm not aware of any documentation describing constraint evaluation order.

IIRC, triggers are specified to fire in name order.  Uniqueness
constraints are not enforced by triggers though; I wouldn't care
to rely on the order in which those are checked.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Constraint ordering
  2022-04-09 14:42 Constraint ordering Perry Smith <pedz@easesoftware.com>
@ 2022-04-09 15:05 ` Ron <ronljohnsonjr@gmail.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Ron @ 2022-04-09 15:05 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

On 4/9/22 09:42, Perry Smith wrote:
> I think (hope) I’ve made a bad assumption.  I have my DB with one table with two constraint on new entries.  The “first” is for the parent and basename be unique.  The “second” is that the devno and inode are unique if it is a directory.
>
> When I was doing my early testing, the parent+basename constraint would fire first if it needed to.  Now that I’m doing a longer test run, the second constraint is firing at a time that I wasn’t expecting.  I’m debugging but it takes time to hit this again.
>
> My assumption was if the error reported back that the “second" constraint failed that the “first” constraint passed.  But I bet that isn’t a valid assumption at all.
>
> All that to ask: is there a predictable ordering of constraints?

If this would be a problem, then make the constraints deferred (until commit).

-- 
Angular momentum makes the world go 'round.





^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2022-04-09 15:07 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-04-09 14:42 Constraint ordering Perry Smith <pedz@easesoftware.com>
2022-04-09 15:01 ` David G. Johnston <david.g.johnston@gmail.com>
2022-04-09 15:07   ` Tom Lane <tgl@sss.pgh.pa.us>
2022-04-09 15:05 ` Ron <ronljohnsonjr@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox