| From: | Fujii Masao <masao(dot)fujii(at)gmail(dot)com> | 
|---|---|
| To: | Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> | 
| Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> | 
| Subject: | Re: Existence check for suitable index in advance when concurrently refreshing. | 
| Date: | 2016-02-09 07:27:19 | 
| Message-ID: | CAHGQGwH76FKzZsn4_CQGouw-xBtxe0123UB26773XT-tJ2ViKQ@mail.gmail.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
On Thu, Jan 28, 2016 at 1:01 AM, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> wrote:
> On Wed, Jan 27, 2016 at 4:42 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>> On Tue, Jan 26, 2016 at 9:33 PM, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> wrote:
>>> Hi all,
>>>
>>> In concurrently refreshing materialized view, we check whether that
>>> materialized view has suitable index(unique and not having WHERE
>>> condition), after filling data to new snapshot
>>> (refresh_matview_datafill()).
>>> This logic leads to taking a lot of time until postgres returns ERROR
>>> log if that table doesn't has suitable index and table is large. it
>>> wastes time.
>>> I think we should check whether that materialized view can use
>>> concurrently refreshing or not in advance.
>>
>> +1
>>
>>> The patch is attached.
>>>
>>> Please give me feedbacks.
>
> Thank you for having look at this patch.
>
>> +            indexRel = index_open(indexoid, RowExclusiveLock);
>>
>> Can we use AccessShareLock here, instead?
>
> Yeah, I think we can use it. Fixed.
>
>> +            if (indexStruct->indisunique &&
>> +                IndexIsValid(indexStruct) &&
>> +                RelationGetIndexExpressions(indexRel) == NIL &&
>> +                RelationGetIndexPredicate(indexRel) == NIL)
>> +                hasUniqueIndex = true;
>> +
>> +            index_close(indexRel, RowExclusiveLock);
>>
>> In the case where hasUniqueIndex = true, ISTM that we can get out of
>> the loop immediately just after calling index_close(). No?
>
> Fixed.
>
>> +    /* Must have at least one unique index */
>> +    Assert(foundUniqueIndex);
>>
>> Can we guarantee that there is at least one valid unique index here?
>> If yes, it's better to write the comment about that.
>>
>
> Added.
>
> Attached latest patch. Please review it.
Thanks for updating the patch!
Attached is the updated version of the patch.
I removed unnecessary assertion check and change of source code
that you added, and improved the source comment.
Barring objection, I'll commit this patch.
Regards,
-- 
Fujii Masao
| Attachment | Content-Type | Size | 
|---|---|---|
| matview_concurrently_refresh_check_index_v3.patch | text/x-patch | 1.7 KB | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Heikki Linnakangas | 2016-02-09 07:27:42 | Re: [Proposal] Improvement of GiST page layout | 
| Previous Message | Fabien COELHO | 2016-02-09 07:24:53 | Re: pgbench stats per script & other stuff |