Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hNzYO-0000is-7R for pgsql-general@arkaria.postgresql.org; Tue, 07 May 2019 12:50: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 1hNzYM-0000XJ-Ih for pgsql-general@arkaria.postgresql.org; Tue, 07 May 2019 12:50:38 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hNzYM-0000Ug-2A for pgsql-general@lists.postgresql.org; Tue, 07 May 2019 12:50:38 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hNzYJ-0002V0-Nc for pgsql-general@lists.postgresql.org; Tue, 07 May 2019 12:50:36 +0000 Received: by mail-ed1-x533.google.com with SMTP id p27so3683441eda.1 for ; Tue, 07 May 2019 05:50:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Ie9vnJC4lgb0CnTfwdwqEwM0St48SysYti1vnnsLMSg=; b=XTN7QDUktKiJHUCfzjFp9JUHrc7DyKqNyWxWLGNXX/Abe4DhRwefC9kaGFpgkZJHEQ FcgXB5B76LA0x/SqIJsTvglyvByhuZm7hdofyZfS/Ei7MB1uQ8QSNnO9rYk88EgG6tQh XWa8DB75CuqvUCkeEyyZkY4dF561hK+Y5hszTpoo0duUKzijvuTqenaXMbNmQub3dsA6 MG4NeI6fFI2yzShb+x6CXX3PXjGLJQSlWWg/gT/BeQbcxCPWzsPmlqhe65ehLkXCBo2Q VK9mpfat7d0RCtfcoMSYYZmzP26pcmgGfwcDQJU36VH2+p1mDjV7rruQOudU+fRHUioV 8reg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Ie9vnJC4lgb0CnTfwdwqEwM0St48SysYti1vnnsLMSg=; b=VzbLIfX/ew05XumGz3LKz69PrWRxzgw12Dc4lQb7NehpJxuI5BlRtttLkeeB2JYsV5 EL/rcwrpolt3EVIpz6XEG+Z9Mfl4uZdSWwzemjuVWG47IGve3bwLqdtoIRh0XZhTUSXZ thCTf2aRccn5kmiw1G1PlJG1Wq7mlVlp3rOIqY6/zAaiq8WP6clTEJqE7CnOaajpTUe1 X/u+oSjuemyY6F5/QR8H40BZw76xIVBmBQ4OT/KQz0+NhYpBuY+nshrocJzgo28+Ugac ZH8nTdpq44FU9Jw+VAklQMW2mqUTarI9uHH57aMRHTQhhYxm6yHnhbpYKDofVOf5sljz vH+A== X-Gm-Message-State: APjAAAWAcoV5+M0YlXstmPTMfa24zKMLEpIZvfKdGdSxfFXRsneotwsE Iqbn4C5muSfO7tXTipONeh6UvHln X-Google-Smtp-Source: APXvYqxfhrbJTrTMocij4BOTSoZe+Zz4edjudui8AKTbpswAKz8JQWL6dluEokgZo5V1VDA6pJfYUQ== X-Received: by 2002:a50:a389:: with SMTP id s9mr32053505edb.113.1557233433077; Tue, 07 May 2019 05:50:33 -0700 (PDT) Received: from hollewijn.internal (217-19-30-105.dsl.cambrium.nl. [217.19.30.105]) by smtp.gmail.com with ESMTPSA id q4sm2139521ejb.65.2019.05.07.05.50.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 May 2019 05:50:32 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.8\)) Subject: Re: random generated string matching index in inexplicable ways From: Alban Hertroys In-Reply-To: <20190507115345.GA56585@50pop.com> Date: Tue, 7 May 2019 14:50:31 +0200 Cc: pgsql-general@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <20190507115345.GA56585@50pop.com> To: Myles Miller X-Mailer: Apple Mail (2.3445.104.8) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On 7 May 2019, at 13:53, Myles Miller wrote: >=20 > PROBLEM: > Strings or characters generated by any random function (including = pg_crypto > gen_random_bytes) are matching a string/char index in surprising ways. I fail to see anything surprising in your examples. > Reduced down to its simplest example: (=E2=80=A6) > -- if we use random-generated 'A' or 'B', things get inexplicable >=20 > # SELECT y FROM x WHERE y =3D chr(round(random())::int + 65); > y=20 > --- > A > B > (2 rows) Here you got a random value in the lower range of 0..1 for the record = with value =E2=80=98A=E2=80=99, so that=E2=80=99s a match, and one in = the higher range for value =E2=80=98B=E2=80=99, a match again, so you = get 2 rows. >=20 > # SELECT y FROM x WHERE y =3D chr(round(random())::int + 65); > y=20 > --- > (0 rows) Here you got a random value in the higher range for the record with = value =E2=80=98A=E2=80=99, so no match, and one in the lower range for = value =E2=80=98B=E2=80=99, no match again, so you get 0 rows. > # SELECT y FROM x WHERE y =3D chr(round(random())::int + 65); > y=20 > --- > B > (1 row) Here you got two random values in the higher range, so only the row with = =E2=80=98B=E2=80=99 matches. You could also get two random values in the lower range and only get a = match against =E2=80=98A=E2=80=99. Regards, Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.