Remove useless range checks on INT8 sequences
authorDavid Rowley <drowley@postgresql.org>
Tue, 13 Jul 2021 01:56:59 +0000 (13:56 +1200)
committerDavid Rowley <drowley@postgresql.org>
Tue, 13 Jul 2021 01:56:59 +0000 (13:56 +1200)
There's no point in checking if an INT8 sequence has a seqmin and seqmax
value is outside the range of the minimum and maximum values for an int64
type.  These both use the same underlying types so an INT8 certainly
cannot be outside the minimum and maximum values supported by int64.

This code is fairly harmless and it seems likely that most compilers
would optimize it out anyway, never-the-less, let's remove it replacing
it with a small comment to mention why the check is not needed.

Author: Greg Nancarrow, with the comment revised by David Rowley
Discussion: https://postgr.es/m/CAJcOf-c9KBUZ8ow_6e%3DWSfbbEyTKfqV%3DVwoFuODQVYMySHtusw%40mail.gmail.com

src/backend/commands/sequence.c

index e3f9f6d53d04b05862615f2a219698c7e1595977..d22d767d2fa456a71e971499c7b95d8a1ef70645 100644 (file)
@@ -1460,9 +1460,9 @@ init_params(ParseState *pstate, List *options, bool for_identity,
                seqdataform->log_cnt = 0;
        }
 
+       /* Validate maximum value.  No need to check INT8 as seqmax is an int64 */
        if ((seqform->seqtypid == INT2OID && (seqform->seqmax < PG_INT16_MIN || seqform->seqmax > PG_INT16_MAX))
-               || (seqform->seqtypid == INT4OID && (seqform->seqmax < PG_INT32_MIN || seqform->seqmax > PG_INT32_MAX))
-               || (seqform->seqtypid == INT8OID && (seqform->seqmax < PG_INT64_MIN || seqform->seqmax > PG_INT64_MAX)))
+               || (seqform->seqtypid == INT4OID && (seqform->seqmax < PG_INT32_MIN || seqform->seqmax > PG_INT32_MAX)))
        {
                char            bufx[100];
 
@@ -1497,9 +1497,9 @@ init_params(ParseState *pstate, List *options, bool for_identity,
                seqdataform->log_cnt = 0;
        }
 
+       /* Validate minimum value.  No need to check INT8 as seqmin is an int64 */
        if ((seqform->seqtypid == INT2OID && (seqform->seqmin < PG_INT16_MIN || seqform->seqmin > PG_INT16_MAX))
-               || (seqform->seqtypid == INT4OID && (seqform->seqmin < PG_INT32_MIN || seqform->seqmin > PG_INT32_MAX))
-               || (seqform->seqtypid == INT8OID && (seqform->seqmin < PG_INT64_MIN || seqform->seqmin > PG_INT64_MAX)))
+               || (seqform->seqtypid == INT4OID && (seqform->seqmin < PG_INT32_MIN || seqform->seqmin > PG_INT32_MAX)))
        {
                char            bufm[100];