Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SQL Query very slow
#8
Quote:Places.Name like ElectionResults2012.Town + '%'

Is the name the only way the two tables are related? There's no ids or anything? I think that, by default, sqlite can't use indices for 'like' queries due to case sensitivity. You can check what the sql engine is doing with your query by asking it to explain query: https://www.sqlite.org/eqp.html

Depending on how much control you have, rebuilding the table to use a fulltext search engine would make it work as expected, if you use the keyword 'match' instead of 'like': https://www.sqlite.org/fts3.html

Or, you can use pragma declarations to let sql know you don't care about case sensitivity, then it might decide to use the index: https://www.sqlite.org/optoverview.html#...timization
https://stackoverflow.com/a/8586390

sqlite apparently doesn't let you alter tables that already exist, so you can't modify the collation of a preexisting table. But you can create a temporary table to hold the contents, drop the table, recreate it using the proper collation, then put the data back in:https://stackoverflow.com/a/47469890

CREATE TABLE table01 (id, name countrycode, comment );
INSERT INTO table01 SELECT id, name, countrycode, comment FROM table;
DROP TABLE table;
CREATE TABLE table (
   id       integer PRIMARY KEY AUTOINCREMENT,
   name     text COLLATE NOCASE
   country  integer,
   comment  text COLLATE NOCASE
);
INSERT INTO table (id, name, countrycode, comment)
    SELECT id, name, countrycode, comment FROM table01;
DROP TABLE table01;
Reply


Messages In This Thread
SQL Query very slow - by Larz60+ - May-18-2019, 11:02 PM
RE: SQL Query very slow - by MvGulik - May-19-2019, 12:23 PM
RE: SQL Query very slow - by ichabod801 - May-19-2019, 02:07 PM
RE: SQL Query very slow - by Larz60+ - May-19-2019, 03:47 PM
RE: SQL Query very slow - by richalt2 - May-20-2019, 04:32 PM
RE: SQL Query very slow - by Larz60+ - May-20-2019, 05:11 PM
RE: SQL Query very slow - by MvGulik - May-21-2019, 06:50 AM
RE: SQL Query very slow - by nilamo - May-21-2019, 06:12 PM
RE: SQL Query very slow - by Larz60+ - May-21-2019, 10:34 PM
RE: SQL Query very slow - by Mark87 - Jun-23-2019, 11:43 AM
RE: SQL Query very slow - by Larz60+ - Jun-23-2019, 04:11 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020