gluesql / gluesql

GlueSQL is quite sticky. It attaches to anywhere.

Home Page:https://gluesql.org/docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Composite Storage support CTAS

enginefuture opened this issue · comments

I have a table stored in Sled. Due to the large amount of data, the join query speed is very slow. I want to copy this table into memory, using Composite Storage for querying. I attempted to create it using the following SQL statement:

           let memory_storage = MemoryStorage::default();
           let mut storage = CompositeStorage::new();
           let Glue {
               storage: sled_storage,
           } = &*db.lock();
           storage.push("MEM", memory_storage);
           storage.push("SLED", sled_storage.clone());
           storage.set_default("SLED");
           let mut glue = Glue::new(storage);
           let start_time = Instant::now();
           let res = &glue
               .execute("CREATE TABLE MEM_material ENGINE = MEM AS (SELECT * FROM material);")
               .unwrap();
CREATE TABLE MEM_material ENGINE = MEM AS (SELECT * FROM material);

However, a syntax error occurred. Is there a problem with my usage, or does Composite Storage not currently support this syntax?

Yes, I also encountered this problem. Have you solved it

noup

I have the same problem, is there any good solution?

Currently, CTAS does not work with ENGINE option but only works with default storage.
So, you could do like this.

storage.push("MEM", memory_storage);
storage.push("SLED", sled_storage.clone());
storage.set_default("MEMORY");
let mut glue = Glue::new(storage);

glue.execute("CREATE TABLE material (id INT, name TEXT) ENGINE = SLED;");
// insert data
glue.execute("CREATE TABLE MEM_material AS SELECT * FROM material;");

By the way, Can you guys { @enginefuture, @suncunxudsb, @wawnchg } share below information? It might help a lot to improve query performance.

  • The slow query
  • The row number of each tables in the slow query
  • Schema of each tables
  • PK on each tables
  • Indexes on each tables