Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Deleting, indexes and transactions

Received: by 10.68.195.131 with SMTP id ie3mr7220338pbc.8.1338227014138;
        Mon, 28 May 2012 10:43:34 -0700 (PDT)
X-FeedAbuse: http://nntpfeed.proxad.net/abuse.pl feeded by 78.192.0.157
Path: pr3ni59315pbb.0!nntp.google.com!news2.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx01.iad01.newshosting.com!newshosting.com!novia!news-out.readnews.com!transit4.readnews.com!216.40.28.145.MISMATCH!novia!proxad.net!feeder1-1.proxad.net!nntpfeed.proxad.net!78.192.0.157.MISMATCH!news.le-studio75.com!news.hub.org!postgresql.org!pgsql-general-owner+M187680
From: adrian.kla...@gmail.com (Adrian Klaver)
Newsgroups: pgsql.general
Subject: Re: [GENERAL] Deleting, indexes and transactions
Date: Mon, 28 May 2012 10:41:55 -0700
Organization: Hub.Org Networking Services
Lines: 62
Sender: n...@news.hub.org
Message-ID: <4FC3B8E3.8010907@gmail.com>
References: <CAAUywg__VyUuE+_Z8MMgEKzraGH=soHapOOcNoBgPWPxRBV82Q@mail.gmail.com> <4FC38E40.2040608@gmail.com> <CAAUywg9LSZAc1O6O7Kr9Z7LJHQtd++5S8qF4YwNrEExdOWs53A@mail.gmail.com>
NNTP-Posting-Host: news.hub.org
Mime-Version: 1.0
X-Trace: news.hub.org 1338227012 88321 200.46.204.72 (28 May 2012 17:43:32 GMT)
X-Complaints-To: usenet@news.hub.org
NNTP-Posting-Date: Mon, 28 May 2012 17:43:32 +0000 (UTC)
X-Received: from mx2.hub.org (mx2.hub.org [200.46.204.254])
	by news.hub.org (8.14.5/8.14.5) with ESMTP id q4SHhUSv088235
	for <pgsql-gene...@news.hub.org>; Mon, 28 May 2012 14:43:30 -0300 (ADT)
	(envelope-from pgsql-general-owner+M187...@postgresql.org)
X-Received: from postgresql.org (mail.postgresql.org [200.46.204.86])
	by mx2.hub.org (Postfix) with ESMTP id 139A2932E0B;
	Mon, 28 May 2012 14:43:30 -0300 (ADT)
X-Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229])
	by mail.postgresql.org (Postfix) with ESMTP id 75C6C1C11163
	for <pgsql-gene...@postgresql.org>; Mon, 28 May 2012 14:42:50 -0300 (ADT)
X-Received: from mail-pz0-f46.google.com ([209.85.210.46])
	by magus.postgresql.org with esmtp (Exim 4.72)
	(envelope-from <adrian.kla...@gmail.com>)
	id 1SZ3xu-0003Bn-T5
	for pgsql-gene...@postgresql.org; Mon, 28 May 2012 17:42:49 +0000
X-Received: by dady13 with SMTP id y13so4381072dad.19
        for <pgsql-gene...@postgresql.org>; Mon, 28 May 2012 10:42:33 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=message-id:date:from:user-agent:mime-version:to:cc:subject
         :references:in-reply-to:content-type:content-transfer-encoding;
        bh=gT9KQyoke/Vhd7jtHMH9njK/ICDy7SE5vXbpobKUIUI=;
        b=STTpP5VJyUZRLJwwv3zTHYwq3/5IdoqEZMspYSBUkGpN/Js1dAFjzerX/leWxREa4O
         b3QcBMfwZX30v9AilTfBOZZOe/OYHPepRjk5DmFz7rFQZCZ6kNOzr/Wn/y2UVtFmbUDd
         7GtF2SSkirZLxa7CP2tDAvkH+f0ezrLdAD8u3yo9pUSuSH+w+Q7RcOMxiB+O/rbuh+8n
         cjwM+zWz/8BWD5Zr4zvilAmOstSvn13Vll28YBFclJMV+5aTrKy81OfioD/9gsEuaj6r
         mWsiVLgDii3CJ7w0xLkAttw1HEC4SrDZsOpRPEqb/H8NqJn09IzKh/iaFDnXH1ppj4qY
         EV5w==
X-Received: by 10.68.190.39 with SMTP id gn7mr29920001pbc.5.1338226951284;
        Mon, 28 May 2012 10:42:31 -0700 (PDT)
X-Received: from [192.168.0.3] (c-24-17-164-54.hsd1.wa.comcast.net. [24.17.164.54])
        by mx.google.com with ESMTPS id mt9sm19909792pbb.14.2012.05.28.10.42.29
        (version=SSLv3 cipher=OTHER);
        Mon, 28 May 2012 10:42:30 -0700 (PDT)
X-User-Agent: Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20120428 Thunderbird/12.0.1
X-To: =?UTF-8?B?U3Rldm8gU2xhdmnEhw==?= <ssla...@gmail.com>
X-CC: pgsql-gene...@postgresql.org
X-In-Reply-To: <CAAUywg9LSZAc1O6O7Kr9Z7LJHQtd++5S8qF4YwNrEExdOWs...@mail.gmail.com>
X-Pg-Spam-Score: -2.7 (--)
X-Mailing-List: pgsql-general
X-List-Archive: <http://archives.postgresql.org/pgsql-general>
X-List-Help: <mailto:majord...@postgresql.org?body=help>
X-List-ID: <pgsql-general.postgresql.org>
X-List-Owner: <mailto:pgsql-general-ow...@postgresql.org>
X-List-Post: <mailto:pgsql-gene...@postgresql.org>
X-List-Subscribe: <mailto:majord...@postgresql.org?body=sub%20pgsql-general>
X-List-Unsubscribe: <mailto:majord...@postgresql.org?body=unsub%20pgsql-general>
X-Precedence: bulk
X-Received-Bytes: 6870
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

On 05/28/2012 08:46 AM, Stevo Slavić wrote:
> Hello Adrian,
>
> Thanks for replying!
>
> I guess in this case, referential action, from your quote, on deleting
> As is check that there are no Bs referencing to-be-deleted A row. But
> since all Bs are deleted (not committed yet though) prior to deleting
> As, I don't understand why is this check taking that long time. Doesn't
> this transaction, that both deleting Bs and As belong to, have enough
> "knowledge" if not to skip this check then to at least have it executed
> faster? It seems, in case without index, that postgres is executing this
> referential integrity check sequentially over B data as if they were not
> deleted, it just skips raising error because it ultimately after long
> time finds B records are about to be deleted. It would be faster if
> postgres had a structure/info on transaction level which would allow it
> to execute following (sequential) queries/checks only over rows which
> haven't been marked for deletion - I guess that would add complexity.
> With index I guess postgres does same logic just uses index to lookup Bs
> referencing to-be-deleted A much faster, and then determines Bs have
> been marked for deletion and doesn't raise error. I wonder how other
> RDBMS behave in this case.

FKs, as I understand it, are basically system triggers. The exact method 
by which they work and the effect of indexes on that are beyond me at 
this point. Others may have more insight.

>
> Anyway, regarding your second question, cascade delete hasn't been
> applied or tried yet. Case I've initially explained is one subcase of
> actual case that needs to be supported which is to sync As with an
> external source, which unfortunatelly doesn't provide info whether Bs
> have been changed or not for given A. So, there are two subcases, one
> where almost all data is dropped (As and Bs) and replaced with new,
> while in other subcase just some As data gets added while some As are
> deleted. In either case, we need to drop all Bs and add them because of
> lack of information of changes in Bs. Will check and see how that
> performs for both scenarios.

Well the issue seems to be with what you do to A not B. The FK is on B 
but the reference is to A and when you do an action on A in it needs to 
verify the state of the referring rows in B. By explicitly specifying a 
course of action (ON DELETE CASCADE) you streamline the process in the 
first case. In the second case it not as big an issue because you are 
only changing a small subset of A.

>
> Kind regards,
> Stevo.
>



-- 
Adrian Klaver
adrian.kla...@gmail.com

-- 
Sent via pgsql-general mailing list (pgsql-gene...@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general