Comments (45)
v2.0.2
Looks good, still there is a problem
findall([A,_,_],member([A,B,C],Data),Fraud)
:
Fraud detected: ['Jack',1,5000]/[['Jack',_97,_98],['Jack',_99,_100]]
Fraud detected: ['Jack',2,4500]/[['Jack',_100,_101],['Jack',_102,_103]]
Fraud detected: ['Jack',3,4750]/[['Jack',_115,_116],['Jack',_117,_118]]
Fraud detected: ['Jones',1,5500]/[['Jones',_130,_131],['Jones',_132,_133]]
Fraud detected: ['Jones',2,6500]/[['Jones',_145,0],['Jones',_146,0]] % 0 is not a variable
Fraud detected: ['Jones',3,6000]/[['Jones',0,0],['Jones',0,0]] % 0,0 ...
If more impermissible entries inserted , the problem is back.
/* These are valid but impermissible entries */
insert into data(name,month,score) values('Jack', 1, -500);
insert into data(name,month,score) values('Jones', 1, 500);
insert into data(name,month,score) values('Jack', 2, -2000);
insert into data(name,month,score) values('Jones', 2, 2000);
insert into data(name,month,score) values('Jack', 3, -1250);
insert into data(name,month,score) values('Jones', 3, 1250);
insert into data(name,month,score) values('Jack', 1, -500);
insert into data(name,month,score) values('Jones', 1, 500);
insert into data(name,month,score) values('Jack', 2, -2000);
insert into data(name,month,score) values('Jones', 2, 2000);
insert into data(name,month,score) values('Jack', 3, -1250);
insert into data(name,month,score) values('Jones', 3, 1250);
findall([A,_,_],member([A,B,C],Data),Fraud)
:
Fraud detected: ['Jones',1,6000]/[['Jones',_140,_141],['Jones',_142,_143],['Jones',_144,_145]]
Fraud detected: ['Jones',2,8500]/[['Jones','insert into result(name,jan,feb,mar) select name, SUM(score*(1-abs(sign(month-1)))), SUM(score*(1-abs(sign(month-2)))), SUM(score*(1-abs(sign(month-3)))) from data group by name',0],['Jones','insert into result(name,jan,feb,mar) select name, SUM(score*(1-abs(sign(month-1)))), SUM(score*(1-abs(sign(month-2)))), SUM(score*(1-abs(sign(month-3)))) from data group by name',0],['Jones','insert into result(name,jan,feb,mar) select name, SUM(score*(1-abs(sign(month-1)))), SUM(score*(1-abs(sign(month-2)))), SUM(score*(1-abs(sign(month-3)))) from data group by name',0]]
Fraud detected: ['Jones',3,7250]/[['Jones',_166,_167],['Jones',_168,_169],['Jones',_170,_171]]
from trealla.
Too bad.
Having 10000 impermissible entries in the database
bagof/3 just works but
findall/3 crashes
sometimes with
realloc(): invalid next size Aborted (core dumped)
or sometimes
Segmentation fault (core dumped)
from trealla.
from trealla.
725 impermissible entries, findall starts crashing
On the other hand, 724 entries, findall/3 works like bagof/3, thats good(no sql or 0s in the lists)
(F..k linux buffers, sometimes crashing starts with 726 entires)
from trealla.
from trealla.
findall([A,_,_],member([A,B,C],Data),Fraud)
If this is the template? [A, _, _], A is used to transport the value from member into list Fraud? and 2 anon.
The position of A should have nothing to do with position A in member([A,B,C] ...
What I want is what I get: Fraud = [ [A,_,_], [A,_,_], ...]
This template?
findall([_,_,A,_,_],member([A,B,C],Data),Fraud)
produced this:
[_2724,_2725,'Jones',_2726,_2727],[_2728,_2729,'Jones',_2730,_2731],[_2732,_2733,'Jones',_2734,_2735],[_2736,_2737,'Jones',_2738,_2739]]
tpl: src/heap.c:23: alloc_grow: Assertion `min_elements <= max_elements' failed.
ttt.sh: line 872: 28152 Aborted (core dumped)
For comparsion
bagof([_,_,A,_,_],B^C^member([A,B,C],Data),Fraud)
... ,[_1297,_1298,'Jones',_1299,_1300],[_1301,_1302,'Jones',_1303,_1304],[_1305,_1306,'Jones',_1307,_1308]]
?-
Because of B^C^ the count of variables decreases? _1308 (findall _2739 before it crashes)
from trealla.
In the range of 719 - 725 impermissible entries, I get 3 different core dumps
member(X,Atad), \+member(X,Data),
[A,B,_] = X, /* Find this; A (=name) and B (=month) are in Atad and Data,
just the Score C is different and so not member(of Data) is true.
findall([A,_,_],member([A,B,C],Data),Fraud),
% I don't see a problem here. A and B are instantiated.
% The Data list of lists is not corrupt.
% Even this query should work: findall([_,_,_],member([_,_,_],Data),Fraud),
% as bagof([_,_,_],member([_,_,_],Data),Fraud) does.
Warning: singleton: C, (of no interest, in template ignored)
Program received signal SIGSEGV, Segmentation fault.
0x0000555555634093 in unify_internal (q=0x5555557b0f60, p1=0x555555753be0, p1_ctx=144, p2=0x500000202, p2_ctx=0, depth=0) at src/unify.c:1114
1114 if (is_variable(p1) && is_variable(p2)) {
(gdb) bt
#0 0x0000555555634093 in unify_internal (q=0x5555557b0f60, p1=0x555555753be0, p1_ctx=144, p2=0x500000202, p2_ctx=0, depth=0) at src/unify.c:1114
#1 0x00005555556346f4 in unify (q=0x5555557b0f60, p1=0x555555753be0, p1_ctx=144, p2=0x500000202, p2_ctx=0) at src/unify.c:1204
#2 0x00005555555e0af3 in fn_sys_get_attributes_2 (q=0x5555557b0f60) at src/predicates.c:6271
#3 0x00005555555fe271 in start (q=0x5555557b0f60) at src/query.c:1728
#4 0x00005555555fea30 in execute (q=0x5555557b0f60, cells=0x5555557189d0, nbr_vars=0) at src/query.c:1923
#5 0x00005555555ac3f2 in run (p=0x55555579afd0, pSrc=0x7fffffffc5ed "run", dump=true) at src/parser.c:3533
#6 0x00005555555f5d4d in pl_eval (pl=0x555554981010, s=0x7fffffffc5ed "run") at src/prolog.c:122
#7 0x000055555555f76b in main (ac=4, av=0x7fffffffc208) at tpl.c:266
Program received signal SIGABRT, Aborted.
__pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at pthread_kill.c:44
44 pthread_kill.c: No such file or directory.
(gdb) bt
#0 __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at pthread_kill.c:44
#1 __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
#2 __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at pthread_kill.c:89
#3 0x0000555554e42296 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4 0x0000555554e297ec in __GI_abort () at abort.c:79
#5 0x0000555554e8a8b8 in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x555554fbb599 "%s\n") at ../sysdeps/posix/libc_fatal.c:155
#6 0x0000555554ea1cba in malloc_printerr (str=str@entry=0x555554fb92e2 "realloc(): invalid next size") at malloc.c:5667
#7 0x0000555554ea5b1c in _int_realloc (av=av@entry=0x555554ff5c60 <main_arena>, oldp=oldp@entry=0x55555593d890, oldsize=oldsize@entry=67376, nb=nb@entry=89808) at malloc.c:4845
#8 0x0000555554ea67b2 in __GI___libc_realloc (oldmem=0x55555593d8a0, bytes=89792) at malloc.c:3480
#9 0x00005555555904eb in alloc_grow (addr=0x5555557b0fa0, elem_size=32, min_elements=2626, max_elements=2806) at src/heap.c:28
#10 0x00005555555f88a0 in check_slot (q=0x5555557b0f60, cnt=255) at src/query.c:225
#11 0x00005555555fd6a1 in match_head (q=0x5555557b0f60) at src/query.c:1566
#12 0x00005555555fe4b1 in start (q=0x5555557b0f60) at src/query.c:1757
#13 0x00005555555fea30 in execute (q=0x5555557b0f60, cells=0x5555557189d0, nbr_vars=0) at src/query.c:1923
#14 0x00005555555ac3f2 in run (p=0x55555579afd0, pSrc=0x7fffffffc5ef "run", dump=true) at src/parser.c:3533
#15 0x00005555555f5d4d in pl_eval (pl=0x555554981010, s=0x7fffffffc5ef "run") at src/prolog.c:122
#16 0x000055555555f76b in main (ac=4, av=0x7fffffffc208) at tpl.c:266
Program received signal SIGABRT, Aborted.
__pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at pthread_kill.c:44
44 pthread_kill.c: No such file or directory.
(gdb) bt
#0 __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at pthread_kill.c:44
#1 __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
#2 __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at pthread_kill.c:89
#3 0x0000555554e42296 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4 0x0000555554e297ec in __GI_abort () at abort.c:79
#5 0x0000555554e29719 in __assert_fail_base (fmt=0x555554fbcc20 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x55555563ed27 "min_elements <= max_elements",
file=0x55555563ed1c "src/heap.c", line=23, function=<optimized out>) at assert.c:92
#6 0x0000555554e39cc6 in __GI___assert_fail (assertion=0x55555563ed27 "min_elements <= max_elements", file=0x55555563ed1c "src/heap.c", line=23,
function=0x55555563ed70 <__PRETTY_FUNCTION__.0> "alloc_grow") at assert.c:101
#7 0x00005555555904c8 in alloc_grow (addr=0x5555557b0fa0, elem_size=32, min_elements=3655, max_elements=2806) at src/heap.c:23
#8 0x00005555555f88a0 in check_slot (q=0x5555557b0f60, cnt=1822) at src/query.c:225
#9 0x00005555555fbc17 in create_vars (q=0x5555557b0f60, cnt=4) at src/query.c:1208
#10 0x0000555555591ba1 in deep_copy_to_tmp_with_replacement (q=0x5555557b0f60, p1=0x5555557c53f8, p1_ctx=2, copy_attrs=false, from=0x0, from_ctx=0, to=0x0, to_ctx=0) at src/heap.c:387
#11 0x0000555555591e59 in deep_copy_to_tmp (q=0x5555557b0f60, p1=0x5555557c53f8, p1_ctx=2, copy_attrs=false) at src/heap.c:425
#12 0x0000555555591ecf in deep_copy_to_heap (q=0x5555557b0f60, p1=0x5555557c53f8, p1_ctx=2, copy_attrs=false) at src/heap.c:436
#13 0x00005555555601d0 in fn_iso_findall_3 (q=0x5555557b0f60) at src/bags.c:45
#14 0x00005555555fe271 in start (q=0x5555557b0f60) at src/query.c:1728
#15 0x00005555555fea30 in execute (q=0x5555557b0f60, cells=0x5555557189d0, nbr_vars=0) at src/query.c:1923
#16 0x00005555555ac3f2 in run (p=0x55555579afd0, pSrc=0x7fffffffc5ed "run", dump=true) at src/parser.c:3533
#17 0x00005555555f5d4d in pl_eval (pl=0x555554981010, s=0x7fffffffc5ed "run") at src/prolog.c:122
#18 0x000055555555f76b in main (ac=4, av=0x7fffffffc208) at tpl.c:266
from trealla.
from trealla.
This is ok but its like this, I guess:
findall([C,A,B],member([A,B,C],Data),Fraud)
So the problem has to do with anon vars in the template.
Think about this: People manager matches ['Jones',_123,_456] = ['Jones','fired','pronto'] later on.
(If anons are replaced with random atoms the fields are closed/locked)
from trealla.
Can you check this:
bags.c, fn_iso_findall_3()
line 76: cell *solns = take_queuen(q);
line 88: if (!check_slot(q, vars)) return false; // what happens with solns when you return here?
line 112: free(solns);
from trealla.
from trealla.
from trealla.
This core dump is a bit tricky:
"realloc(): invalid next size"
It could be an internal realloc() error as well (depending on a (perhaps buggy) libc version of the OS).
But in most cases it is the application which overwrites/destroys meta-data of malloc.
from trealla.
If anons are replaced with random atoms the fields are closed/locked.
from trealla.
from trealla.
Think about this:
People Manager matches ['Jones',_123,_456] = ['Jones','fired','pronto'] later on,
and at some point this goes back into the database table 'fraudulence' then.
Here a bagof/3 result:
28798 fraudulent entries.
bagof([A,_,_],B^C^member([A,B,C],Data),Fraud)
...,['Jones',_38547,_38548],['Jones',_38549,_38550],['Jones',_38551,_38552]]
?-
Seems that bagof/3 does not have this problem with anons
from trealla.
Clearly, thats all theory.
It just has revealed a bug.
And findall/3 is extremely speedy, so it should be more or less bug-free?
I mean, 3 different types of core dump is not that bad.
from trealla.
realloc() maybe not
v2.0.3-3-g3fe3
725 impermissible entries: Segmentation fault
726 impermissible entries: realloc(): invalid next size
727 impermissible entries: heap.c:23: alloc_grow: Assertion `min_elements <= max_elements' failed
from trealla.
Remark:
The Craft of Prolog 11.3 Standard Predicates
"findall/3, collects ... but doesn't handle free variables right, ... " @UWN What does this mean?
"It is not so important to provide findall/3, as bagof/3 can simulate it"
Here in this scenario (SQL+Prolog) bagof/3 flops. It is way too slow.
from trealla.
from trealla.
from trealla.
from trealla.
Marvelous!
71775 impermissible entries.
CPU Heat 50°
Mem stable 0.2% - 0.7%
System behaves as if nothing going on(stays responsive)
No more core dumps.
Output tact regular/steady/fast!
from trealla.
bagof/3 trouble ... seems trapped somewhere, still way too slow
lightyears away from findall
from trealla.
from trealla.
Nope: Segmentation fault (core dumped)
from trealla.
Program received signal SIGSEGV, Segmentation fault.
0x00005555555f9f15 in try_me (q=0x5555557b0f60, nbr_vars=3) at src/query.c:659
659 e->mark = false;
(gdb) bt
#0 0x00005555555f9f15 in try_me (q=0x5555557b0f60, nbr_vars=3)
at src/query.c:659
#1 0x00005555555fd7ae in match_head (q=0x5555557b0f60) at src/query.c:1576
#2 0x00005555555fe4fc in start (q=0x5555557b0f60) at src/query.c:1757
#3 0x00005555555fea7b in execute (q=0x5555557b0f60, cells=0x5555557189d0,
nbr_vars=0) at src/query.c:1923
#4 0x00005555555ac43d in run (p=0x55555579afd0, pSrc=0x7fffffffc5ee "run",
dump=true) at src/parser.c:3533
#5 0x00005555555f5d98 in pl_eval (pl=0x555554981010, s=0x7fffffffc5ee "run")
at src/prolog.c:122
#6 0x000055555555f76b in main (ac=4, av=0x7fffffffc208) at tpl.c:266
from trealla.
from trealla.
Hard to say.
Last output:
['Jack',_119563,_119564],['Jack',_119565,_119566],['Jack',_119567,_119568],['Jack',_119569,_119570],['Jack',_119571,_119572],['Jack',_119573,_119574],['Jack',_119575,_119576]]
Finding 'Jones'? Maybe.
from trealla.
There is no context, a list is a list is a list.
from trealla.
from trealla.
Segmentation fault.
Forget logtalk for a moment and revert that change.
You ask things I do not understand.
from trealla.
Perhaps something is wrong with logtalk...who knows.
from trealla.
from trealla.
Sorry my friend...this database is just a variant to generate a list and nothing else [[a,b,c],[a,b,d],[w,x,y],[w,x,z]].
You can forget all this database stuff. SQL and !(cut) and Prolog do your list processing.
Easy...two lists ...check that all components of the short list are in the long list and if not print all parts found in the long list which both have in common. Thats it. findall in a list and store it in a structure which a template presets.
from trealla.
?- LIST_ONE = [[a,b,c]], LIST_TWO = [[a,b,d]], member(X,LIST_ONE), \+member(X,LIST_TWO),[A,_,_] = X, findall([A,_,_],member([A,_,_],LIST_TWO),FOUND_A).
LIST_ONE = ["abc"], LIST_TWO = ["abd"], X = "abc", A = a, FOUND_A = [[a,_A,_B]]
; ... .
?-
from trealla.
from trealla.
Yes, it does. findall/3 as such works now as expected.
It seems it has to do with where the prolog code is placed.
Perhaps this was meant when you asked for more context
run :-
% findall in 'context' test/1. CRASH
test('./test.db').
% findall in 'context' run/0. NO CRASH
test('./test.db', Data, Atad),
!,
member(X,Atad), \+member(X,Data),
[A,B,_] = X,
findall([A,_,_],member([A,B,C],Data),Fraud),
write('Fraud detected: '),
length(Fraud,Lf), writeq(X/Lf),nl,
fail.
% findall in test/1
test('./test.db')
Length Data: 728 % Elements in list
Length Atad: 6
Fraud detected: ['Jack',1,-54500]/121 % 121 elements collected
Fraud detected: ['Jack',2,-233500]/121
Fraud detected: ['Jack',3,-145250]/122
Fraud detected: ['Jones',1,65000]/121
Fraud detected: ['Jones',2,244500]/121
Segmentation fault (core dumped)
And it has nothing to do with the quantity:
Length Data: 71776 % Elements in list
Length Atad: 6
Fraud detected: ['Jack',1,-5346500]/11881 % 11881 elements collected
Fraud detected: ['Jack',2,-23116500]/11979
Fraud detected: ['Jack',3,-14844000]/11881
Segmentation fault (core dumped)
% findall in run/0
test('./test.db', Data, Atad)
Length Data: 728
Length Atad: 6
Fraud detected: ['Jack',1,-54500]/121
Fraud detected: ['Jack',2,-233500]/121
Fraud detected: ['Jack',3,-145250]/122
Fraud detected: ['Jones',1,65000]/121
Fraud detected: ['Jones',2,244500]/121
Fraud detected: ['Jones',3,156000]/122 % 121+121+122+121+121+122=728 , perfect
?-
Length Data: 71776
Length Atad: 6
Fraud detected: ['Jack',1,-5346500]/11881
Fraud detected: ['Jack',2,-23116500]/11979
Fraud detected: ['Jack',3,-14844000]/11881
Fraud detected: ['Jones',1,6484000]/12077
Fraud detected: ['Jones',2,24205500]/11979
Fraud detected: ['Jones',3,14977250]/11979
?-
Looks like you don't need a database to muse about whats going on in test/1
from trealla.
v2.0.4
Length Data: 728 Ok! test/1 segfault gone
Length Data: 71776 Both running out of memory quickly
test/1
Length Data: 71776
Length Atad: 6
Fraud detected: ['Jack',1,-5346500]/11881 % Mem 0.5%
Fraud detected: ['Jack',2,-23116500]/11979 % Mem 0.5%
% Eats memory quickly from now on, OS fired at tpl
Killed
run/0
Length Data: 71776
Length Atad: 6
Fraud detected: ['Jack',1,-5346500]/11881 % Mem 0.5
Fraud detected: ['Jack',2,-23116500]/11979 % Mem 0.5
Fraud detected: ['Jack',3,-14844000]/11881 % Mem 0.8
% Eats memory quickly from now on, OS fired at tpl
Killed
from trealla.
from trealla.
You saying that you happy with version v2.0.4 at the moment?
I mean, it seems that these problems are fixed now:
Meta-called problems.
findall/3 issues.
I investigate this memory behaviour more precisely to find a better Length Data value and
prepare a little script to create the db then next week.
I guess this issue(#4) can be closed. What you think?
from trealla.
from trealla.
from trealla.
$ trealla/tpl testrun.pl
Warning: singleton: C, near library/sqlite3:22
Trealla Prolog (c) Infradig 2020-2023, v2.10.10
?- run.
Atad: [['Jack',1,-5346500],['Jack',2,-23116500],['Jack',3,-14844000],['Jones',1,6484000],['Jones',2,24205500],['Jones',3,14977250]]
Length Data: 71776
Length Atad: 6
% Time elapsed 0.085502s
Fraud detected: ['Jack',1,-5346500]/11881
% Time elapsed 0.090475s
% Time elapsed 0.078336s
Fraud detected: ['Jack',2,-23116500]/11979
% Time elapsed 0.081799s
% Time elapsed 0.078924s
Fraud detected: ['Jack',3,-14844000]/11881
% Time elapsed 0.082899s
% Time elapsed 0.080680s
Fraud detected: ['Jones',1,6484000]/12077
% Time elapsed 0.084104s
% Time elapsed 0.076667s
Fraud detected: ['Jones',2,24205500]/11979
% Time elapsed 0.080224s
% Time elapsed 0.080339s
Fraud detected: ['Jones',3,14977250]/11979
% Time elapsed 0.083886s
false.
?-
Sophisticated! Great!
from trealla.
Fraud detected: ['Jack',1,-5346500]/11881
Fraud detected: ['Jack',2,-23116500]/11979
Fraud detected: ['Jack',3,-14844000]/11881
Fraud detected: ['Jones',1,6484000]/12077
Fraud detected: ['Jones',2,24205500]/11979
Fraud detected: ['Jones',3,14977250]/11979
11881+11979+11881+12077+11979+11979
71776 % Perfect: Length Data: 71776
from trealla.
Related Issues (20)
- write_term/2 printing issue? HOT 5
- portray_clause/1 stateful variable names (again?)
- write_term_to_chars/3 writes invalid syntax sometimes. HOT 4
- call_nth/2: malformed integer, sometimes HOT 14
- [user]. core dump after overwriting, error, overwriting HOT 8
- listing/0, write_term/2 printing error HOT 3
- Syntax error displayed
- Segmentation fault HOT 1
- listing/0 printing issue
- (=)/2 fatal error bug check HOT 3
- Change name of read_term_from_chars/2 to read_from_chars/2
- Invalid syntax emitted with max_depth/1 HOT 3
- write_term/2 counting sometimes incorrect HOT 4
- Invalid memory read in prune_me for soft cuts HOT 3
- Debug version reports error HOT 1
- ^C Segmentation fault HOT 2
- write_term/2, max_depth/1 verification
- Unseeable missing operand secrets HOT 2
- Top-Level Intermezzo HOT 2
- F1 motor broken? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from trealla.