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

Commitefe0713

Browse files
author
Artur Zakirov
committed
Remove duplicated times after collectMatchRumKey
1 parent790c362 commitefe0713

File tree

2 files changed

+68
-13
lines changed

2 files changed

+68
-13
lines changed

‎expected/orderby.out

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ SELECT id, d, d <-> '2016-05-16 14:21:25' FROM tsts ORDER BY d <-> '2016-05-16 1
194194
(3 rows)
195195

196196
SELECT id, d, d <-> '2016-05-16 14:21:25' FROM tsts ORDER BY d <-> '2016-05-16 14:21:25' LIMIT 5;
197-
id | d | ?column?
198-
-----+---------------------------------+----------
199-
355 | Mon May 16 14:21:22.326724 2016 | 2.673276
200-
355 | Mon May 1614:21:22.326724 2016 |2.673276
201-
355 | Mon May 1614:21:22.326724 2016 |2.673276
202-
355 | Mon May 1614:21:22.326724 2016 |2.673276
203-
355 | Mon May 1614:21:22.326724 2016 |2.673276
197+
id | d |?column?
198+
-----+---------------------------------+-------------
199+
355 | Mon May 16 14:21:22.326724 2016 |2.673276
200+
356 | Mon May 1615:21:22.326724 2016 |3597.326724
201+
354 | Mon May 1613:21:22.326724 2016 |3602.673276
202+
357 | Mon May 1616:21:22.326724 2016 |7197.326724
203+
353 | Mon May 1612:21:22.326724 2016 |7202.673276
204204
(5 rows)
205205

‎rumget.c

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static bool scanPage(RumState *rumstate, RumScanEntry entry, ItemPointer item,
3838
Pagepage,boolequalOk);
3939
staticvoidinsertScanItem(RumScanOpaqueso,boolrecheck);
4040
staticintscan_entry_cmp(constvoid*p1,constvoid*p2);
41+
staticintrum_key_cmp_with_check(constvoid*p1,constvoid*p2,void*arg);
4142
staticvoidentryGetItem(RumState*rumstate,RumScanEntryentry);
4243

4344

@@ -414,6 +415,41 @@ collectMatchBitmap(RumBtreeData *btree, RumBtreeStack *stack,
414415
}
415416
}
416417

418+
/*
419+
* Sort array of RumKey and remove duplicates.
420+
*
421+
* Returns new size of the array.
422+
*/
423+
staticuint32
424+
sortAndUniqRumKeys(RumKey*list,uint32nlist)
425+
{
426+
uint32i,j;
427+
boolhaveDups= false;
428+
429+
if (nlist<2)
430+
returnnlist;
431+
432+
qsort_arg(list,nlist,sizeof(RumKey),rum_key_cmp_with_check,
433+
(void*)&haveDups);
434+
435+
/* There are duplicates, remove them */
436+
if (haveDups)
437+
{
438+
j=1;
439+
for (i=1;i<nlist;i++)
440+
{
441+
if (rumCompareItemPointers(&list[i-1].iptr,&list[i].iptr)!=0)
442+
{
443+
list[j]=list[i];
444+
j++;
445+
}
446+
}
447+
returnj;
448+
}
449+
else
450+
returnnlist;
451+
}
452+
417453
staticvoid
418454
collectMatchRumKey(RumBtreeData*btree,RumBtreeStack*stack,
419455
RumScanEntryentry)
@@ -588,14 +624,16 @@ collectMatchRumKey(RumBtreeData *btree, RumBtreeStack *stack,
588624
}
589625
elseif (RumGetNPosting(itup)>0)
590626
{
591-
uint32j;
627+
uint32off,count;
592628

593-
j=entry->nlist;
594-
entry->nlist+=RumGetNPosting(itup);
595-
entry->predictNumberResult+=RumGetNPosting(itup);
629+
count=RumGetNPosting(itup);
630+
631+
off=entry->nlist;
632+
entry->nlist+=count;
633+
entry->predictNumberResult+=count;
596634
if (entry->nalloc==0)
597635
{
598-
entry->nalloc=Max(RumGetNPosting(itup),32);
636+
entry->nalloc=Max(count,32);
599637
entry->list= (RumKey*)palloc(entry->nalloc*sizeof(RumKey));
600638
}
601639
elseif (entry->nlist>entry->nalloc)
@@ -605,7 +643,7 @@ collectMatchRumKey(RumBtreeData *btree, RumBtreeStack *stack,
605643
repalloc(entry->list,entry->nalloc*sizeof(RumKey));
606644
}
607645

608-
rumReadTuple(btree->rumstate,entry->attnum,itup,entry->list+j);
646+
rumReadTuple(btree->rumstate,entry->attnum,itup,entry->list+off);
609647
entry->isFinished= FALSE;
610648
}
611649

@@ -696,6 +734,7 @@ startScanEntry(RumState *rumstate, RumScanEntry entry)
696734
{
697735
btreeEntry.findItem(&btreeEntry,stackEntry);
698736
collectMatchRumKey(&btreeEntry,stackEntry,entry);
737+
entry->nlist=sortAndUniqRumKeys(entry->list,entry->nlist);
699738
}
700739
elseif (btreeEntry.findItem(&btreeEntry,stackEntry))
701740
{
@@ -810,6 +849,22 @@ scan_entry_cmp(const void *p1, const void *p2)
810849
return-cmpEntries(e1,e2);
811850
}
812851

852+
staticint
853+
rum_key_cmp_with_check(constvoid*p1,constvoid*p2,void*arg)
854+
{
855+
constRumKey*k1= (constRumKey*)p1;
856+
constRumKey*k2= (constRumKey*)p2;
857+
bool*haveDups= (bool*)arg;
858+
intres;
859+
860+
res=rumCompareItemPointers(&k1->iptr,&k2->iptr);
861+
862+
if (res==0)
863+
*haveDups= true;
864+
865+
returnres;
866+
}
867+
813868
staticvoid
814869
startScan(IndexScanDescscan)
815870
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp