如何与Sqlite索引一起使用join

如何与Sqlite索引一起使用join,sqlite,join,indexing,Sqlite,Join,Indexing,我正在用ionic 3创建一个应用程序。在应用程序中,我添加了一个搜索过滤器,根据用户的角色对其进行过滤。我有5个表,我必须从中提取数据 使用所需数据创建每个表索引 CREATE INDEX IF NOT EXISTS AccountIndexTable ON Accounts(id,roleId,firstName,lastName,email,accountId); CREATE INDEX IF NOT EXISTS AddressIndexTable ON Addresses(id,ad

我正在用ionic 3创建一个应用程序。在应用程序中,我添加了一个搜索过滤器,根据用户的角色对其进行过滤。我有5个表,我必须从中提取数据

使用所需数据创建每个表索引

CREATE INDEX IF NOT EXISTS AccountIndexTable ON Accounts(id,roleId,firstName,lastName,email,accountId);
CREATE INDEX IF NOT EXISTS AddressIndexTable ON Addresses(id,addressTypeId,street,city,state,country,pincode,accountId)
CREATE INDEX IF NOT EXISTS CompanyIndexTable ON Companies(id,name,accountId)
CREATE INDEX IF NOT EXISTS CommunicationIndexTable ON Communications(id,phone,accountId)
CREATE INDEX IF NOT EXISTS OptionalInfoIndexTable ON CustomerOptionalInfos(id,customerType,accountId)
然后我用join来获取数据。在此之前,我有一些问题

1:我需要在联接中使用索引表吗

联接查询:

SELECT Accounts.accountId AS accountID,
   Accounts.roleId AS roleID,
   Accounts.email AS email,
   Accounts.firstName || " " || Accounts.lastName AS name,
   Addresses.street AS street,
   Addresses.city AS city,
   Addresses.state AS state,
   Addresses.country AS country,
   Addresses.pincode AS pincode,
   Communications.phone AS phone,
   Companies.name AS compName,
   CustomerOptionalInfos.customerType AS cType
FROM Accounts
LEFT JOIN Addresses ON Addresses.accountId=Accounts.accountId
AND Addresses.addressTypeId=1
LEFT JOIN Communications ON Communications.accountId=Accounts.accountId
LEFT JOIN Companies ON Companies.accountId=Accounts.accountId
LEFT JOIN CustomerOptionalInfos ON CustomerOptionalInfos.accountId=Accounts.accountId
WHERE 1=1
  AND Accounts.isDelete!='true'
  AND Accounts.firstName!= ''
  AND Accounts.roleId = 5
ORDER BY Accounts.firstName ASC
LIMIT ?,?

执行仍然需要+2秒。请告诉我更好的方法。我有大量的数据。

我怀疑除了AccountsIndexTable列之外,其他任何索引都没有被使用(但请检查以确定),因为您正在连接各个表的
accountId
列,但这不是这些索引中的第一个。有关sqlite如何使用索引以及为什么列的顺序很重要的详细信息,请参阅。每个索引都在使用中。问题在于加载时间。