From 46830c7eeecf2c117ea3a15584d985ff1736a762 Mon Sep 17 00:00:00 2001 From: linqiang <1667704220@qq.com> Date: Tue, 3 Dec 2024 16:01:05 +0800 Subject: [PATCH] =?UTF-8?q?subvector=E5=87=BD=E6=95=B0=E7=9A=84=E5=8F=82?= =?UTF-8?q?=E6=95=B02=E4=BB=A3=E8=A1=A8=E7=9A=84=E8=B5=B7=E5=A7=8B?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E5=A2=9E=E5=8A=A0=E8=8C=83=E5=9B=B4=E9=99=90?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/utils/adt/vector.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/common/backend/utils/adt/vector.cpp b/src/common/backend/utils/adt/vector.cpp index db2365eb9..7cd2ce324 100644 --- a/src/common/backend/utils/adt/vector.cpp +++ b/src/common/backend/utils/adt/vector.cpp @@ -1099,6 +1099,14 @@ Datum subvector(PG_FUNCTION_ARGS) ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION), errmsg("vector must have at least 1 dimension"))); } + /* Indexing starts at 1, like substring */ + if (start < 1) { + ereport(WARNING, (errmsg("when the start position is less than 1, it will begin with the first dimension"))); + start = 1; + } else if (start > a->dim) { + ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION), errmsg("vector must have at least 1 dimension"))); + } + /* * Check if (start + count > a->dim), avoiding integer overflow. a->dim * and count are both positive, so a->dim - count won't overflow. @@ -1109,13 +1117,6 @@ Datum subvector(PG_FUNCTION_ARGS) end = start + count; } - /* Indexing starts at 1, like substring */ - if (start < 1) { - start = 1; - } else if (start > a->dim) { - ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION), errmsg("vector must have at least 1 dimension"))); - } - dim = end - start; CheckDim(dim); result = InitVector(dim);