How to Make Efficient Google-App-Engine Schema with Lots of BooleanPropertys
I'm building a GAE app that has objects with a lot of boolean properties. I want to be able to search through those properties making a query like (in psuedo-sql) "get items where X1=True, X2=False, X3=False and let X4 through X7 be either true or false".
I have a model similar to the one shown below:
class JobModel(BaseModel):
job_name = db.StringProperty();
part_time = db.BooleanProperty();
has_401k = db.BooleanProperty();
has_health_in = db.BooleanProperty();
has_childcare = db.BooleanProperty();
has_edu_reim = db.BooleanProperty();
The problem is that GAE requires an index for every possible way of searching these booleans. So if you have 5 boolean prop开发者_StackOverflowerties you will need 32 different indexes. If you have 20 boolean properties (in my actual case) you need over a million indexes!
There must be a better way to setup this datastore schema, right?
This may be a good opportunity for a StringListProperty.
Set membership is a strength of the ListProperty.
You would need to provide a way to update and marshal the list but it could be efficient for your needs.
db.StringListProperty
has = ['401k:T', 'health_in:F', 'has_childcare:T']
GQL Where Clause
"WHERE has = '401k:T' and has = 'health_in:F'"
ListProperties require some effort to understand their strengths and application.
GAE datastore list property serialization
精彩评论