Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rZuJ8-0074AK-34 for pgsql-general@arkaria.postgresql.org; Tue, 13 Feb 2024 15:02:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rZuJ6-000UAh-I3 for pgsql-general@arkaria.postgresql.org; Tue, 13 Feb 2024 15:02:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rZuJ6-000UAZ-7S for pgsql-general@lists.postgresql.org; Tue, 13 Feb 2024 15:02:48 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rZuIw-006YaE-9Z for pgsql-general@lists.postgresql.org; Tue, 13 Feb 2024 15:02:46 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id BA59018B27; Tue, 13 Feb 2024 16:02:34 +0100 (CET) Date: Tue, 13 Feb 2024 16:02:34 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: How to do faster DML Message-ID: <20240213150234.ydiitfoowojhj2n3@hjp.at> Mail-Followup-To: pgsql-general@lists.postgresql.org References: <20240211002528.hjxls24vnnck7wsh@hjp.at> <20240211133203.zw6ezhdzefyxmkd7@hjp.at> <20240211222230.tt3mpjdvgrimeodu@hjp.at> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="tn3evuqyxtj6aij5" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --tn3evuqyxtj6aij5 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2024-02-13 01:53:25 +0530, veem v wrote: > On Mon, 12 Feb 2024 at 03:40, Peter J. Holzer wrote: >=20 > The fixed width types are those that the CPU can directly process: > Integers with 16, 32 and 64 bits, floating point numbers with 32 and = 64 > bits. The CPU can read and write them with a single memory access, it > can do arithmetic with a single instruction, etc. >=20 > Number/Numeric are not native types on any CPU. To read them the CPU > needs several memory accesses (probably one per byte unless you get > really clever) and then it can't do any calculations with them > directly, instead it has run a subroutine which does operations on > little chunks and then puts those chunks together again - basically t= he > same as you do when you're doing long addition or multiplication on > paper. So that's not very efficient. >=20 >=20 > So it looks like the fixed length data type(like integer, float) should b= e the > first choice while choosing the data type of the attributes wherever=A0po= ssible, > as these are native types. (Like choosing "Integer/float" over "Numeric", > "Char" over "Varchar" etc).=A0 Please do not conflate "char(n)" with native machine types like int or float. These are very different things. A char(n) is string of fixed but arbitrary length. This is not something a CPU can process in a single instruction. It has to go over it character by character. There is almost never a reason to use char(n). Just use varchar(n) or in the case of PostgreSQL just varchar or text. > However I do see even in Oracle databases, we have Integer type too, Not really. INTEGER is just an alias for NUMBER(38) in Oracle (see for example https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlqr/Data-Ty= pes.html). It's not the same as an INTEGER in PostgreSQL. hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --tn3evuqyxtj6aij5 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmXLhIMACgkQ8g5IURL+ KF1QcA//ZUs4N0wNHB5YFrmeb6XAr50dF9VH/30iD6ht3Hmq582KDR2FpPRSeIGZ 5Y8eKxuNMGJEw4WTL4y7d5zsHXn4wYevwNdlcuzbvoRzR/jnEEXy/6JdhjiEAJeI E17cfM7znxWvFanlQWCYTgJ1nk8COXbzBV2HmFN91OycPaU0oeYmVAjDMz1aWPP0 5n+OgZbUYX/U0s6O2XJefB4XxbjCihkTq7OhYFn9AZhUw4QGQ4eiSkSzCHxzDLbf pfEndxY72cY0gWxqA669EyCQ7mb8o50V3+GrF0StkBjCsPbYGKV9XCemiaGf5rNz PjLYtrBZlRiENdeKfBgJ5YEFUg/54ekXgnetzvP4dyoG2Ug4Rr7HhiNIPJUYme+M Jk0kGzXw3C56j1QGU7j5glR7mRpVG8oveldPRxPu+pPefnruGgdhiIHZ2yPaRt0W 9V29giwpHSlnuhJSdjU+EBA9M1L7wdT3uvV/feXt3fLCfqxPF7i+4Y63mz0sxjIf pIdA9DEDdUhLN3Wgkv6SiyLz7txUECUch/R9L2qAg1fco2cum5F/1vtUtU/lLlnc 6KO1HWRJ9QVlPbGJLLQ60a0yWs/KQkngw42nJE4UuxlzM+RzEVcX+WVAjLJBF8DH wCC5KOmSfipP4Kd3HNjcsfjGhkfb0Cg6J2hdom38uHcBXOiAtrI= =v0Lq -----END PGP SIGNATURE----- --tn3evuqyxtj6aij5--