@@ -46,7 +46,7 @@ detoast_external_attr(struct varlena *attr)
46
46
{
47
47
struct varlena * result ;
48
48
49
- if (VARATT_IS_EXTERNAL_ONDISK ( attr ) || VARATT_IS_EXTERNAL_ONDISK_INLINE (attr ))
49
+ if (VARATT_IS_EXTERNAL_ONDISK_ANY (attr ))
50
50
{
51
51
/*
52
52
* This is an external stored plain value
@@ -115,7 +115,7 @@ detoast_external_attr(struct varlena *attr)
115
115
struct varlena *
116
116
detoast_attr (struct varlena * attr )
117
117
{
118
- if (VARATT_IS_EXTERNAL_ONDISK ( attr ) || VARATT_IS_EXTERNAL_ONDISK_INLINE (attr ))
118
+ if (VARATT_IS_EXTERNAL_ONDISK_ANY (attr ))
119
119
{
120
120
/*
121
121
* This is an externally stored datum --- fetch it back from there
@@ -226,15 +226,14 @@ detoast_attr_slice(struct varlena *attr,
226
226
//if (VARATT_IS_EXTERNAL_ONDISK_INLINE(attr))
227
227
//elog(ERROR, "slicing of chunked attributes is not yet supported"); /* FIXME */
228
228
229
- if (VARATT_IS_EXTERNAL_ONDISK (attr )||
230
- VARATT_IS_EXTERNAL_ONDISK_INLINE (attr ))
229
+ if (VARATT_IS_EXTERNAL_ONDISK_ANY (attr ))
231
230
{
232
- struct varatt_external toast_pointer ;
231
+ struct varatt_external_versioned toast_pointer ;
233
232
234
233
VARATT_EXTERNAL_INLINE_GET_POINTER (toast_pointer ,attr );
235
234
236
235
/* fast path for non-compressed external datums */
237
- if (!VARATT_EXTERNAL_IS_COMPRESSED (toast_pointer ))
236
+ if (!VARATT_EXTERNAL_IS_COMPRESSED (toast_pointer . va_external ))
238
237
return toast_fetch_datum_slice (attr ,sliceoffset ,slicelength );
239
238
240
239
/*
@@ -244,7 +243,7 @@ detoast_attr_slice(struct varlena *attr,
244
243
*/
245
244
if (slicelimit >=0 )
246
245
{
247
- int32 max_size = VARATT_EXTERNAL_GET_EXTSIZE (toast_pointer );
246
+ int32 max_size = VARATT_EXTERNAL_GET_EXTSIZE (toast_pointer . va_external );
248
247
249
248
/*
250
249
* Determine maximum amount of compressed data needed for a prefix
@@ -255,7 +254,7 @@ detoast_attr_slice(struct varlena *attr,
255
254
* determine how much compressed data we need to be sure of being
256
255
* able to decompress the required slice.
257
256
*/
258
- if (VARATT_EXTERNAL_GET_COMPRESS_METHOD (toast_pointer )==
257
+ if (VARATT_EXTERNAL_GET_COMPRESS_METHOD (toast_pointer . va_external )==
259
258
TOAST_PGLZ_COMPRESSION_ID )
260
259
max_size = pglz_maximum_compressed_size (slicelimit ,max_size );
261
260
@@ -346,9 +345,9 @@ detoast_attr_slice(struct varlena *attr,
346
345
DetoastIterator
347
346
create_detoast_iterator (struct varlena * attr )
348
347
{
349
- struct varatt_external toast_pointer ;
348
+ struct varatt_external_versioned toast_pointer ;
350
349
DetoastIterator iter ;
351
- if (VARATT_IS_EXTERNAL_ONDISK ( attr ) || VARATT_IS_EXTERNAL_ONDISK_INLINE (attr ))
350
+ if (VARATT_IS_EXTERNAL_ONDISK_ANY (attr ))
352
351
{
353
352
FetchDatumIterator fetch_iter ;
354
353
int32 inlineSize ;
@@ -363,13 +362,13 @@ create_detoast_iterator(struct varlena *attr)
363
362
/* Must copy to access aligned fields */
364
363
inlineSize = VARATT_EXTERNAL_INLINE_GET_POINTER (toast_pointer ,attr );
365
364
366
- if (VARATT_EXTERNAL_IS_COMPRESSED (toast_pointer ))
365
+ if (VARATT_EXTERNAL_IS_COMPRESSED (toast_pointer . va_external ))
367
366
{
368
367
iter -> compressed = true;
369
- iter -> compression_method = VARATT_EXTERNAL_GET_COMPRESS_METHOD (toast_pointer );
368
+ iter -> compression_method = VARATT_EXTERNAL_GET_COMPRESS_METHOD (toast_pointer . va_external );
370
369
371
370
/* prepare buffer to received decompressed data */
372
- iter -> buf = create_toast_buffer (toast_pointer .va_rawsize , false);
371
+ iter -> buf = create_toast_buffer (toast_pointer .va_external . va_rawsize , false);
373
372
}
374
373
else
375
374
{
@@ -472,21 +471,21 @@ toast_fetch_datum(struct varlena *attr)
472
471
{
473
472
Relation toastrel ;
474
473
struct varlena * result ;
475
- struct varatt_external toast_pointer ;
474
+ struct varatt_external_versioned toast_pointer ;
476
475
int32 attrsize ;
477
476
int32 inline_size ;
478
477
char * detoast_ptr ;
479
478
480
- if (!VARATT_IS_EXTERNAL_ONDISK ( attr ) && ! VARATT_IS_EXTERNAL_ONDISK_INLINE (attr ))
479
+ if (!VARATT_IS_EXTERNAL_ONDISK_ANY (attr ))
481
480
elog (ERROR ,"toast_fetch_datum shouldn't be called for non-ondisk datums" );
482
481
483
482
/* Must copy to access aligned fields */
484
483
inline_size = VARATT_EXTERNAL_INLINE_GET_POINTER (toast_pointer ,attr );
485
- attrsize = VARATT_EXTERNAL_GET_EXTSIZE (toast_pointer );
484
+ attrsize = VARATT_EXTERNAL_GET_EXTSIZE (toast_pointer . va_external );
486
485
487
486
result = (struct varlena * )palloc (attrsize + VARHDRSZ );
488
487
489
- if (VARATT_EXTERNAL_IS_COMPRESSED (toast_pointer ))
488
+ if (VARATT_EXTERNAL_IS_COMPRESSED (toast_pointer . va_external ))
490
489
SET_VARSIZE_COMPRESSED (result ,attrsize + VARHDRSZ );
491
490
else
492
491
SET_VARSIZE (result ,attrsize + VARHDRSZ );
@@ -511,10 +510,12 @@ toast_fetch_datum(struct varlena *attr)
511
510
/*
512
511
* Open the toast relation and its indexes
513
512
*/
514
- toastrel = table_open (toast_pointer .va_toastrelid ,AccessShareLock );
513
+ toastrel = table_open (toast_pointer .va_external . va_toastrelid ,AccessShareLock );
515
514
516
515
/* Fetch all chunks */
517
- table_relation_fetch_toast_slice (toastrel ,toast_pointer .va_valueid ,
516
+ table_relation_fetch_toast_slice (toastrel ,
517
+ toast_pointer .va_external .va_valueid ,
518
+ toast_pointer .va_version ,
518
519
attrsize - inline_size ,0 ,attrsize - inline_size ,
519
520
(struct varlena * )detoast_ptr );
520
521
@@ -541,12 +542,11 @@ toast_fetch_datum_slice(struct varlena *attr, int32 sliceoffset,
541
542
{
542
543
Relation toastrel ;
543
544
struct varlena * result ;
544
- struct varatt_external toast_pointer ;
545
+ struct varatt_external_versioned toast_pointer ;
545
546
int32 attrsize ;
546
547
int32 inline_size ;
547
548
548
- if (!VARATT_IS_EXTERNAL_ONDISK (attr )&&
549
- !VARATT_IS_EXTERNAL_ONDISK_INLINE (attr ))
549
+ if (!VARATT_IS_EXTERNAL_ONDISK_ANY (attr ))
550
550
elog (ERROR ,"toast_fetch_datum_slice shouldn't be called for non-ondisk datums" );
551
551
552
552
/* Must copy to access aligned fields */
@@ -557,9 +557,9 @@ toast_fetch_datum_slice(struct varlena *attr, int32 sliceoffset,
557
557
* prefix -- this isn't lo_* we can't return a compressed datum which is
558
558
* meaningful to toast later.
559
559
*/
560
- Assert (!VARATT_EXTERNAL_IS_COMPRESSED (toast_pointer )|| 0 == sliceoffset );
560
+ Assert (!VARATT_EXTERNAL_IS_COMPRESSED (toast_pointer . va_external )|| 0 == sliceoffset );
561
561
562
- attrsize = VARATT_EXTERNAL_GET_EXTSIZE (toast_pointer );
562
+ attrsize = VARATT_EXTERNAL_GET_EXTSIZE (toast_pointer . va_external );
563
563
564
564
if (sliceoffset >=attrsize )
565
565
{
@@ -572,7 +572,7 @@ toast_fetch_datum_slice(struct varlena *attr, int32 sliceoffset,
572
572
* space required by va_tcinfo, which is stored at the beginning as an
573
573
* int32 value.
574
574
*/
575
- if (VARATT_EXTERNAL_IS_COMPRESSED (toast_pointer )&& slicelength > 0 )
575
+ if (VARATT_EXTERNAL_IS_COMPRESSED (toast_pointer . va_external )&& slicelength > 0 )
576
576
slicelength = slicelength + sizeof (int32 );
577
577
578
578
/*
@@ -585,7 +585,7 @@ toast_fetch_datum_slice(struct varlena *attr, int32 sliceoffset,
585
585
586
586
result = (struct varlena * )palloc (slicelength + VARHDRSZ );
587
587
588
- if (VARATT_EXTERNAL_IS_COMPRESSED (toast_pointer ))
588
+ if (VARATT_EXTERNAL_IS_COMPRESSED (toast_pointer . va_external ))
589
589
SET_VARSIZE_COMPRESSED (result ,slicelength + VARHDRSZ );
590
590
else
591
591
SET_VARSIZE (result ,slicelength + VARHDRSZ );
@@ -619,10 +619,12 @@ toast_fetch_datum_slice(struct varlena *attr, int32 sliceoffset,
619
619
return result ;/* Can save a lot of work at this point! */
620
620
621
621
/* Open the toast relation */
622
- toastrel = table_open (toast_pointer .va_toastrelid ,AccessShareLock );
622
+ toastrel = table_open (toast_pointer .va_external . va_toastrelid ,AccessShareLock );
623
623
624
624
/* Fetch all chunks */
625
- table_relation_fetch_toast_slice (toastrel ,toast_pointer .va_valueid ,
625
+ table_relation_fetch_toast_slice (toastrel ,
626
+ toast_pointer .va_external .va_valueid ,
627
+ toast_pointer .va_version ,
626
628
attrsize - inline_size ,sliceoffset ,slicelength ,
627
629
result );
628
630
@@ -717,13 +719,13 @@ toast_raw_datum_size(Datum value)
717
719
struct varlena * attr = (struct varlena * )DatumGetPointer (value );
718
720
Size result ;
719
721
720
- if (VARATT_IS_EXTERNAL_ONDISK ( attr ) || VARATT_IS_EXTERNAL_ONDISK_INLINE (attr ))
722
+ if (VARATT_IS_EXTERNAL_ONDISK_ANY (attr ))
721
723
{
722
724
/* va_rawsize is the size of the original datum -- including header */
723
- struct varatt_external toast_pointer ;
725
+ struct varatt_external_versioned toast_pointer ;
724
726
725
727
VARATT_EXTERNAL_INLINE_GET_POINTER (toast_pointer ,attr );
726
- result = toast_pointer .va_rawsize ;
728
+ result = toast_pointer .va_external . va_rawsize ;
727
729
}
728
730
else if (VARATT_IS_EXTERNAL_INDIRECT (attr ))
729
731
{
@@ -773,18 +775,17 @@ toast_datum_size(Datum value)
773
775
struct varlena * attr = (struct varlena * )DatumGetPointer (value );
774
776
Size result ;
775
777
776
- if (VARATT_IS_EXTERNAL_ONDISK (attr )||
777
- VARATT_IS_EXTERNAL_ONDISK_INLINE (attr ))
778
+ if (VARATT_IS_EXTERNAL_ONDISK_ANY (attr ))
778
779
{
779
780
/*
780
781
* Attribute is stored externally - return the extsize whether
781
782
* compressed or not. We do not count the size of the toast pointer
782
783
* ... should we?
783
784
*/
784
- struct varatt_external toast_pointer ;
785
+ struct varatt_external_versioned toast_pointer ;
785
786
786
787
VARATT_EXTERNAL_INLINE_GET_POINTER (toast_pointer ,attr );
787
- result = VARATT_EXTERNAL_GET_EXTSIZE (toast_pointer );/* FIXME inlineSize */
788
+ result = VARATT_EXTERNAL_GET_EXTSIZE (toast_pointer . va_external );/* FIXME inlineSize */
788
789
}
789
790
else if (VARATT_IS_EXTERNAL_INDIRECT (attr ))
790
791
{