Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fxAxf-0002mQ-NG for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Sep 2018 13:01:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fxAxd-0005iD-U7 for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Sep 2018 13:01:37 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fxAxd-0005i6-HX for pgsql-hackers@lists.postgresql.org; Tue, 04 Sep 2018 13:01:37 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fxAxZ-00047j-SL for pgsql-hackers@lists.postgresql.org; Tue, 04 Sep 2018 13:01:36 +0000 Received: by mail-wr1-x430.google.com with SMTP id 20-v6so3833287wrb.12 for ; Tue, 04 Sep 2018 06:01:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=At9WfgtrBKEbZoYGUak5Y+TAi9dy1T0CGkSN3EAt8d4=; b=Uj9RWf6u/Vd37UaBlRqh24XBz3sAe9clGP5zid93GvNi2QX61U3+P6GcKq6A6G2G3b kLjXJpKq16nfFd5gHfHkr7cgweL9hsPdPq84EiDH8nZe6GZDWtbd56waeCP+oRr5MNhv Op4drgHTkuQCc0vYnIyg4LKcUWhZq6/ufXx7c1MXAkc0lj9kXXzWAMgI+eQnp9ZVUtCZ Zz/n9AFGaw1DXR9ZOfRUxXawFoOKSrk0Vx0cl+voOxnL5LeioLYWyThlEtDP71blf1ST l2Me9Ipuz0s+E4qBrLFVBm3bfs4VaYujyKbDriT53IzS4xBp7gwtpg3dIpjtwWh65O7k subg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=At9WfgtrBKEbZoYGUak5Y+TAi9dy1T0CGkSN3EAt8d4=; b=UnfvqE3P8lGgyGPO5GUySruu2oSJxrWZnivlgmR08f1YiwwCJSf0194M08MuIi+qbH 9SAMaZSLKYeCztV6twNyWIy/2/M0YKSzSV3STseJ38IsegIOxz+Z1MN/dkZxih7QliyY /HESxdkh/Yq1I0WD+TKoC9MUXKWsURjcGlZeSBHJ2P6K9ZFrr15WILgiaqEDxqmSBavx Wc6v4oCHmNHcSEVleOpbhsTdu1zWqJdLmxDEU9PU2OQFej4KzygpN53wlTZAuhl17i+j y9BKHN9OW6pSeOrGQsxW2MG29rGspj6A6dPelntN/D/VAyCi4K+4xAeSZulGbm9ipzv9 MiGg== X-Gm-Message-State: APzg51Cjfb44eBnlRmOyVVOsnRd9KW7CBvJlfV6+TapgG8776eJD+avv RJ5+4+Dgzigz17uGdnMVq7teMtMH9OMRiaKg7cw= X-Google-Smtp-Source: ANB0Vdbq+mGPLSG0xkLK4oRGOvId2+YezECbdkNK4XVXmXgsCf0v2lP2c83kktNwmafo1+TDVG8L3Kd2sRWLxCdAWZQ= X-Received: by 2002:a5d:6381:: with SMTP id p1-v6mr1186340wru.106.1536066091893; Tue, 04 Sep 2018 06:01:31 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a5d:5646:0:0:0:0:0 with HTTP; Tue, 4 Sep 2018 06:00:51 -0700 (PDT) In-Reply-To: References: <623395617.20171113141500@gf.microolap.com> <28924bcc-9242-9798-e4e8-9d83cea3fef6@dalibo.com> From: Pavel Stehule Date: Tue, 4 Sep 2018 15:00:51 +0200 Message-ID: Subject: Re: [HACKERS] proposal: schema variables To: Dean Rasheed Cc: Fabien COELHO , Gilles Darold , PostgreSQL Hackers Content-Type: multipart/alternative; boundary="000000000000c248eb05750b41e8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --000000000000c248eb05750b41e8 Content-Type: text/plain; charset="UTF-8" Hi 2018-09-04 9:21 GMT+02:00 Dean Rasheed : > AFAICS this patch does nothing to consider parallel safety -- that is, > as things stand, a variable is allowed in a query that may be > parallelised, but its value is not copied to workers, leading to > incorrect results. For example: > > create table foo(a int); > insert into foo select * from generate_series(1,1000000); > create variable zero int; > let zero = 0; > > explain (costs off) select count(*) from foo where a%10 = zero; > > QUERY PLAN > ----------------------------------------------- > Finalize Aggregate > -> Gather > Workers Planned: 2 > -> Partial Aggregate > -> Parallel Seq Scan on foo > Filter: ((a % 10) = zero) > (6 rows) > > select count(*) from foo where a%10 = zero; > > count > ------- > 38037 -- Different random result each time, should be 100,000 > (1 row) > > Thoughts? > The query use copy of values of variables now - but unfortunately, these values are not passed to workers. Should be fixed. Thank you for test case. Pavel > Regards, > Dean > --000000000000c248eb05750b41e8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi

2018-09-04 9:21 GMT+02:00 Dean Rasheed <dean.a.rasheed@g= mail.com>:
AFAICS this patc= h does nothing to consider parallel safety -- that is,
as things stand, a variable is allowed in a query that may be
parallelised, but its value is not copied to workers, leading to
incorrect results. For example:

create table foo(a int);
insert into foo select * from generate_series(1,1000000);
create variable zero int;
let zero =3D 0;

explain (costs off) select count(*) from foo where a%10 =3D zero;

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 QUERY PLAN -----------------------------------------------
=C2=A0Finalize Aggregate
=C2=A0 =C2=A0->=C2=A0 Gather
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Workers Planned: 2
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Partial Aggregate
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Parallel= Seq Scan on foo
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0Filter: ((a % 10) =3D zero)
(6 rows)

select count(*) from foo where a%10 =3D zero;

=C2=A0count
-------
=C2=A038037=C2=A0 =C2=A0 -- Different random result each time, should be 10= 0,000
(1 row)

Thoughts?

The query use copy of values = of variables now - but unfortunately, these values are not passed to worker= s.=C2=A0 Should be fixed.

Thank you for test case.=

Pavel


Regards,
Dean

--000000000000c248eb05750b41e8--