interplane.Get Omega
Read in your language

cortex

aien-dev/cortex

Brought by drakestapleton

branch main Branches Tags History

cortex / tests / fts / t_query.om

336 lines · 5609 bytes Raw Blame History
1note ===== tests/fts/t_query.om : search differential harness =====
2note usage: t_query DUMP QUERIES [OPS|- [ROUTE]] > out (QUERIES: records u32 length + MATCH bytes)
3note Each row is put in the group of its space (5 = none of the four) and each search runs in the
4note group of its space. ROUTE (a digit) forces the plan of fts_search: 0 chosen per query,
5note 1 group scan, 2 term lists, 3 every row. After the searches the incremental index is
6note compared with a rebuild (fts_icheck); a nonzero result is printed as a last line
7note "icheck=N", so it differs from the oracle's output.
8note prints, for every query x space x limit, the line format of `oracle query`:
9note q<i> s<space> l<limit> ok|err n=<rows>( <fts rowid>:<bm25 bits hex>)*
10note timing (monotonic ns over all fts_search calls) goes to stderr
11global tspc uchar 4194304
12text tsp0 "aien-lessons"
13text tsp1 "aien-sources"
14text tsp2 "atlas-memory"
15text tsp3 "survey-test-mask"
16text tsp4 "nope"
17text tok1 " ok n="
18text terr " err n="
19text ttm1 "searches="
20text ttm2 " total_ns="
21text ttm3 " max_ns="
22text ttm4 " load_ns="
23fn t_speq k ulong to bool
24n = get tsbn 0
25if eq k 0
26if ne n len tsp0
27ret false
28end
29for i ulong n
30if ne get tsb i get tsp0 i
31ret false
32end
33end
34ret true
35end
36if eq k 1
37if ne n len tsp1
38ret false
39end
40for i ulong n
41if ne get tsb i get tsp1 i
42ret false
43end
44end
45ret true
46end
47if eq k 2
48if ne n len tsp2
49ret false
50end
51for i ulong n
52if ne get tsb i get tsp2 i
53ret false
54end
55end
56ret true
57end
58if ne n len tsp3
59ret false
60end
61for i ulong n
62if ne get tsb i get tsp3 i
63ret false
64end
65end
66ret true
67end
68global tstat long 4
69global trc ulong 5
70text tic "icheck="
71text trt "plans none/group/terms/every-row/term-count-loop="
72global tqn uchar 1048576
73global tqc uchar 16777216
74global tqno ulong 65536
75global tqco ulong 65536
76fn main to int
77put qrte 0 t_route
78t0 = monons
79nf = t_load
80put tstat 3 sub monons t0
81if gt argcnt 3
82if not t_dash 3
83t_ops nf
84end
85end
86fq = t_open 2
87put tibn 0 0
88put tibp 0 0
89qi = ulong 0
90while t_need fq 4 bound 999999
91t_rdq fq
92for s ulong 5
93t_setok s nf
94for l ulong 4
95t_one qi s l
96end
97end
98qi = add qi 1
99end
100m = fts_icheck
101if ne m 0
102for i ulong len tic
103t_ch ulong get tic i
104end
105t_dec m
106t_ch 10
107end
108t_flush
109t_stats
110t_routes
111ret 0
112end
113note argv[4]: the forced plan (a digit), 0 when absent
114fn t_route to ulong
115if le argcnt 4
116ret 0
117end
118n = argread 4 targ 0 4096
119if lt n 1
120ret 0
121end
122ret sub ulong get targ 0 48
123end
124fn t_dash k ulong to bool
125n = argread k targ 0 4096
126ret and eq n 1 eq get targ 0 45
127end
128fn t_routes to void
129for i ulong len trt
130t_ch ulong get trt i
131end
132for k ulong 5
133if gt k 0
134t_ch 47
135end
136t_dec get trc k
137end
138t_ch 10
139w = write 2 tob 0 get tobn 0
140put tobn 0 0
141end
142fn t_load to ulong
143fd = t_open 1
144z = t_need fd 12
145put tibp 0 8
146nf = t_u32
147for r ulong nf
148z = t_need fd 8
149row = t_u64
150b = t_rdsb fd
151t_rdnm fd
152t_rdct fd
153b = t_rdsb fd
154b = t_rdsb fd
155z = t_need fd 1
156rt = get tib get tibp 0
157put tibp 0 add get tibp 0 1
158t_space r b rt
159t_keep r
160put qgr 0 ulong get tspc r
161if not fts_put r row
162exit 80
163end
164end
165ret nf
166end
167note keep row r's texts (qnm, qct) for later re-inserts
168fn t_keep r ulong to void
169a = get tqno r
170n = get qnml 0
171for i ulong n
172put tqn add a i get qnm i
173end
174put tqno add r 1 add a n
175a = get tqco r
176n = get qctl 0
177for i ulong n
178put tqc add a i get qct i
179end
180put tqco add r 1 add a n
181end
182note apply argv[3] ops ("D i" / "P i rowid" lines), then compact the token pool
183fn t_ops nf ulong to void
184fd = t_open 3
185put tibn 0 0
186put tibp 0 0
187z = t_fill fd
188while lt get tibp 0 get tibn 0 bound 999999
189op = get tib get tibp 0
190put tibp 0 add get tibp 0 2
191i = t_num
192if eq op 68
193fts_del i
194else
195rw = t_num
196t_rest i
197put qgr 0 ulong get tspc i
198if not fts_put i rw
199exit 81
200end
201end
202end
203fts_cmp
204end
205fn t_num to ulong
206v = ulong 0
207while true bound 30
208c = ulong get tib get tibp 0
209put tibp 0 add get tibp 0 1
210if or lt c 48 gt c 57
211ret v
212end
213v = add mul v 10 sub c 48
214end
215ret v
216end
217fn t_rest r ulong to void
218a = get tqno r
219n = sub get tqno add r 1 a
220for i ulong n
221put qnm i get tqn add a i
222end
223put qnml 0 n
224a = get tqco r
225n = sub get tqco add r 1 a
226for i ulong n
227put qct i get tqc add a i
228end
229put qctl 0 n
230end
231fn t_space r ulong b bool rt uchar to void
232sp = uchar 255
233if and b eq rt 0
234for k ulong 4
235if t_speq k
236sp = uchar k
237end
238end
239end
240put tspc r sp
241end
242fn t_rdq fq int to void
243n = t_u32
244z = t_need fq n
245p = get tibp 0
246for i ulong n
247put qq i get tib add p i
248end
249put tibp 0 add p n
250put qql 0 n
251end
252fn t_setok s ulong nf ulong to void
253for k ulong nf
254put qok k 0
255if eq ulong get tspc k s
256put qok k 1
257end
258end
259end
260fn t_one qi ulong s ulong l ulong to void
261lm = ulong 1
262if eq l 1
263lm = ulong 5
264end
265if eq l 2
266lm = ulong 12
267end
268if eq l 3
269lm = ulong 50
270end
271put qlim 0 lm
272put qgsel 0 s
273a = monons
274c = fts_search
275dt = sub monons a
276k = get qrst 0
277put trc k add get trc k 1
278if eq get qrst 2 1
279put trc 4 add get trc 4 1
280end
281put tstat 0 add get tstat 0 dt
282if gt dt get tstat 1
283put tstat 1 dt
284end
285put tstat 2 add get tstat 2 1
286t_line qi s lm c
287end
288fn t_stats to void
289for i ulong len ttm1
290t_ch ulong get ttm1 i
291end
292t_sdec get tstat 2
293for i ulong len ttm2
294t_ch ulong get ttm2 i
295end
296t_sdec get tstat 0
297for i ulong len ttm3
298t_ch ulong get ttm3 i
299end
300t_sdec get tstat 1
301for i ulong len ttm4
302t_ch ulong get ttm4 i
303end
304t_sdec get tstat 3
305t_ch 10
306n = get tobn 0
307w = write 2 tob 0 n
308put tobn 0 0
309end
310fn t_line qi ulong s ulong lm ulong c ulong to void
311t_ch 113
312t_dec qi
313t_ch 32
314t_ch 115
315t_dec s
316t_ch 32
317t_ch 108
318t_dec lm
319if not fts_bad
320for i ulong len tok1
321t_ch ulong get tok1 i
322end
323else
324for i ulong len terr
325t_ch ulong get terr i
326end
327end
328t_dec c
329for i ulong c
330t_ch 32
331t_dec get qdrow get qrd i
332t_ch 58
333t_hex bitcast ulong get qrb i 16
334end
335t_ch 10
336end