Comments (5)
Please share the schema and queries you're using @3g015st
from libsql.
@haaawk Sorry for the late reply, here it is:
Query:
SELECT id, imageUrl, socialId, userType
FROM Users
WHERE
(
userType = "SUBSCRIBED_PLAYER"
socialId = <v4-uuid>
AND DATETIME(scheduledBoostAt) >= CURRENT_TIMESTAMP
Schema
model Users {
id String @id @default(uuid())
socialId String @unique
email String @unique
scheduledBoostAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime?
userType String
referralCode String @unique
Items Items[]
}
Query itself returns a single row on my app server, but when executed it's like 100 row reads on Turso analytics. Weird enough because I have 100-ish rows on that table, so maybe it is doing a FULL TABLE SCAN. But when I used the EXPLAIN QUERY PLAN it is using the index that I made.
from libsql.
is the issue still not assigned ??
from libsql.
@3g015st - can you share more details here? I don't quite understand your setup as you initially mentioned that you Made a compound index for socialId and userType
but in your Prisma schema I don't see any compound indices - only unique indices over id
, socialId
, email
& referralCode
(also, your query has some imageUrl
field but there is no such field in the schema...)
You can attach output of the following command with more details about your setup:
SELECT name, tbl_name, sql FROM sqlite_master WHERE tbl_name = 'Users'; SELECT sqlite_version();
Also, it will be great if you can attach query with EXPLAIN
and EXPLAIN QUERY PLAN
output (first one will print sqlite3 VM operations which can be helpful to track issue).
I also tried to reproduce your issue locally (with turso and against raw libsql
with the test provided below) - but for me libsql
accounted only 1 read row for the query you shared:
#[test]
fn test_stat() -> Result<(), Error> {
let db = Connection::open_in_memory()?;
db.execute(
r#"
CREATE TABLE "Users" (
"id" TEXT NOT NULL PRIMARY KEY,
"socialId" TEXT NOT NULL,
"email" TEXT NOT NULL,
"scheduledBoostAt" DATETIME,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME,
"userType" TEXT NOT NULL,
"referralCode" TEXT NOT NULL
);
"#, ()
)?;
for i in 0..100 {
let id = i.to_string();
db.execute(r#"INSERT INTO "Users" VALUES (?, ?, ?, datetime('2020-01-01T00:00:00'), datetime('2020-01-01T00:00:00'), datetime('2020-01-01T00:00:00'), ?, ?)"#, (&id, &id, &id, &id, &id))?;
}
db.execute(r#" CREATE UNIQUE INDEX "Users_socialId_userType_key" ON "Users"("socialId", "userType"); "#, ())?;
let mut statement = db.prepare(
"SELECT id, socialId, userType FROM Users WHERE (userType = '90' AND socialId = '90' AND DATETIME(scheduledBoostAt) >= CURRENT_TIMESTAMP)"
)?;
let mut result = statement.query(params![])?;
while let Ok(Some(_)) = result.next() {}
drop(result);
assert_eq!(statement.get_status(rusqlite::StatementStatus::RowsRead), 1);
Ok(())
}
from libsql.
@sivukhin Sorry for the late reply but yeah you're right the SELECT query returns a single row, but when I visit the Turso analytics dashboard that same query returns the number of rows that the table has, instead of just "1". I haven't tried running the query locally. The contract's done on my end, so I guess we can close this out. Thank you all.
from libsql.
Related Issues (20)
- Creating namespaces in sqld following the docs does not work. HOT 2
- Switch to locking_mode EXCLUSIVE in libSQL server? HOT 2
- Feature request: support for `begin concurrent`
- How to enable the `attach` permission for databases HOT 1
- Improve database connection builder API? HOT 1
- Go API: Compile/Link error on Linux with Embedded Replication library
- CHECK failure not propagated on failing INSERT/UPDATE HOT 2
- libsql-ffi build failed on Windows HOT 4
- Issue: pyo3_runtime.PanicException: not yet implemented
- The stream expired due to inactivity with SQLC and turso
- missing `libsql-server-v0.24.19/source.tar.gz` HOT 5
- Sync hangs for a very long time when using archived database HOT 2
- failed to build 0.24.20 HOT 1
- Having trouble syncing in Nuxt3 – Embedded Syncs works with Nuxt x Vercel?
- Foreign key referencing a non-primary field results in `ValueError: foreign key mismatch` when using `ON CONFLICT` HOT 1
- turso not working with laravel
- Implement Statement::raw_bind_parameter() API HOT 2
- turso with Bun.sh issue HOT 1
- Conditionless batch support in libSQL remote protocol
- Unblocking writes/reads does not work if there's a pending schema migration
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 libsql.