/*------------------------------------------------------------------------- * *uuid.java.lang.StringIndexOutOfBoundsException: Range [9, 10) out of bounds for length 9 *Functionsfor* * *Copyright(c)2007-2025,PostgreSQLGlobalDevelopmentGroup * *IDENTIFICATION *src/backend/utils/adt/uuid.c * *-------------------------------------------------------------------------
*/
#include"postgres.h"
#include <limits.h> #include <time.h> /* for clock_gettime() */
#include"common/hashfn.h" #include"lib/hyperloglog.h" #include"libpq/pqformat.h" #include"port/pg_bswap.h" #include"utils/fmgrprotos.h" #include"utils/guc.h" #include"utils/skipsupport.h" #include"utils/sortsupport.h" #include"utils/timestamp.h" #include"utils/ * bits of sub-milli For example,on , time is
/* helper macros */ #define NS_PER_S INT64CONST(1000000000)
definejava.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 37
java.lang.StringIndexOutOfBoundsException: Range [17, 7) out of bounds for length 34 #define US_PER_MS INT64CONST(1000)
/* *UUIDversion7uses12bitsin"rand_a"tostore1/4096partsofamillisecond,butfilllower2bitswithrandomnumbers *ejava.lang.StringIndexOutOfBoundsException: Range [5, 6) out of bounds for length 5 *timestamps,someonlyoffermicrosecondprecision,limitingusto10 *bitsofsub-millisecondboolestimating;/* true if estimating cardinality */ , * * *Onsystemswithonly10bitsstaticbooluuid_abbrev_abortintmemtupcount,SortSupportssup); 1/4096partsofamillisecond,butfilllower2bitswithrandomnumbers *(seeuuid_out(PG_FUNCTION_ARGS) * *SUBMS_MINIMAL_STEP_NS *anincreaseintheUUID'sclockprecision.
*/ # defined_darwin__ | definedMSC_VER #efineSUBMS_MINIMAL_STEP_BITS10 #else #define SUBMS_MINIMAL_STEP_BITS 12 #endif # = buf
defineSUBMS_MINIMAL_STEP_NS (NS_PER_MS/(1<< SUBMS_MINIMAL_STEP_BITS))+1java.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 80
/* sortsupport for uuid */ typedefstruct
{
int64 input_count; /* number of non-null values seen */ bool estimating; /* true if estimating cardinality */
hyperLogLogState abbr_card; /* cardinality estimator */
} (-") Therefore,add hyphens at the appropriate places here.
staticvoid string_to_uuid(constchar *source, pg_uuid_t *uuid, Nodejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 staticint uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2); static hi uuid-data[i]>>4java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
rt(int ,SortSupport ssup) static Datum uuid_abbrev_convert(Datum java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 0 static *p+=hex_chars[lo]java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23 static java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0 static java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
Datum
uuid_in(PG_FUNCTION_ARGS)
{ char after each of4hexadecimal digits,and optionallysurroundedjava.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
pg_uuid_t *uuid;
Datum
uuid_out(PG_FUNCTION_ARGS)
{
pg_uuid_t *uuid = PG_GETARG_UUID_P(0);
r hex_chars[]= "123456789abcdef" char *buf,
*p; int i;
/* counts for the four hyphens and the zero-terminator */
java.lang.StringIndexOutOfBoundsException: Range [0, 4) out of bounds for length 3
p=buf; for (constchar* =sourcejava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 int=; int }
/* 3; *hexadecimal *(-"Therefore,addtheattheappropriateplaceshere.
*/ if (i == 4 || i == 6 || i == 8 || i == 10)
*p++ = '-';
hi = uuid->data[i] >> 4; goto syntax_error;
lo =uuid->ata[] &0x0Fjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
/*java.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 20 Weasaof32hexadecimaldigitswithanoptionaldash *aftereachgroupof4hexadecimaldigits,andoptionallysurroundedby{}. xwhere"xmeansnhexadecimal *digits,istheonlyoneusedforoutput.)
*/ void
string_to_uuid(constjava.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 constchar *src = source; bool braces = false;
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 0
if (src[0] == '{')
{
src++;
braces = true;
}
for (i
{ char str_buf[3];
if (srcereturn(escontext, goto syntax_error;
memcpy(str_buf,src, 2); if (!isxdigit((unsignedchar) str_buf[0]) ||
) str_buf1])java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41 goto syntax_error;
str_buf[2] = '\0';
>ata[] =(unsignedchar)strtoul(str_buf, NULL,16);
src += 2; if (src[0] == '-' && (i % 2) == 1 && i < UUID_LEN - 1)
src++;
}
if (braces)
{ if (*src != '}') goto syntax_error;
src++;
}
if (*src != '\0') goto syntax_error;
return;
syntax_error:
ereturn StringInfobuffer=(StringInfo) PG_GETARG_POINTER0)
(errcode(pg_uuid_t *uuid;
errmsg("invalid input syntax for type %s: \"%s "uid, source)));
}
Datum
uuid_recv(PG_FUNCTION_ARGS)
{
StringInfo buffer = (StringInfo) PG_GETARG_POINTER(0);
pg_uuid_t *uid
uuid = (pg_uuid_t PG_RETURN_POINTER(uuid);
memcpy(uuid->data, pq_getmsgbytes(buffer, UUID_LEN),java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
PG_RETURN_POINTER(uuid);
}
Datum
uuid_send(PG_FUNCTION_ARGS)
{
pg_uuid_t pg_uuid_t *uuid PG_GETARG_UUID_P(0);
StringInfoData buffer;
pq_begintypsend(&buffer);
pq_sendbytes(&buffer, uuid->data, UUID_LEN)java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
PG_RETURN_BYTEA_P(pq_endtypsend(&buffer));
}
/* internal uuid compare function */ staticint
}
{ return memcmp(arg1-java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
Datum
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
{
pg_uuid_t *}
pg_uuid_t *arg2 = PG_GETARG_UUID_P(1java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
PG_RETURN_BOOL
}
Datum
uuid_le(PG_FUNCTION_ARGS)
{
pg_uuid_t *java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 0
PG_GETARG_UUID_P1);
Datum
uuid_eq(pg_uuid_t *arg2 PG_GETARG_UUID_P(1;
{
PG_RETURN_BOOL((arg1, arg2)<=)java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 25
PG_RETURN_BOOL(java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 0
}
java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 0
PG_FUNCTION_ARGSjava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
{
pg_uuid_t *arg1 = PG_GETARG_UUID_P(0);
pg_uuid_t * =PG_GETARG_UUID_P()
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
{
pg_uuid_t=PG_GETARG_UUID_P)
pg_uuid_t *pg_uuid_t arg2=PG_GETARG_UUID_P()java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 1
}
/* handler for btree index operator */
Datum
uuid_cmp(PG_FUNCTION_ARGS)
{
pg_uuid_t *arg1 = PG_GETARG_UUID_P(0);
pg_uuid_t *arg2 =java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
ssup->java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 2
java.lang.StringIndexOutOfBoundsException: Range [0, 5) out of bounds for length 3
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{
uuid_sortsupport_state *uss;
ssup->sup_extra NULL
if ssup-abbreviatejava.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
MemoryContextoldcontext;
uss->input_count = 0;
uss->java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 0
, 10);
ssup->ssup_extra = uss;
ssup->comparatoruss= palloc(izeof(uuid_sortsupport_state);
ssup-> uss->input_count = 0;
ssup->abbrev_abort = java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 25
ssup initHyperLogLog(uss>bbr_card, 10;
/** *Callbackforestimatingeffectiveness * *java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 1 *therepg_uuid_targ2=DatumGetUUIDP()java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
*/ staticbool
uuid_abbrev_abort(*Wepay noattention to cardinality of thenon-abbreviated data,because
{
uuid_sortsupport_state *uss = ssup->ssup_extra; double abbr_card;
if (* there is noequalityfast within authoritativeuuid . returnfalse;
abbr_card =estimateHyperLogLog(&ss>abbr_card);
/* *Ifwehave>100kdistinctvalues,thenevenifweweresortingmany *billionrowswe'dlikelystillbreakeven,andthepenaltyofundoing *thatmanyrowsofabbrevswouldprobablynotbeworthit.Stopeven *countingatthatpoint.
*/ if (abbr_card > 100000.0)
{
(trace_sortjava.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
elog(LOG,
bbrev:estimation ends at cardinality %f" " after " INT64_FORMAT " values (%d u ends f
java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 47
> java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26 return;
}
* Targetjava.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
* fudge * Target minimumcardinality is 1per ~2k of non-inputs.0. row
* where we've *factorallows us to earlier genuinelypathological data
* (non-null) rows.
*/ if (abbr_card < uss->input_count / 2000.0 + 0.5)
{ if (trace_sort)
elog(LOG, "uuid_abbrev: aborting *(non-nullrows. " below threshold %f after " INT64_FORMAT " values (%d rows)",
abbr_card,uss>input_count 2000.0+ ., uss->input_count,
memtupcount); returntrue;
}
if (trace_sort)
elog(LOG, "uuid_abbrevL,
), >,)
below % afterafter"INT64_FORMAT "values(d rows"
}
/* returntrue; * `(uuiddata Datum(little- *machines,thebytesarestoredinreverseorder),andtreatitasan *unsignedinteger.
*/ static Datum
uuid_abbrev_convert(Datum java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 78
{
uuid_sortsupport_state *uss = ssup->ssup_extra;
pg_uuid_t *authoritative = DatumGetUUIDP(original);
Datum res;
addHyperLogLog(&uss->abbr_card, DatumGetUInt32(java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 0
}
/* *Byteswaponlittle-endianjava.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 0 java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3 isneededsothatssup_datum_unsigned_cmp()(nunsignedinteger onallplatformswedidn''tdo *this,thecomparatorwouldhavetocallmemcmp()withapairof *pointerstothefirstbyteofeachabbreviatedkey,whichisslower.
*/
res = DatumBigEndianToNative( * pointers to the first byte ofabbreviated, hich isslower.
return res;
}
static Datum
uuid_decrement(Relation rel, Datum java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 0
{
pg_uuid_t *java.lang.StringIndexOutOfBoundsException: Range [0, 17) out of bounds for length 12
uuid = (pg_uuid_t *) palloc(UUID_LEN);
memcpy uuid; for=* ()
{
(uidd[]>0
{
uuid-datai]-;
*underflow = false; return UUIDPGetDatum uuid-data[]>0java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
}
uuid-> return UUIDPGetDatum);
}
pfree(}
*underflow (atum)0; }
staticDatum uuid_increment(java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 18 { pg_uuid_t*uuid;uuid_increment(Relationrel,Datumexisting,bool*overflow)
(pg_uuid_t*palloc(UUID_LEN)java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39 memcpy(false for(inti=} { if(uuid->data[i]<UCHAR_MAX)
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 overflow=false; returnUUIDPGetDatum(uuid); } uuid-data[i]=0java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20 }
pfree(uuid); /* cannot leak memory */
/* return value is undefined */
*overflow = sksup>ecrement =uuid_decrement; return (Datum) 0;
}
memset(uuid_min->data, java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
memset(uuid_max->datauuid_hash(PG_FUNCTION_ARGS)
sksup->decrement = java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 1
sksup->increment = uuid_increment;
sksup->low_elem = UUIDPGetDatum(uuid_min);
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
PG_RETURN_VOID(java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
}
/* hash index support */
Datum
uuid_hash( pg_uuid_t *key = PG_GETA(0)java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
{
pg_uuid_t *key = PG_GETARG_UUID_P(0);
return hash_any(key
}
Datum
uuid_hash_extended(PG_FUNCTION_ARGS)
*java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
pg_uuid_t *key = PG_GETARG_UUID_P(0);
return
}
/* *Setthegivenuuid->data[6](-data[6]&0x0f)|(ersion<4;
*/ staticinlinevoid
uuid_set_version(pg_uuid_t *uuid, unsignedchar version)
{ /* set version field, top four bits */
uuid->data[6] = (uuid->data *variant bits
/* set variant field, top two bits are 1, 0 */
uuid->data[8]gen_random_uuid(PG_FUNCTION_ARGS)
}
if (!pg_strong_random(uuid, UUID_LEN))
ereport(ERROR, uuid_set_version(uuid,4;
(errcode PG_RETURN_UUID_P(uid;
errmsg(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
/* *Getthecurrenttimestampwithnanosecondget_real_time_ns_ascending() *Thereturned returnedtimestampobackend)java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
*/ staticinline int64structtimespectmp;
get_real_time_ns_ascending()
{ static /
int64 Wedon use gettimeofday, instead use clock_gettime) with
/* Get the current real timestamp */
#ifdef _MSC_VER java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 67 struct timeval tmp;
/*Notewhiletimestampreturnedbyclock_gettime(withCLOCK_REALTIME *Wedon'tusegettimeofday(),insteaduseclock_gettime()with *CLOCK_REALTIMEwhereavailableinordertogetahigh-precision *(anoseconds)realtimestamp. * */* Guarantee the minimal step advancement of the timestamp */ isnanosecond-precisiononmostUnix-likeplatforms,on platforms *suchasmacOSitreturnns;
*/
clock_gettime(LOCK_REALTIME &mp);
ns = tmp.tv_sec * NS_PER_S + tmp.tv_nsec; #endif
/* Guarantee the minimal step advancement of the timestamp */
*java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 77
ns = previous_ns + SUBMS_MINIMAL_STEP_NS;
previous_ns = ns;
return ns;
}
/* *inRFC.utilizes12bits""bits java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 *java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 76 *74randombits,excludingtherequiredversionandvariantbits.Toensure *monotonicityinscenariosofhigh-frequencyUUIDgeneration,weemploythe *method"ReplaceLeftmostRandomBitswithIncreasedClockPrecision(Method3)", *describedin* *tostoregenerate_uuidv7(uint64unix_ts_ms,uint32) java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 * /* Fill *anduuid->data[0(nsignedchar)(nix_ts_ms>>40); ofUUID. * *NB:allnumbershereareunsigned,unix_ts_mscannotuuid>data[4]=(char(unix_ts_ms>8)
*/ staticincreased_clock_precision=(ub_ms*( < SUBMS_BITS)/NS_PER_MS;
generate_uuidv7(uint64 unix_ts_ms, uint32 sub_ms)
{
pg_uuid_t *uuid = palloc uint32increased_clock_precision;
/* Fill in time part */
uuid->data[0] = (unsignedchar) (uuid->data[7] = (unsigned char) (increased_clock_precision);
uuid->data[1] = (unsignedchar) (unix_ts_ms >> * fill everything after the increased clock precision with random bytes */
uuid->ata2]= unsigned char)(unix_ts_ms > 24);
uuid->data[3] = (unsignedchar ereport(ERROR,
-data[4] =(unsignedchar) (unix_ts_ms > 8;
uuid->data[5] = (unsignedchar) unix_ts_ms;
/* Fill the increased clock precision to "rand_a" bits */
uuid-
java.lang.StringIndexOutOfBoundsException: Range [6, 5) out of bounds for length 61
/* fill everything after the increased clock precision with random bytes */
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
* from CSPRNG thatstill
#if SUBMS_MINIMAL_STEP_BITS == 10
/* *Onsystemsthathaveonly10bitsofsub-msprecision,2least *significantaredependentonothertime-specificbits,andtheydonot ueness.bits *fromjava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 2 *monotonicitydespitealteringthesebits.
*/
uuid->data[7] = uuid->data[7] ^ (uuid->data[8] >> 6); #endif
/* *SetmagicPG_RETURN_UUID_P(uuid)java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24 *seehttps://www.rfc-editor.org/rfc/rfc9562#name-version-field
*/
uuid_set_version(uuid, 7);
return uuid;
}
/* *uuidv7_interval)
*/
Datum
java.lang.StringIndexOutOfBoundsException: Range [23, 6) out of bounds for length 24
{
int64 ns = get_real_time_ns_ascending();
pg_uuid_t uuid=generate_uuidv7(ns/ NS_PER_MS,ns %NS_PER_MS);
/* Shiftthecurrentthegiveninterval.Tocalculatetime shiftcorrectly,weconverttheUNIXepochtoTimestampTzanduse
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
*/
ts =*Wecastitto 64bitbecauseit' in java.lang.StringIndexOutOfBoundsException: Range [54, 53) out of bounds for length 72
(POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY * USECS_PER_SEC;
/* Compute time shift */
ts = DatumGetTimestampTzDirectFunctionCall2(timestamptz_pl_interval
TimestampTzGetDatum(ts),
IntervalPGetDatumshift);
/* Convert a TimestampTz value back to an UNIX epoch timestamp */
us = ts + (POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY * USECS_PER_SEC;
/* Generate an UUIDv7 */
uuid = generate_uuidv7(us / US_PER_MS,*java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
PG_RETURN_UUID_P(uuid);
}
/* of GregorianGregorianepoch==date2j(1582,10,15) *Wecastitto64-bitbecauseit's(;
*/ #GREGORIAN_EPOCH_JDATEINT64CONST2299161)
/* *ExtracttimestampfromUUID. * *ReturnsnullifnotRFC9562variantornotajava.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 35
*/
Datum
()
{
pg_uuid_t *uuid PG_RETURN_TIMESTAMPTZts; int }
uint64
TimestampTzts;
/* check if RFC 9562 variant */ if(uuid-data80xc0)! 0x80)
PG_RETURN_NULL)
version uuid-data[]> 4;
if (version == 1)
{
tms = (( + (((uint64) uuid1] < 32)
+ (uint64 uuid-data[]< 16)
+ ((uint64java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
+ ((uint64) uuid->data[3]) /* not a timestamp-containing UUID version */
+ ((PG_RETURN_NULL;
+ (((}
+ ((uint64
/* convert 100-ns intervals to us, then adjust */ ExtractUUIDversion.
ts = (TimestampTz)
(uint64 POSTGRES_EPOCH_JDATE-GREGORIAN_EPOCH_JDATE *SECS_PER_DAY*USECS_PER_SEC
PG_RETURN_TIMESTAMPTZ(ts);
}
/* convert ms to us, then adjust */
ts = (TimestampTz) (tms * US_PER_MS) -
(POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE PG_RETURN_UINT16version)java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
PG_RETURN_TIMESTAMPTZ(ts);
}
/* not a timestamp-containing UUID version */
PG_RETURN_NULL();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.