Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitad9a23b

Browse files
committed
Optimize Query jumble
f31aad9 adjusted query jumbling so it no longer ignores NULL nodesduring the jumble. This added some overhead. Here we tune a fewthings to make jumbling faster again. This makes jumbling performsimilar or even slightly faster than prior to that change.Author: David Rowley <dgrowleyml@gmail.com>Reviewed-by: Michael Paquier <michael@paquier.xyz>Discussion:https://postgr.es/m/CAApHDvreP04nhTKuYsPw0F-YN+4nr4f=L72SPeFb81jfv+2c7w@mail.gmail.com
1 parentf31aad9 commitad9a23b

File tree

1 file changed

+95
-9
lines changed

1 file changed

+95
-9
lines changed

‎src/backend/nodes/queryjumblefuncs.c

Lines changed: 95 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ DoJumble(JumbleState *jstate, Node *node)
218218

219219
/*
220220
* AppendJumbleInternal: Internal function for appending to the jumble buffer
221+
*
222+
* Note: Callers must ensure that size > 0.
221223
*/
222224
staticpg_attribute_always_inlinevoid
223225
AppendJumbleInternal(JumbleState*jstate,constunsignedchar*item,
@@ -226,16 +228,36 @@ AppendJumbleInternal(JumbleState *jstate, const unsigned char *item,
226228
unsignedchar*jumble=jstate->jumble;
227229
Sizejumble_len=jstate->jumble_len;
228230

231+
/* Ensure the caller didn't mess up */
232+
Assert(size>0);
233+
234+
/*
235+
* Fast path for when there's enough space left in the buffer. This is
236+
* worthwhile as means the memcpy can be inlined into very efficient code
237+
* when 'size' is a compile-time constant.
238+
*/
239+
if (likely(size <=JUMBLE_SIZE-jumble_len))
240+
{
241+
memcpy(jumble+jumble_len,item,size);
242+
jstate->jumble_len+=size;
243+
244+
#ifdefUSE_ASSERT_CHECKING
245+
jstate->total_jumble_len+=size;
246+
#endif
247+
248+
return;
249+
}
250+
229251
/*
230252
* Whenever the jumble buffer is full, we hash the current contents and
231253
* reset the buffer to contain just that hash value, thus relying on the
232254
* hash to summarize everything so far.
233255
*/
234-
while (size>0)
256+
do
235257
{
236258
Sizepart_size;
237259

238-
if (jumble_len >=JUMBLE_SIZE)
260+
if (unlikely(jumble_len >=JUMBLE_SIZE))
239261
{
240262
uint64start_hash;
241263

@@ -253,7 +275,7 @@ AppendJumbleInternal(JumbleState *jstate, const unsigned char *item,
253275
#ifdefUSE_ASSERT_CHECKING
254276
jstate->total_jumble_len+=part_size;
255277
#endif
256-
}
278+
}while (size>0);
257279

258280
jstate->jumble_len=jumble_len;
259281
}
@@ -281,6 +303,61 @@ AppendJumbleNull(JumbleState *jstate)
281303
jstate->pending_nulls++;
282304
}
283305

306+
/*
307+
* AppendJumble8
308+
*Add the first byte from the given 'value' pointer to the jumble state
309+
*/
310+
staticpg_noinlinevoid
311+
AppendJumble8(JumbleState*jstate,constunsignedchar*value)
312+
{
313+
if (jstate->pending_nulls>0)
314+
FlushPendingNulls(jstate);
315+
316+
AppendJumbleInternal(jstate,value,1);
317+
}
318+
319+
/*
320+
* AppendJumble16
321+
*Add the first 2 bytes from the given 'value' pointer to the jumble
322+
*state.
323+
*/
324+
staticpg_noinlinevoid
325+
AppendJumble16(JumbleState*jstate,constunsignedchar*value)
326+
{
327+
if (jstate->pending_nulls>0)
328+
FlushPendingNulls(jstate);
329+
330+
AppendJumbleInternal(jstate,value,2);
331+
}
332+
333+
/*
334+
* AppendJumble32
335+
*Add the first 4 bytes from the given 'value' pointer to the jumble
336+
*state.
337+
*/
338+
staticpg_noinlinevoid
339+
AppendJumble32(JumbleState*jstate,constunsignedchar*value)
340+
{
341+
if (jstate->pending_nulls>0)
342+
FlushPendingNulls(jstate);
343+
344+
AppendJumbleInternal(jstate,value,4);
345+
}
346+
347+
/*
348+
* AppendJumble64
349+
*Add the first 8 bytes from the given 'value' pointer to the jumble
350+
*state.
351+
*/
352+
staticpg_noinlinevoid
353+
AppendJumble64(JumbleState*jstate,constunsignedchar*value)
354+
{
355+
if (jstate->pending_nulls>0)
356+
FlushPendingNulls(jstate);
357+
358+
AppendJumbleInternal(jstate,value,8);
359+
}
360+
284361
/*
285362
* FlushPendingNulls
286363
*Incorporate the pending_null value into the jumble buffer.
@@ -417,9 +494,18 @@ IsSquashableConstList(List *elements, Node **firstExpr, Node **lastExpr)
417494
#defineJUMBLE_LOCATION(location) \
418495
RecordConstLocation(jstate, expr->location, false)
419496
#defineJUMBLE_FIELD(item) \
420-
AppendJumble(jstate, (const unsigned char *) &(expr->item), sizeof(expr->item))
421-
#defineJUMBLE_FIELD_SINGLE(item) \
422-
AppendJumble(jstate, (const unsigned char *) &(item), sizeof(item))
497+
do { \
498+
if (sizeof(expr->item) == 8) \
499+
AppendJumble64(jstate, (const unsigned char *) &(expr->item)); \
500+
else if (sizeof(expr->item) == 4) \
501+
AppendJumble32(jstate, (const unsigned char *) &(expr->item)); \
502+
else if (sizeof(expr->item) == 2) \
503+
AppendJumble16(jstate, (const unsigned char *) &(expr->item)); \
504+
else if (sizeof(expr->item) == 1) \
505+
AppendJumble8(jstate, (const unsigned char *) &(expr->item)); \
506+
else \
507+
AppendJumble(jstate, (const unsigned char *) &(expr->item), sizeof(expr->item)); \
508+
} while (0)
423509
#defineJUMBLE_STRING(str) \
424510
do { \
425511
if (expr->str) \
@@ -551,15 +637,15 @@ _jumbleList(JumbleState *jstate, Node *node)
551637
break;
552638
caseT_IntList:
553639
foreach(l,expr)
554-
JUMBLE_FIELD_SINGLE(lfirst_int(l));
640+
AppendJumble32(jstate, (constunsignedchar*)&lfirst_int(l));
555641
break;
556642
caseT_OidList:
557643
foreach(l,expr)
558-
JUMBLE_FIELD_SINGLE(lfirst_oid(l));
644+
AppendJumble32(jstate, (constunsignedchar*)&lfirst_oid(l));
559645
break;
560646
caseT_XidList:
561647
foreach(l,expr)
562-
JUMBLE_FIELD_SINGLE(lfirst_xid(l));
648+
AppendJumble32(jstate, (constunsignedchar*)&lfirst_xid(l));
563649
break;
564650
default:
565651
elog(ERROR,"unrecognized list node type: %d",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp