Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kIRyQ-0007mx-FI for pgsql-general@arkaria.postgresql.org; Wed, 16 Sep 2020 07:35:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kIRyP-0008Vc-4x for pgsql-general@arkaria.postgresql.org; Wed, 16 Sep 2020 07:35:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kIRyO-0008VV-N2 for pgsql-general@lists.postgresql.org; Wed, 16 Sep 2020 07:35:24 +0000 Received: from mail-oo1-xc42.google.com ([2607:f8b0:4864:20::c42]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kIRyM-0002iS-9V for pgsql-general@lists.postgresql.org; Wed, 16 Sep 2020 07:35:23 +0000 Received: by mail-oo1-xc42.google.com with SMTP id r10so1424635oor.5 for ; Wed, 16 Sep 2020 00:35:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=MMt72seHbLR2Dmrp+z2C0AX3+s//C+DTnuFY/1IZ8EI=; b=u9S72kbcTueKfijsBYgUdL3RLAe62vXYFa94zNYYk8W3aHSSlYMZ51ZbGVEYqo5XOU SBJM7606SXdbeH88YKS04b9Tr1GuWX7VrD2yU5JGUzqvTYXS7WMRWau+Hzl3zFpXrSUq khA5+KJViH3fHiXCVZwPtwLOwNKzJQvNMEN7roWcDIGN7LjH4J1lkq3vP9IDuxf9J44q Irs+vnsMmtxgbPAcCD8qoBr3zjehAggxAS085aqb5yDXWQZQmlXKMfNQZIH2LKO3mFZU PPUz8KrZQ/m0Af4Rqmp2W09790JDK7Vfw1BW3T9xBfPwiurJ4uI9RhOXYpO58N7+LbXl wRbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=MMt72seHbLR2Dmrp+z2C0AX3+s//C+DTnuFY/1IZ8EI=; b=HyuuEa46kBYEK9lSpHPpICxgqpAyv//jkjk8JaKafF9JH8ev/357yIplFva7Cbi6pp Hz6IjA/0EPyWCQ5UzrI/g/YjAnKYvzwkiELzTjbFSvfueGRmlr26axQmHJVt/qI30Avm ao3wYqFzvTarfhwXMQkynOm5BOb3G66EDaXOCfiIm05msMyl3GBtLTqLb8aoCT9c+FMr /T0jxRORopt/H4/tJfa0r3KO07w8StLT9lDJpjCzLF5pvaNOrNvThfOcww6/BQ27Axyc nsSrk/H+N5aRJVAgy0WgHbKg7PIbUtw5QLIlT4Pbzb0GdEkS1SpGD93LXzIjOI1rJhA4 58zg== X-Gm-Message-State: AOAM531xQjm6qmFCfPnviCQPwqiMhpnXfK6uM0gXx/x7OPxpwa5dKXOB F5ivJHhxxetVOxoBDnie9+40iAnGqhw1gw== X-Google-Smtp-Source: ABdhPJyQW3eNwhXdlS5XcyTiQLIYsZSQsgOwoSzSX+jT3aqNp/GfkQippswNiGnIs7PgnG+JH5unPg== X-Received: by 2002:a4a:5896:: with SMTP id f144mr2386596oob.49.1600241720552; Wed, 16 Sep 2020 00:35:20 -0700 (PDT) Received: from [192.168.1.10] (ip174-67-143-111.no.no.cox.net. [174.67.143.111]) by smtp.googlemail.com with ESMTPSA id w19sm7676535otq.70.2020.09.16.00.35.19 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Sep 2020 00:35:19 -0700 (PDT) Subject: Re: Obvious data mismatch in View2 which basically SELECT * from View1 To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: Date: Wed, 16 Sep 2020 02:35:19 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 9/15/20 10:40 PM, Ben wrote: > Dear list, > > Recently I am getting feedback, data in my analytic report is not > repeatable. From time to time they get different data for the same time span. > (but IIRC previously it was OK). Therefore I started debuging the View > chain for that report, during which I bumped into this issue/phenomenon. > > In a over -simplified version: > > CREATE VIEW2 AS SELECT * FROM VIEW1; > SELECT  col1 FROM VIEW2 WHERE cond1=True; > SELECT  col1 FROM VIEW1 WHERE cond1=True; > > Now col1 from both views looks different. I don't know where to start to > solve this problem. > > The actual situation is a bit more than that, the following is the actual > query: > > >     -- trying to audit utlog weighed stat >     with t as ( >     select '2020-07-01 00:00:00'::timestamp t0, '2020--07-02 > 0:0:0'::timestamp t1 >     ) >     --select * from t; >     select * >     -- from utlog.cache_stats_per_shift_per_reason_weighed_stats >     -- from utlog.stats_per_shift_filtered_per_reason >     from utlog.stats_per_shift_filtered                     (let's call it > #View2 for short) >     -- from utlog.stats_per_shift_filtered_b0206      (let's call it > #View1 for short) >     -- from utlog.stats_per_shift >     cross join t >     where wline = 'F02'  and wts >= t.t0 and wts < t.t1 and wsft ='D' >     limit 100 >     ; > > The Result for #View2 > >     wts                 | wsft | wspan  | wstate | wline | rcodes >     --------------------+------+--------+--------+-------+------- >     2020-07-01 08:00:00 | D    |      0 | S00    | F02   | {PDCB} >     2020-07-01 09:50:01 | D    | 12.533 | S00    | F02   | {PDCB} >     2020-07-01 11:35:46 | D    | 12.217 | S00    | F02   | {CDSO} >     2020-07-01 13:22:58 | D    |   5.15 | S00    | F02   | {PDCB} >     2020-07-01 14:57:38 | D    |    6.8 | S00    | F02   | {PDCB} > >     INDEX | COLUMN_NAME | DATA_TYPE >     ------+-------------+------------ >     1     | wts         | timestamptz >     3     | wsft        | varchar >     4     | wspan       | float8 >     5     | wstate      | varchar >     6     | wline       | varchar >     7     | rcodes      | text[] > > > Same query, the Result for #View1 > >     wts                 | wsft | wspan | wstate | wline | rcodes >     --------------------+------+-------+--------+-------+------- >     2020-07-01 08:00:00 | D    |     5 | S00    | F02   | {PDCB} >     2020-07-01 09:50:01 | D    |    13 | S00    | F02   | {PDCB} >     2020-07-01 11:35:46 | D    |    12 | S00    | F02   | {CDSO} >     2020-07-01 13:22:58 | D    |     5 | S00    | F02   | {PDCB} >     2020-07-01 14:57:38 | D    |     7 | S00    | F02   | {PDCB} > >     INDEX | COLUMN_NAME | DATA_TYPE >     ------+-------------+------------ >     1     | wts         | timestamptz >     3     | wsft        | varchar >     4     | wspan       | float8 >     5     | wstate      | varchar >     6     | wline       | varchar >     7     | rcodes      | varchar[] > > Reuslts in `wspan` column is inaccurate while both type are float8. Most > weird thing is the 5 to 0 change. for Row 1. > > The `_b0206`(#View1) is just a version of > `stats_per_shift_filtered`(#View2) from past revisions. > I am sure the original CREATE statement for (#View2) is `CREATE VIEW ... > AS SELECT * FROM ...._b0206` > > Definition of View2 in SQLWorkbench/J generated schema: > > >     CREATE OR REPLACE VIEW utlog.stats_per_shift_filtered (#View2) >     ( >     wts, >     wdate, >     wsft, >     wspan, >     wstate, >     wline, >     rcodes >     ) >     AS >     SELECT stats_per_shift_filtered_u0206.wts, >         stats_per_shift_filtered_u0206.wsft::character varying AS wsft, >         stats_per_shift_filtered_u0206.wspan, >         stats_per_shift_filtered_u0206.wstate, >         stats_per_shift_filtered_u0206.wline, >         stats_per_shift_filtered_u0206.rcodes >     FROM utlog.stats_per_shift_filtered_u0206;  (as #View1 in this post) > > > It feels like the utlog.stats_per_shift_filtered_u0206 in > utlog.stats_per_shift_filtered definition is a different object from > utlog.stats_per_shift_filtered_u0206? > > I am totally out of clues. Any help would be appreciated. Thanks. Try the queries in a serializable read only transaction.  That should any possible changes in the underlying data. START TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY; SELECT  col1 FROM VIEW2 WHERE cond1=True; SELECT  col1 FROM VIEW1 WHERE cond1=True; COMMIT; -- Angular momentum makes the world go 'round.