pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Using contrib modules in check (Re: pgsql: Fix BRIN to use SnapshotAny during summarization)
7+ messages / 4 participants
[nested] [flat]

* Using contrib modules in check (Re: pgsql: Fix BRIN to use SnapshotAny during summarization)
@ 2015-08-10 11:00  Christoph Berg <myon@debian.org>
  0 siblings, 1 reply; 7+ messages in thread

From: Christoph Berg @ 2015-08-10 11:00 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@alvh.no-ip.org>; +Cc: pgsql-committers; PostgreSQL Hackers <pgsql-hackers@postgresql.org>

Re: Tom Lane 2015-08-07 <928.1438900846@sss.pgh.pa.us>
> Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> > Fix BRIN to use SnapshotAny during summarization
> 
> This patch added an isolation test that fails unless contrib/pageinspect
> has been built and installed.  I do not find that acceptable.  It causes
> "make check-world" to fail ... and no, installing the extension during
> make check-world isn't going to make me happier.
> 
> I don't really think we need this isolation test at all, but if we do,
> please fix it to not rely on any extensions.  Perhaps looking at
> pg_relation_size or some such would do?  Or you could just issue
> a query that should use the index, and see if it finds the rows it
> ought to.

Hi,

this breaks the Debian package builds as well because we run
check-world as a build step.

Any chance for a fix/workaround so the nightly master/head builds will
succeed again?

Christoph
-- 
cb@df7cb.de | http://www.df7cb.de/


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Using contrib modules in check (Re: pgsql: Fix BRIN to use SnapshotAny during summarization)
@ 2015-08-10 14:08  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Christoph Berg <myon@debian.org>
  0 siblings, 2 replies; 7+ messages in thread

From: Tom Lane @ 2015-08-10 14:08 UTC (permalink / raw)
  To: Christoph Berg <myon@debian.org>; +Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>; pgsql-committers

Christoph Berg <myon@debian.org> writes:
> Re: Tom Lane 2015-08-07 <928.1438900846@sss.pgh.pa.us>
>> I don't really think we need this isolation test at all, but if we do,
>> please fix it to not rely on any extensions.  Perhaps looking at
>> pg_relation_size or some such would do?  Or you could just issue
>> a query that should use the index, and see if it finds the rows it
>> ought to.

> this breaks the Debian package builds as well because we run
> check-world as a build step.
> Any chance for a fix/workaround so the nightly master/head builds will
> succeed again?

I was waiting for Alvaro to deal with this, but perhaps he's on summer
vacation or something.  I will remove the isolation test until he has
time to address it more fully.

However, we did learn something valuable from the fact that all the
-DCLOBBER_CACHE_ALWAYS critters failed on it: per my earlier message,
brin_page_items() is unsafe against a relcache flush on the index.
I'll put that on the 9.5 open items list.

(If I were tasked with fixing it, I'd be tempted to rewrite it to do
all the work in one call and return a tuplestore; the alternative
seems to be to try to keep the index open across multiple calls,
which would be a mess.)

			regards, tom lane


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Using contrib modules in check (Re: pgsql: Fix BRIN to use SnapshotAny during summarization)
@ 2015-08-10 15:13  Christoph Berg <myon@debian.org>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 7+ messages in thread

From: Christoph Berg @ 2015-08-10 15:13 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>; pgsql-committers

Re: Tom Lane 2015-08-10 <2713.1439215712@sss.pgh.pa.us>
> I was waiting for Alvaro to deal with this, but perhaps he's on summer
> vacation or something.  I will remove the isolation test until he has
> time to address it more fully.

Thanks, the build worked now.

Wouldn't a possible fix be to promote this/some module to core? It
doesn't have any SQL- or OS-side dependencies.

Christoph
-- 
cb@df7cb.de | http://www.df7cb.de/


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Using contrib modules in check (Re: pgsql: Fix BRIN to use SnapshotAny during summarization)
@ 2015-08-10 15:19  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Christoph Berg <myon@debian.org>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2015-08-10 15:19 UTC (permalink / raw)
  To: Christoph Berg <myon@debian.org>; +Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>; pgsql-committers

Christoph Berg <myon@debian.org> writes:
> Thanks, the build worked now.

> Wouldn't a possible fix be to promote this/some module to core? It
> doesn't have any SQL- or OS-side dependencies.

Meh.  I think we'd agreed in another nearby thread that pageinspect
is exactly the sort of thing we don't want in core.  Even if it were
in core, I'm dubious that it's a good way to implement the desired
testing here: the risks of platform-dependent results (endianness,
varying numbers of tuples per page, etc etc) seem far too high.

			regards, tom lane


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Using contrib modules in check (Re: pgsql: Fix BRIN to use SnapshotAny during summarization)
@ 2015-08-10 15:33  Andres Freund <andres@anarazel.de>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Andres Freund @ 2015-08-10 15:33 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Christoph Berg <myon@debian.org>; Alvaro Herrera <alvherre@alvh.no-ip.org>; pgsql-committers

On 2015-08-10 11:19:56 -0400, Tom Lane wrote:
> Meh.  I think we'd agreed in another nearby thread that pageinspect
> is exactly the sort of thing we don't want in core.

I think we agreed that it shouldn't be included in an initdb'ed
database, but that doesn't preclude pageinspect being an extension in
src/extension or something.

> Even if it were
> in core, I'm dubious that it's a good way to implement the desired
> testing here: the risks of platform-dependent results (endianness,
> varying numbers of tuples per page, etc etc) seem far too high.

That on the other hand I can agree with being a danger.

Greetings,

Andres Freund


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [COMMITTERS] Using contrib modules in check (Re: pgsql: Fix BRIN to use SnapshotAny during summarization)
@ 2015-08-12 18:52  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 7+ messages in thread

From: Alvaro Herrera @ 2015-08-12 18:52 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Christoph Berg <myon@debian.org>; pgsql-hackers@postgresql.org

Tom Lane wrote:

> However, we did learn something valuable from the fact that all the
> -DCLOBBER_CACHE_ALWAYS critters failed on it: per my earlier message,
> brin_page_items() is unsafe against a relcache flush on the index.
> I'll put that on the 9.5 open items list.
> 
> (If I were tasked with fixing it, I'd be tempted to rewrite it to do
> all the work in one call and return a tuplestore; the alternative
> seems to be to try to keep the index open across multiple calls,
> which would be a mess.)

Here's a patch doing that.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachments:

brin-page-items.patch (text/x-diff, 10.1K) download commit 41eba17795e9cf9b0c23e05def5d33b0dbdd4807 Author: Alvaro Herrera <alvherre@alvh.no-ip.org> AuthorDate: Wed Aug 12 15:41:15 2015 -0300 CommitDate: Wed Aug 12 15:41:15 2015 -0300 fix brin_page_items to use a tuplestore diff --git a/contrib/pageinspect/brinfuncs.c b/contrib/pageinspect/brinfuncs.c index 7adcfa8..f695b18 100644 --- a/contrib/pageinspect/brinfuncs.c +++ b/contrib/pageinspect/brinfuncs.c @@ -37,18 +37,6 @@ typedef struct brin_column_state FmgrInfo outputFn[FLEXIBLE_ARRAY_MEMBER]; } brin_column_state; -typedef struct brin_page_state -{ - BrinDesc *bdesc; - Page page; - OffsetNumber offset; - bool unusedItem; - bool done; - AttrNumber attno; - BrinMemTuple *dtup; - brin_column_state *columns[FLEXIBLE_ARRAY_MEMBER]; -} brin_page_state; - static Page verify_brin_page(bytea *raw_page, uint16 type, const char *strtype); @@ -119,89 +107,90 @@ verify_brin_page(bytea *raw_page, uint16 type, const char *strtype) Datum brin_page_items(PG_FUNCTION_ARGS) { - brin_page_state *state; - FuncCallContext *fctx; + bytea *raw_page = PG_GETARG_BYTEA_P(0); + Oid indexRelid = PG_GETARG_OID(1); + ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; + TupleDesc tupdesc; + MemoryContext oldcontext; + Tuplestorestate *tupstore; + Relation indexRel; + Page page; + OffsetNumber offset; + AttrNumber attno; + bool unusedItem; + BrinDesc *bdesc; + BrinMemTuple *dtup; + brin_column_state **columns; if (!superuser()) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errmsg("must be superuser to use raw page functions")))); - if (SRF_IS_FIRSTCALL()) + /* check to see if caller supports us returning a tuplestore */ + if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo)) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("set-valued function called in context that cannot accept a set"))); + if (!(rsinfo->allowedModes & SFRM_Materialize) || + rsinfo->expectedDesc == NULL) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("materialize mode required, but it is not allowed in this context"))); + + /* Build a tuple descriptor for our result type */ + if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) + elog(ERROR, "return type must be a row type"); + + /* Build tuplestore to hold the result rows */ + oldcontext = MemoryContextSwitchTo(rsinfo->econtext->ecxt_per_query_memory); + + tupstore = tuplestore_begin_heap(true, false, work_mem); + rsinfo->returnMode = SFRM_Materialize; + rsinfo->setResult = tupstore; + rsinfo->setDesc = tupdesc; + + MemoryContextSwitchTo(oldcontext); + + indexRel = index_open(indexRelid, AccessShareLock); + + /* minimally verify the page we got */ + page = verify_brin_page(raw_page, BRIN_PAGETYPE_REGULAR, "regular"); + + bdesc = brin_build_desc(indexRel); + offset = FirstOffsetNumber; + unusedItem = false; + dtup = NULL; + + /* + * Initialize output functions for all indexed datatypes; simplifies + * calling them later. + */ + columns = palloc(sizeof(brin_column_state *) * RelationGetDescr(indexRel)->natts); + for (attno = 1; attno <= bdesc->bd_tupdesc->natts; attno++) { - bytea *raw_page = PG_GETARG_BYTEA_P(0); - Oid indexRelid = PG_GETARG_OID(1); - Page page; - TupleDesc tupdesc; - MemoryContext mctx; - Relation indexRel; - AttrNumber attno; + Oid output; + bool isVarlena; + BrinOpcInfo *opcinfo; + int i; + brin_column_state *column; - /* minimally verify the page we got */ - page = verify_brin_page(raw_page, BRIN_PAGETYPE_REGULAR, "regular"); + opcinfo = bdesc->bd_info[attno - 1]; + column = palloc(offsetof(brin_column_state, outputFn) + + sizeof(FmgrInfo) * opcinfo->oi_nstored); - /* create a function context for cross-call persistence */ - fctx = SRF_FIRSTCALL_INIT(); - - /* switch to memory context appropriate for multiple function calls */ - mctx = MemoryContextSwitchTo(fctx->multi_call_memory_ctx); - - /* Build a tuple descriptor for our result type */ - if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) - elog(ERROR, "return type must be a row type"); - - indexRel = index_open(indexRelid, AccessShareLock); - - state = palloc(offsetof(brin_page_state, columns) + - sizeof(brin_column_state) * RelationGetDescr(indexRel)->natts); - - state->bdesc = brin_build_desc(indexRel); - state->page = page; - state->offset = FirstOffsetNumber; - state->unusedItem = false; - state->done = false; - state->dtup = NULL; - - /* - * Initialize output functions for all indexed datatypes; simplifies - * calling them later. - */ - for (attno = 1; attno <= state->bdesc->bd_tupdesc->natts; attno++) + column->nstored = opcinfo->oi_nstored; + for (i = 0; i < opcinfo->oi_nstored; i++) { - Oid output; - bool isVarlena; - BrinOpcInfo *opcinfo; - int i; - brin_column_state *column; - - opcinfo = state->bdesc->bd_info[attno - 1]; - column = palloc(offsetof(brin_column_state, outputFn) + - sizeof(FmgrInfo) * opcinfo->oi_nstored); - - column->nstored = opcinfo->oi_nstored; - for (i = 0; i < opcinfo->oi_nstored; i++) - { - getTypeOutputInfo(opcinfo->oi_typcache[i]->type_id, &output, &isVarlena); - fmgr_info(output, &column->outputFn[i]); - } - - state->columns[attno - 1] = column; + getTypeOutputInfo(opcinfo->oi_typcache[i]->type_id, &output, &isVarlena); + fmgr_info(output, &column->outputFn[i]); } - index_close(indexRel, AccessShareLock); - - fctx->user_fctx = state; - fctx->tuple_desc = BlessTupleDesc(tupdesc); - - MemoryContextSwitchTo(mctx); + columns[attno - 1] = column; } - fctx = SRF_PERCALL_SETUP(); - state = fctx->user_fctx; - - if (!state->done) + for (;;) { - HeapTuple result; Datum values[7]; bool nulls[7]; @@ -211,39 +200,32 @@ brin_page_items(PG_FUNCTION_ARGS) * signal for obtaining and decoding the next one. If that's not the * case, we output the next attribute. */ - if (state->dtup == NULL) + if (dtup == NULL) { BrinTuple *tup; - MemoryContext mctx; ItemId itemId; - /* deformed tuple must live across calls */ - mctx = MemoryContextSwitchTo(fctx->multi_call_memory_ctx); - /* verify item status: if there's no data, we can't decode */ - itemId = PageGetItemId(state->page, state->offset); + itemId = PageGetItemId(page, offset); if (ItemIdIsUsed(itemId)) { - tup = (BrinTuple *) PageGetItem(state->page, - PageGetItemId(state->page, - state->offset)); - state->dtup = brin_deform_tuple(state->bdesc, tup); - state->attno = 1; - state->unusedItem = false; + tup = (BrinTuple *) + PageGetItem(page, PageGetItemId(page, offset)); + dtup = brin_deform_tuple(bdesc, tup); + attno = 1; + unusedItem = false; } else - state->unusedItem = true; - - MemoryContextSwitchTo(mctx); + unusedItem = true; } else - state->attno++; + attno++; MemSet(nulls, 0, sizeof(nulls)); - if (state->unusedItem) + if (unusedItem) { - values[0] = UInt16GetDatum(state->offset); + values[0] = UInt16GetDatum(offset); nulls[1] = true; nulls[2] = true; nulls[3] = true; @@ -253,17 +235,17 @@ brin_page_items(PG_FUNCTION_ARGS) } else { - int att = state->attno - 1; + int att = attno - 1; - values[0] = UInt16GetDatum(state->offset); - values[1] = UInt32GetDatum(state->dtup->bt_blkno); - values[2] = UInt16GetDatum(state->attno); - values[3] = BoolGetDatum(state->dtup->bt_columns[att].bv_allnulls); - values[4] = BoolGetDatum(state->dtup->bt_columns[att].bv_hasnulls); - values[5] = BoolGetDatum(state->dtup->bt_placeholder); - if (!state->dtup->bt_columns[att].bv_allnulls) + values[0] = UInt16GetDatum(offset); + values[1] = UInt32GetDatum(dtup->bt_blkno); + values[2] = UInt16GetDatum(attno); + values[3] = BoolGetDatum(dtup->bt_columns[att].bv_allnulls); + values[4] = BoolGetDatum(dtup->bt_columns[att].bv_hasnulls); + values[5] = BoolGetDatum(dtup->bt_placeholder); + if (!dtup->bt_columns[att].bv_allnulls) { - BrinValues *bvalues = &state->dtup->bt_columns[att]; + BrinValues *bvalues = &dtup->bt_columns[att]; StringInfoData s; bool first; int i; @@ -272,14 +254,14 @@ brin_page_items(PG_FUNCTION_ARGS) appendStringInfoChar(&s, '{'); first = true; - for (i = 0; i < state->columns[att]->nstored; i++) + for (i = 0; i < columns[att]->nstored; i++) { char *val; if (!first) appendStringInfoString(&s, " .. "); first = false; - val = OutputFunctionCall(&state->columns[att]->outputFn[i], + val = OutputFunctionCall(&columns[att]->outputFn[i], bvalues->bv_values[i]); appendStringInfoString(&s, val); pfree(val); @@ -295,35 +277,35 @@ brin_page_items(PG_FUNCTION_ARGS) } } - result = heap_form_tuple(fctx->tuple_desc, values, nulls); + tuplestore_putvalues(tupstore, tupdesc, values, nulls); /* * If the item was unused, jump straight to the next one; otherwise, * the only cleanup needed here is to set our signal to go to the next * tuple in the following iteration, by freeing the current one. */ - if (state->unusedItem) - state->offset = OffsetNumberNext(state->offset); - else if (state->attno >= state->bdesc->bd_tupdesc->natts) + if (unusedItem) + offset = OffsetNumberNext(offset); + else if (attno >= bdesc->bd_tupdesc->natts) { - pfree(state->dtup); - state->dtup = NULL; - state->offset = OffsetNumberNext(state->offset); + pfree(dtup); + dtup = NULL; + offset = OffsetNumberNext(offset); } /* - * If we're beyond the end of the page, set flag to end the function - * in the following iteration. + * If we're beyond the end of the page, we're done. */ - if (state->offset > PageGetMaxOffsetNumber(state->page)) - state->done = true; - - SRF_RETURN_NEXT(fctx, HeapTupleGetDatum(result)); + if (offset > PageGetMaxOffsetNumber(page)) + break; } - brin_free_desc(state->bdesc); + /* clean up and return the tuplestore */ + brin_free_desc(bdesc); + tuplestore_donestoring(tupstore); + index_close(indexRel, AccessShareLock); - SRF_RETURN_DONE(fctx); + return (Datum) 0; } Datum
^ permalink raw reply [nested|flat] 7+ messages in thread

* Re: Re: [COMMITTERS] Using contrib modules in check (Re: pgsql: Fix BRIN to use SnapshotAny during summarization)
@ 2015-08-13 16:03  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Alvaro Herrera @ 2015-08-13 16:03 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Christoph Berg <myon@debian.org>; pgsql-hackers@postgresql.org

Alvaro Herrera wrote:
> Tom Lane wrote:

> > (If I were tasked with fixing it, I'd be tempted to rewrite it to do
> > all the work in one call and return a tuplestore; the alternative
> > seems to be to try to keep the index open across multiple calls,
> > which would be a mess.)
> 
> Here's a patch doing that.

Pushed, thanks.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2015-08-13 16:03 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-08-10 11:00 Using contrib modules in check (Re: pgsql: Fix BRIN to use SnapshotAny during summarization) Christoph Berg <myon@debian.org>
2015-08-10 14:08 ` Tom Lane <tgl@sss.pgh.pa.us>
2015-08-10 15:13   ` Christoph Berg <myon@debian.org>
2015-08-10 15:19     ` Tom Lane <tgl@sss.pgh.pa.us>
2015-08-10 15:33       ` Andres Freund <andres@anarazel.de>
2015-08-12 18:52   ` Alvaro Herrera <alvherre@2ndquadrant.com>
2015-08-13 16:03     ` Alvaro Herrera <alvherre@2ndquadrant.com>

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