tursodatabase / libsql

libSQL is a fork of SQLite that is both Open Source, and Open Contributions.
https://turso.tech/libsql
MIT License
10.77k stars 273 forks source link

count(*) always returns 0 if table has a vector index #1819

Closed andreaswimmer closed 6 hours ago

andreaswimmer commented 6 hours ago
import random

import libsql_experimental as libsql

conn = libsql.connect(":memory:")
dims = 4
conn.execute(f"""
    CREATE TABLE vectors
    (
        vector_id INTEGER PRIMARY KEY,
        vector F32_BLOB({dims})
    ) 
    """)
conn.execute("CREATE INDEX vector_idx ON vectors(libsql_vector_idx(vector))")
data = []
for primary in range(10):
    vector = ','.join(str(random.random()) for _ in range(dims))
    data.append((primary, f"[{vector}]"))

conn.executemany("""
INSERT INTO vectors
values (?, ?)
""", data)
print(conn.execute("SELECT COUNT(*) FROM vectors").fetchall())
print(conn.execute("SELECT * FROM vectors").fetchall())

In this program, count(*) returns 0, even though the table has 10 rows. If you comment out the 'CREATE INDEX' line, the correct answer of 10 is given.

Using libsql-experimental 0.0.41

andreaswimmer commented 6 hours ago

Just saw libsql-experimental has its own issue tracker, will post over there

Feel free to delete this, I don't think I can