On Thu, Mar 18, 2010 at 4:32 PM, Jeff Schnitzer <[email protected]> wrote:
> From one of my followup posts:
>
> Every scrap of documentation I've found says that GAE queries only
> follow a single index (the one exception being zigzag merges, which
> don't apply here). This means that to answer my query.filter(foo,
> "fooValue1").sort("-bar"), there must be an index that contains the
> foo and bar data sorted appropriately, no? Ie:
>
> /Thing/foo:fooValue1/bar:bar9/[thekeyvalue]
> /Thing/foo:fooValue1/bar:bar8/[thekeyvalue]
> /Thing/foo:fooValue1/bar:bar7/[thekeyvalue]
> /Thing/foo:fooValue2/bar:bar8/[thekeyvalue]
> /Thing/foo:fooValue2/bar:bar7/[thekeyvalue]
>
> To satisfy this query, GAE should start following this custom index
> and that's pretty much it. There's no reason for it to touch the
> single-property indexes (foo ASC, foo DESC, bar ASC, and bar DESC).
>
> ...and in my test, if I remove the custom index from
> datastore-indexes.xml, it doesn't work. But also if I use
> setUnindexedProperty, it doesn't work.
>
> It's like setUnindexedProperty is being interpreted as "not only don't
> set single-property indexes, but also don't include the property in
> any custom indexes". This is counterintuitive - if I wanted the index
> not to be built, I can just remove the index.
>
That's correct. Entities are evaluated individually, not as a group, and any
unindexed properties are ignored for the purposes of all indexing, not just
for built-in indexes.
-Nick Johnson
>
> Jeff
>
> On Thu, Mar 18, 2010 at 9:27 AM, Jeff Schnitzer <[email protected]>
> wrote:
> > For those of you reading this thread on appengine-java, I apologize.
> > However, I realized that this is really a general appengine question
> > and might get a better response from someone "in the know" here.
> > Here's the appengine-java thread:
> >
> http://groups.google.com/group/google-appengine-java/browse_thread/thread/efed35cabf60f6ee
> >
> > ----------
> >
> > I'm puzzled by the behavior of custom indexes. I have a simple test
> > case below, a simple equality filter on one property combined with a
> > descending sort on another property. If I set the properties with
> > setUnindexedProperty(), the query fails to find the result. If I set
> > the properties with setProperty(), it does.
> >
> > Why? I have a custom index, therefore the query should not need or
> > touch the single-property indexes on these fields, right?
> >
> > With this requirement, adding a single custom index means the
> > datastore must now update (at least) five indexes on every put() - the
> > single-value ASC and DESC indexes of both properties as well as my
> > custom index. That's gotta hurt.
> >
> > Here's a test case using the low-level API:
> >
> > /** */
> > @Test
> > public void lowLevelTest() throws Exception
> > {
> > DatastoreService service =
> DatastoreServiceFactory.getDatastoreService();
> >
> > Entity ent = new Entity("Thing");
> > ent.setUnindexedProperty("foo", "fooValue");
> > ent.setUnindexedProperty("bar", 123L);
> > // switching to this works
> > //ent.setProperty("foo", "fooValue");
> > //ent.setProperty("bar", 123L);
> > service.put(ent);
> >
> > Query query = new Query("Thing");
> > query.addFilter("foo", FilterOperator.EQUAL, "fooValue");
> > query.addSort("bar", SortDirection.DESCENDING);
> >
> > PreparedQuery pq = service.prepare(query);
> > int count = 0;
> > for (Entity fetched: pq.asIterable())
> > {
> > count++;
> > }
> >
> > assert count == 1;
> > }
> >
> > The last assertion fails. The query doesn't find any results. The
> > automatic datastore index seems to be fine:
> >
> > <!-- Indices written at Mon, 15 Mar 2010 21:49:01 PDT -->
> > <datastore-indexes>
> > <!-- Used 1 time in query history -->
> > <datastore-index kind="Thing" ancestor="false" source="auto">
> > <property name="foo" direction="asc"/>
> > <property name="bar" direction="desc"/>
> > </datastore-index>
> > </datastore-indexes>
> >
> > What's up? Is this just a bug in the dev mode, or is there a real
> > requirement that all properties must have single-value indexes in
> > order to be part of a custom index?
> >
> > Thanks,
> > Jeff
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>
>
--
Nick Johnson, Developer Programs Engineer, App Engine
Google Ireland Ltd. :: Registered in Dublin, Ireland, Registration Number:
368047
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.