pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter J. Holzer <hjp-pgsql@hjp.at>
To: pgsql-general@lists.postgresql.org
Subject: Re: How to do faster DML
Date: Tue, 13 Feb 2024 16:02:34 +0100
Message-ID: <20240213150234.ydiitfoowojhj2n3@hjp.at> (raw)
In-Reply-To: <CAB+=1TXv=RNOttpmzJOwbczSsaS0VnigFMLkPVY051fiVAxPdg@mail.gmail.com>
References: <CAB+=1TUfA7dra5DRqAoVvKvjTv5WndyNDiuvFw+bBR0qi6_tWQ@mail.gmail.com>
	<20240211002528.hjxls24vnnck7wsh@hjp.at>
	<CAB+=1TV1+1=6mXQhi=m7f_2XDXek=+xf8RBeAWv-Vhr4J8k2SQ@mail.gmail.com>
	<20240211133203.zw6ezhdzefyxmkd7@hjp.at>
	<CAB+=1TVP9xFM16J_ipQaL05UYQPAYyP51xzOSnvcmppBLKvYpA@mail.gmail.com>
	<CANzqJaDOjP=DY8ArVae0py_iSiS+JneQatB7seRhU29y7DqbXw@mail.gmail.com>
	<20240211222230.tt3mpjdvgrimeodu@hjp.at>
	<CAB+=1TVjov+y-8=d3ey-B7-Wj-23KPAKQQAejkjXcS50_KZ=pg@mail.gmail.com>
	<CAKAnmmLcTS7zpeZ3m7mkJxGsu+f+Tv9bp5KV3T52Q+c8DMTm+A@mail.gmail.com>
	<CAB+=1TXv=RNOttpmzJOwbczSsaS0VnigFMLkPVY051fiVAxPdg@mail.gmail.com>

On 2024-02-13 01:53:25 +0530, veem v wrote:
> On Mon, 12 Feb 2024 at 03:40, Peter J. Holzer <hjp-pgsql@hjp.at> wrote:
> 
>     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.
> 
>     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 the
>     same as you do when you're doing long addition or multiplication on
>     paper. So that's not very efficient.
> 
> 
> So it looks like the fixed length data type(like integer, float) should be the
> first choice while choosing the data type of the attributes wherever possible,
> as these are native types. (Like choosing "Integer/float" over "Numeric",
> "Char" over "Varchar" etc). 

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-Types.html).
It's not the same as an INTEGER in PostgreSQL.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachments:

  signature.asc (application/pgp-signature, 832B) download

view thread (67+ messages)  latest in thread

Message-ID: <20240213150234.ydiitfoowojhj2n3@hjp.at>
Permalink:  ../20240213150234.ydiitfoowojhj2n3@hjp.at/
Also on:    postgresql.org/message-id/20240213150234.ydiitfoowojhj2n3@hjp.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: hjp-pgsql@hjp.at
  Subject: Re: How to do faster DML
  In-Reply-To: <20240213150234.ydiitfoowojhj2n3@hjp.at>
  References: <CAB+=1TUfA7dra5DRqAoVvKvjTv5WndyNDiuvFw+bBR0qi6_tWQ@mail.gmail.com> <20240211002528.hjxls24vnnck7wsh@hjp.at> <CAB+=1TV1+1=6mXQhi=m7f_2XDXek=+xf8RBeAWv-Vhr4J8k2SQ@mail.gmail.com> <20240211133203.zw6ezhdzefyxmkd7@hjp.at> <CAB+=1TVP9xFM16J_ipQaL05UYQPAYyP51xzOSnvcmppBLKvYpA@mail.gmail.com> <CANzqJaDOjP=DY8ArVae0py_iSiS+JneQatB7seRhU29y7DqbXw@mail.gmail.com> <20240211222230.tt3mpjdvgrimeodu@hjp.at> <CAB+=1TVjov+y-8=d3ey-B7-Wj-23KPAKQQAejkjXcS50_KZ=pg@mail.gmail.com> <CAKAnmmLcTS7zpeZ3m7mkJxGsu+f+Tv9bp5KV3T52Q+c8DMTm+A@mail.gmail.com> <CAB+=1TXv=RNOttpmzJOwbczSsaS0VnigFMLkPVY051fiVAxPdg@mail.gmail.com> <20240213150234.ydiitfoowojhj2n3@hjp.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox