I have a local SQLite database
PARTS TABLE
-- Describe PREFIX_LIST CREATE TABLE PREFIX_LIST(ITEM VARCHAR(25) PRIMARY KEY) -- Describe SUFFIX_LIST CREATE TABLE SUFFIX_LIST(ITEM VARCHAR(25) PRIMARY KEY) -- Describe VALID_LIST CREATE TABLE VALID_LIST ( "PART1" TEXT, "PART2" TEXT, PRIMARY KEY(PART1, PART2) )
Now this list is really huge, and I need to save data from it.
Here is my implementation.
SQLiteConnection con = null; SQLiteCommand cmd = null; Connect(DbPath, ref con, ref cmd); cmd.CommandText = "SELECT PART1 || '@' || PART2 FROM VALID_LIST WHERE NOT EXISTS (SELECT * FROM PREFIX_LIST WHERE VALID_LIST.PART1 LIKE '%' || ITEM || '%') AND NOT EXISTS (SELECT * FROM SUFFIX_LIST WHERE VALID_LIST.PART2 LIKE '%' || ITEM || '%')"; var reader = cmd.ExecuteReader(); if (reader.HasRows) { string savePath; if (SaveTextFile(out savePath) == DialogResult.OK) { TextWriter writer = new StreamWriter(savePath); while (reader.Read()) { writer.WriteLine(reader.GetString(0)); } writer.Close(); writer.Dispose(); } } reader.Close(); reader.Dispose(); cmd.Dispose(); con.Close(); con.Dispose(); MessageBox.Show("List Saved!.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
I need a little better, I can save the list faster. Total records in VALID_LIST - 2639117
and it took 15 minutes to save it for the above SQL QUERY!
please lmk if sql query can be optimized!
Thanks in advance
source share