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 1mQNj0-0005Hq-Ne for pgsql-general@arkaria.postgresql.org; Wed, 15 Sep 2021 05:44:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mQNiy-0004bQ-Og for pgsql-general@arkaria.postgresql.org; Wed, 15 Sep 2021 05:44:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mQNiy-0004bH-Eb for pgsql-general@lists.postgresql.org; Wed, 15 Sep 2021 05:44:48 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mQNiv-0004zK-2N for pgsql-general@lists.postgresql.org; Wed, 15 Sep 2021 05:44:47 +0000 Received: by mail-pl1-x629.google.com with SMTP id o8so959982pll.1 for ; Tue, 14 Sep 2021 22:44:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:message-id:in-reply-to:references:subject:mime-version; bh=knHtHme4DD5okCgKObiU3S7+affwfZhvQVyFCZPWlAE=; b=Q8cFzIPTN8sfwaCbGjjh0uAdsGnBwUUUnMjlgGj3PEa6xll0dgYoFA/fFsP6zsfKPP QXTacJJztPFwg7DATvC82f/kQa6dLfBfMeJz0w66vKhqH2k6qeuj2NlJy65dr6hIdygz KnIQAMjh/+N6cpZyrP4fNn9luZ82OQlAwqz3G5h73iyrTXUjOV6teAQxB11S1YDw5Fzb VNAZhKsUmuBdC+0LgrORu5fBmSG7EGAsoJRZKomKoZv4fvmbLD8eJXBZO3k+2XrMmcKI Mnio1Uh4Ric+h0yKhqU3zUxfL4uw8bUXoYz8+iAfZhja4BTPh4ybct7NaEUfTybw0V7Q ELdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:message-id:in-reply-to:references :subject:mime-version; bh=knHtHme4DD5okCgKObiU3S7+affwfZhvQVyFCZPWlAE=; b=yWxYfNL8WapyEQsKzdwpBX/aH0/iRGThLPPVDx7OZi1KlL3wX0+MkjHag36xwN7teY witEFw/xkfF/1Y+7hmBdUYkv6XQ9dPJIQCFy+t6t+wFK9/HTGk9fxSszWUHrMYKgWm6A Io20KzzyQdil795F6w++UicswiPhjo7NwJN1I2MpXQR3DtmpJRvKHW8KuxOOVYbAcD/y YO0kekJJxz/5IIpGOv3zPj9T2SUho8R5gVZrRgdazT/kAZHZDRVd1C3OqayXrU3JtTtw qoC4aav/Pv3MaByy9jlrwxWOovfLpC6VLV2nZO8Le7+4075vJgllfSsxU40hGHL31EnU isww== X-Gm-Message-State: AOAM532GIV2R4TdJcSiE9LcKsG/hnJQ34VMrAcyrUZFbNkXaAWWaRrGy R2JKusHpPvFrfSILgD7PGhAy5GCdWI0= X-Google-Smtp-Source: ABdhPJxg2c4f/FuEmcvVFEpSVLKdPf0PlHq8hOU56VCqJg/UZ2HA3lvzLYg8s0Q5ZvbOBXF0yJRbsQ== X-Received: by 2002:a17:902:b095:b029:12c:de88:7d3b with SMTP id p21-20020a170902b095b029012cde887d3bmr18492370plr.15.1631684682220; Tue, 14 Sep 2021 22:44:42 -0700 (PDT) Received: from [2600:8801:8800:5:100::] ([2600:8801:8800:5::6]) by smtp.gmail.com with ESMTPSA id j20sm13569487pgb.2.2021.09.14.22.44.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Sep 2021 22:44:41 -0700 (PDT) Date: Tue, 14 Sep 2021 22:31:41 -0700 From: Guyren Howe To: pgsql-general@lists.postgresql.org, Steve Litt Message-ID: <4c21fe13-fbb2-40d7-ae34-e6129d7f85fb@Spark> In-Reply-To: <20210915005449.150f2e45@mydesk.domain.cxm> References: <4dc338ad-b0aa-4f4c-bd9c-4dc76dda9e8b@Spark> <20210915005449.150f2e45@mydesk.domain.cxm> Subject: Re: SQL queries as sets: was The tragedy of SQL X-Readdle-Message-ID: 4c21fe13-fbb2-40d7-ae34-e6129d7f85fb@Spark MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="61418848_4516dde9_12d3d" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --61418848_4516dde9_12d3d Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Oh, yeah, wow. Big topic. My original post in the series is in significant part about how SQL hides= this sort of thing from you. A table is a set:=C2=A0=C2=A0a set of true facts, all having the same str= ucture, so you can operate on all of them with any operation on the indiv= idual rows. Multiple tables, multiples facts. Sometimes about the same things, which = is what a join does: the join key is the identifier of the things a bunch= of statements are all about. A user has a name, and a login, and a creat= ion date. When the identifier is the primary key, there is only such stat= ement. When it=E2=80=99s a foreign key, there are multiple statements. As an aside: it would be perfectly reasonable to have multiple tables wit= h the same primary key. Or with the same foreign key. You could have only= =E2=80=9Cforeign keys=E2=80=9D on a bunch of different tables. When you do a join, you=E2=80=99re finding all the =E2=80=9Cx and y=E2=80= =9D statements that the system knows to be true. That=E2=80=99s why a 1:m= any joins produces duplicate 1-side values in its results. When you do a where, you=E2=80=99re reducing the number of rows by only f= inding the rows with a certain property. The joins and wheres together gi= ve you a very expressive logic engine. There are two equivalent ways of looking at what the database does: it st= ores logical statements and acts as a logic engine; or it stores sets of = tuples and gives you set operations on them. Go read up on the basics of Datalog: it makes all of this beautifully obv= ious. My original post was about how different the computer industry would be i= f only we=E2=80=99d made relations as easy as Datalog does. The entire in= dustry would look different, just as garbage collection made the entire i= ndustry different. On Sep 14, 2021, 21:55 -0700, Steve Litt , w= rote: > Rich Shepard said on Tue, 14 Sep 2021 05:49:07 -0700 (PDT) > > > On Mon, 13 Sep 2021, Guyren Howe wrote: > > > > > They are making a decent decision. SQL is a *fucking terrible* > > > language, which I don=E2=80=99t blame them for not wanting to learn= . > > > > > > SQL is not the problem. Problem are the devs. I love SQL. I hate > > > > orms. The problem with databases is people refuse to treat it as > > > > the entity it is and want to use their beautiful OO system. Probl= em > > > > is databases are not OO. We need to recognize that and treat > > > > databases as databases. > > > > Guyren/Hemil, > > > > As a non-SQL expert who's used postgres since 1997 I've come to > > believe the basic issue is that SQL is based on sets, neither > > procedural or object oriented. =46ew people think in sets so they try= to > > fit SQL into what they know rather than understand the how sets work.= > > Rich, could you please elaborate on SQL queries being based on sets=3F = I > never thought of it that way, and would like to hear your related > thoughts. > > SteveT > > Steve Litt > Spring 2021 featured book: Troubleshooting Techniques of the Successful= > Technologist http://www.troubleshooters.com/techniques > > --61418848_4516dde9_12d3d Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
Oh, yeah, wow. Big topic.

My original post in the series is in significant part about how SQL hides= this sort of thing from you.

A table is a set:&=23160;&=23160;a set of true facts, all having the same= structure, so you can operate on all of them with any operation on the i= ndividual rows.

Multiple tables, multiples facts. Sometimes about the same things, which = is what a join does: the join key is the identifier of the things a bunch= of statements are all about. A user has a name, and a login, and a creat= ion date. When the identifier is the primary key, there is only such stat= ement. When it=E2=80=99s a foreign key, there are multiple statements.
As an aside: it would be perfectly reasonable to have multiple tables wit= h the same primary key. Or with the same foreign key. You could have only= =E2=80=9Cforeign keys=E2=80=9D on a bunch of different tables.

When you do a join, you=E2=80=99re finding all the =E2=80=9Cx and y=E2=80= =9D statements that the system knows to be true. That=E2=80=99s why a 1:m= any joins produces duplicate 1-side values in its results.

When you do a where, you=E2=80=99re reducing the number of rows by only f= inding the rows with a certain property. The joins and wheres together gi= ve you a very expressive logic engine.

There are two equivalent ways of looking at what the database does: it st= ores logical statements and acts as a logic engine; or it stores sets of = tuples and gives you set operations on them.

Go read up on the basics of Datalog: it makes all of this beautifully obv= ious.

My original post was about how different the computer industry would be i= f only we=E2=80=99d made relations as easy as Datalog does. The entire in= dustry would look different, just as garbage collection made the entire i= ndustry different.
On Sep 14, 2021, 21:55 -0700, Steve= Litt <slitt=40troubleshooters.com>, wrote:
Rich Shepard said on Tue, 14 Sep 2021 05:49:07 -0700 (PDT)

On Mon, 13 Sep 2021, Guyren Howe wrote:

They are making a decent decision. SQL is a= *fucking terrible*
language, which I don=E2=80=99t blame them for not wanting to learn.

SQL is not the problem. Problem are the dev= s. I love SQL. I hate
orms. The problem with databases is people refuse to treat it as
the entity it is and want to use their beautiful OO system. Problem
= is databases are not OO. We need to recognize that and treat
databases as databases.

Guyren/Hemil,

As a non-SQL expert who's used postgres since 1997 I've come to
believe the basic issue is that SQL is based on sets, neither
procedural or object oriented. =46ew people think in sets so they try to<= br /> fit SQL into what they know rather than understand the how sets work.

Rich, could you please elaborate on SQL queries being based on sets=3F I<= br /> never thought of it that way, and would like to hear your related
thoughts.

SteveT

Steve Litt
Spring 2021 featured book: Troubleshooting Techniques of the Successful Technologist http://www.troubleshooters.com/techniques


--61418848_4516dde9_12d3d--