Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too slow when do the big table join #130

Open
jensenw-pki opened this issue Aug 1, 2019 · 8 comments
Open

Too slow when do the big table join #130

jensenw-pki opened this issue Aug 1, 2019 · 8 comments

Comments

@jensenw-pki
Copy link

MyDatabase.zip
The database query is very slow when do the join with two table(20k records, need about 4 minutes), i tried to use the DB Browser for SQLite to access the same database file and get the same result. But in our android team, they use another ORM library to generate the database, the data access is fast(the same query only need about 100ms). is there any parameter need to be changed when generate the database file?
Attached the database file, and the left join statement is:
select Person.name , Home.address from Person left join Home on Person.home = Home.Id

@editfmah
Copy link
Owner

editfmah commented Aug 1, 2019

Person.home is an integer in the DB definition. so SQLite performs and unordered index scan on the Home table. Changing the definition of Person.home to TEXT sped the query up to 0.032s.

@editfmah
Copy link
Owner

editfmah commented Aug 1, 2019

Can you post your object definition for Person, so we can have a look.

@jensenw-pki
Copy link
Author

Home.swift
import UIKit
import SharkORM

class Home: SRKStringObject{
@objc dynamic var address: String?
}

Person.swift
import UIKit
import SharkORM

class Person: SRKStringObject {
@objc dynamic var name: String?
@objc dynamic var home: Home?
}

@editfmah
Copy link
Owner

editfmah commented Aug 2, 2019

Thanks, I know where that bug will be. I probably assume that all related tables have an "int" primary key.

@jensenw-pki
Copy link
Author

ok, is there any easy fix?

@yc-zhu
Copy link

yc-zhu commented Aug 2, 2019

if ([testClass isSubclassOfClass:[SRKEntity class]]) {
if ([testClass isSubclassOfClass:[SRKStringObject class]]) {
[SharkSchemaManager.shared schemaSetEntity:entity property:propName type: SRK_PROPERTY_TYPE_STRING];
}else if ([testClass isSubclassOfClass:[SRKObject class]]){
[SharkSchemaManager.shared schemaSetEntity:entity property:propName type:SRK_PROPERTY_TYPE_ENTITYOBJECT];
}
// now register a relationship for this object
could we change code to this? Or, we define a new key ,for example 'SRK_PROPERTY_TYPE_ENTITYSTRINGOBJECT', if testClass is subclass of SRKStringObject, we use this key. if type is equal to this key , we create column in table use 'text' not 'integer', this solution is ok ?

@editfmah
Copy link
Owner

editfmah commented Aug 2, 2019

I just have to check that type:SRK_PROPERTY_TYPE_ENTITYOBJECT isn;t used to determine relationships. Otherwise I will need to create type:SRK_PROPERTY_TYPE_ENTITYOBJECT_TEXTPK or similar.

@editfmah
Copy link
Owner

editfmah commented Aug 2, 2019

@yc-zhu, sorry saw you suggested just that in your comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants