Earlier quoted context omitted.
You might like Google's Logica https://opensource.googleblog.com/2021/04/logica-organizing-... (Datalog/Prolog family language compiled to SQL)
I've been using this fairly heavily recently (internal to Google), to the point where I'm thinking of investing in writing an org-babel mode for it. It's a really nice way to structure queries!
And yes, this kind of thing is why datalog is a lot more amenable to fast query plans & runtimes than prolog. This part is especially cool: https://github.com/EvgSkv/logica/blob/main/compiler/dialects...