Readit News logoReadit News
michae2 commented on Implementing Logic Programming   btmc.substack.com/p/imple... · Posted by u/sirwhinesalot
sirwhinesalot · 2 months ago
Hey, author here. The one time I go straight to bed after posting on hackernews is the one time I get a bunch of comments hahaha.

Yes you can add support for integers in various ways where termination is still guaranteed. The simplest trick is to distinguish predicates (like pred(X, 42)) from constraints (like X > 7). Predicates have facts, constraints do not. When checking that every variable in the head of a rule appears in the body, add the condition that it appears in a predicate in the body.

So if you have a predicate like age(X:symbol, Y:int), you can use its facts to limit the set of integers under consideration. Then, if you write:

age(X, A), A + 1 >= 18.

You'd get everyone that becomes an adult next year. Fancier solutions are also possible, for example by employing techniques from finite domain constraint solving.

michae2 · 2 months ago
Thanks, this is really helpful! And great article.
michae2 commented on Implementing Logic Programming   btmc.substack.com/p/imple... · Posted by u/sirwhinesalot
michae2 · 2 months ago
Something I’ve wondered about Datalog is whether integers can be added to the language without losing guarantees about termination of query evaluation. It seems like as soon as we add integers with successor() or strings with concat() then we can potentially create infinite relations. Is there a way to add integers or strings (well, really basic scalar operations on integer or string values) while preserving termination guarantees?

This bit at the end of the article seems to imply it’s possible, maybe with some tricks?

> We could also add support for arithmetic and composite atoms (like lists), which introduce some challenges if we wish to stay “Turing-incomplete”.

michae2 commented on Why CockroachDB doesn't use EvalPlanQual   cockroachlabs.com/blog/wh... · Posted by u/michae2
CurtHagenlocher · a year ago
UPDATE player set name = 'Stonebraker' where name = 'Stonebreaker'
michae2 · a year ago
Oh, thank you!
michae2 commented on Why CockroachDB doesn't use EvalPlanQual   cockroachlabs.com/blog/wh... · Posted by u/michae2
big_whack · a year ago
My guess is orgs that have a real need for a distributed SQL database (which are rare in the space of orgs) will make their choices based on requirements analysis rather than naming.

So probably if you would be turned off enough by the name not to use the software, you don't actually need a distributed SQL database and are not the target customer.

michae2 · a year ago
To put it somewhat irreverently: running large production databases is not for the squeamish.
michae2 commented on Why CockroachDB doesn't use EvalPlanQual   cockroachlabs.com/blog/wh... · Posted by u/michae2
npstr · a year ago
> given what constraint 2 says the level is actually a team level, not a player level.

Then it's bad unnormalized data design that is the problem here. If that is a team level, it should be in the team table, not the player table.

michae2 · a year ago
> If that is a team level, it should be in the team table, not the player table.

It's all contrived, of course, but the reason I would consider skill level to be a player attribute rather than a team attribute is that there could be free agents with a skill level but no team:

INSERT INTO player VALUES (10, 'Pavlo', 'AAA', NULL);

Then with enough free agents, you could imagine building a new team out of free agents that are all at the same skill level:

UPDATE player SET team = 'Otters' WHERE level = 'AAA' AND team IS NULL ORDER BY id LIMIT 3;

michae2 commented on Why CockroachDB doesn't use EvalPlanQual   cockroachlabs.com/blog/wh... · Posted by u/michae2
qazxcvbnm · a year ago
Which of these strategies does Postgres use under Repeatable Read?
michae2 · a year ago
PG only uses EvalPlanQual under read committed isolation. Under repeatable read the first update fails with a "could not serialize" error, just as it does under serializable.
michae2 commented on Why CockroachDB doesn't use EvalPlanQual   cockroachlabs.com/blog/wh... · Posted by u/michae2
CGamesPlay · a year ago
How does the CockroachDB approach not deadlock? Surely retrying could encounter a situation where two competing UPDATE will lock rows in different order, and no amount of retrying will unlock the required rows, right?
michae2 · a year ago
It's a good question. For simple UPDATEs, CockroachDB always executes in a deterministic, serial order and so it's likely the rows will be locked in the same order by any competing updates. (This can be confirmed by looking at the query plans.) Complex UPDATEs using joins and subqueries will need explicit ORDER BY to always lock in the same order.

If an UPDATE has to retry halfway through, locks are held across the retry to help the system make progress. But as you point out, this could cause lock acquisition to happen in an unexpected order if new rows qualify during a retry. So far we haven't run into this, but we might need to provide an option for an UPDATE to drop locks on retry if deadlock turns into a bigger problem than livelock. It depends on the workload.

michae2 commented on Why CockroachDB doesn't use EvalPlanQual   cockroachlabs.com/blog/wh... · Posted by u/michae2
sbstp · a year ago
Why is Cockroach adding READ COMMITTED? Is using a lower level of isolation better for performance or just reduces the amount of serialization errors and retries that need to be done?
michae2 · a year ago
The main motivation is reduce serialization errors, for applications that can handle the weaker isolation level. Especially for applications that were previously running fine under RC on another database.

u/michae2

KarmaCake day135April 10, 2013
About
https://twitter.com/michae2_ https://github.com/michae2
View Original