Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure out if select query is dirtied by a mutator query #1383

Closed
cw-dev opened this issue Jun 23, 2019 · 7 comments
Closed

Figure out if select query is dirtied by a mutator query #1383

cw-dev opened this issue Jun 23, 2019 · 7 comments
Labels

Comments

@cw-dev
Copy link

cw-dev commented Jun 23, 2019

The commit that removes this TODO hinted that it would eventually be implemented, so I figured I'd open this to see if you've had any thoughts since. Wouldn't this be impossible for some queries, or at least insanely hard?

@ursusursus
Copy link

This would be greate, as now I have to have distinctUntilChanged everywhere when using Rx, and emits are mostly false positive, + it doubles the work as the is DiffUtil near UI level almost always

@erikc5000
Copy link
Contributor

erikc5000 commented Jun 24, 2019

SQLite only supports table level triggers. I don't think you can know if a given query's results changed without comparing everything -- unless you start making assumptions about what will be changed in response to mutating queries. Seems like it wouldn't be easy to do that reliably. And any query executed outside of SQLDelight would break it.

Edit: Disregard what I said above. I was mistaken about how the invalidation tracking works.

I believe Room requires you to do distinctUntilChanged() also. Could write some extension functions like mapDistinctToList() to cut down on boilerplate, though obviously that won't do anything to improve performance.

@AlecKazakova
Copy link
Collaborator

yea, i don't think we'll ever get it perfect but we can eliminate a lot of false positives by leveraging the compiler

for example these two queries are linked:

SELECT *
FROM table
WHERE id = 10;

UPDATE table
SET stuff = 'foo'
WHERE id = 10;

however this one wouldn't effect the queried row:

INSERT INTO table (id, stuff)
VALUES (11, 'foo');

we can determine that statically instead of trying to do it at runtime, and then for bind args its a combination of figuring out which queries could update each other and checking the right parameters at runtime.

@ursusursus
Copy link

what about this?

https://www.sqlite.org/c3ref/update_hook.html

it gives you rowid affected

@JakeWharton
Copy link
Member

We don't have access to the native APIs on Android, but potentially on native platforms.

@AlecKazakova
Copy link
Collaborator

might revisit this in the future, but I'm going to close this out since it'd be a big effort (so I suspect I am the only one who would do it) and I'm not planning on it atm. Would be cool but with distributed databases a proper implementation would be wild

I think the long term solution is probably hooking into specific database implementations that provide result set invalidation

@cw-dev
Copy link
Author

cw-dev commented Apr 15, 2022

yeah this would definitely be a larger undertaking than initially anticipated

incremental view maintenance and dataflow stuff is pretty interesting if you ever decide to circle back in the future! https://github.com/mit-pdos/noria comes to mind

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants