tursodatabase / libsql

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

Rows written with `INSERT OR IGNORE` still read/writing #1544

Open hbmartin opened 1 month ago

hbmartin commented 1 month ago

I am frequently inserting datasets with many duplicates using INSERT OR IGNORE .... However, it appears that this still causes writes (and also maybe reads?) on the remote replicant? Is this expected behavior? Is there a configuration to prevent this?

sivukhin commented 1 month ago

Hi @hbmartin!

I think that reads are expected for INSERT OR IGNORE query but there must be no writes actually.

Can you share more details about your setup?

BTW, I tried to replicate your issue but don't see any signs of writes for your type of query:

$> cat query.json
{
  "requests": [
    {
      "type": "execute", "stmt": { "sql": "INSERT OR IGNORE INTO with_dup VALUES (1, 10);" }
    },
    {
      "type": "close"
    }
  ]
}
$> cat query.json | curl -X POST https://localhost:8080/v2/pipeline -d @- | jq . # some fields are omitted
{
  "results": [
    {
      "type": "ok",
      "response": {
        "type": "execute",
        "result": {
          "rows_read": 1,
          "rows_written": 0,
        }
      }
    },
    {
      "type": "ok",
      "response": {
        "type": "close"
      }
    }
  ]
}