forked from timescale/timescaledb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan_iterator.c
60 lines (51 loc) · 1.62 KB
/
scan_iterator.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* This file and its contents are licensed under the Apache License 2.0.
* Please see the included NOTICE for copyright information and
* LICENSE-APACHE for a copy of the license.
*/
#include <postgres.h>
#include "scan_iterator.h"
TSDLLEXPORT void
ts_scan_iterator_set_index(ScanIterator *iterator, CatalogTable table, int indexid)
{
iterator->ctx.index = catalog_get_index(ts_catalog_get(), table, indexid);
}
void
ts_scan_iterator_end(ScanIterator *iterator)
{
ts_scanner_end_scan(&iterator->ctx);
}
void
ts_scan_iterator_close(ScanIterator *iterator)
{
/* Ending a scan is a no-op if already ended */
ts_scanner_end_scan(&iterator->ctx);
ts_scanner_close(&iterator->ctx);
}
TSDLLEXPORT void
ts_scan_iterator_scan_key_init(ScanIterator *iterator, AttrNumber attributeNumber,
StrategyNumber strategy, RegProcedure procedure, Datum argument)
{
MemoryContext oldmcxt;
Assert(iterator->ctx.scankey == NULL || iterator->ctx.scankey == iterator->scankey);
iterator->ctx.scankey = iterator->scankey;
if (iterator->ctx.nkeys >= EMBEDDED_SCAN_KEY_SIZE)
elog(ERROR, "cannot scan more than %d keys", EMBEDDED_SCAN_KEY_SIZE);
/*
* For rescans, when the scan key is reinitialized during the scan, make
* sure the scan key is initialized on the long-lived scankey memory
* context.
*/
oldmcxt = MemoryContextSwitchTo(iterator->ctx.internal.scan_mcxt);
ScanKeyInit(&iterator->scankey[iterator->ctx.nkeys++],
attributeNumber,
strategy,
procedure,
argument);
MemoryContextSwitchTo(oldmcxt);
}
TSDLLEXPORT void
ts_scan_iterator_rescan(ScanIterator *iterator)
{
ts_scanner_rescan(&iterator->ctx, NULL);
}