Changeset 3598

Show
Ignore:
Timestamp:
10/18/07 13:44:03 (1 year ago)
Author:
mscott
Message:

Merge #10 to trunk.

SchevoBenchmark?

  • new benchmark find-entity-values that performs a find operation that can be optimized in the database engine to take advantage of bidirectional links.

schevo.database2:Database._find_entity_oids

  • Optimize db.Foo.find(bar=baz) calls to perform as well as baz.sys.links('Foo', 'bar')
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Benchmark/schevobenchmark/mapping.py

    r3596 r3598  
    1515    # benchmark-alias: [benchmark-name, ...], 
    1616 
    17     'all': ['updates'], 
     17    'all': ['find', 'updates'], 
     18 
     19    # --- 
     20 
     21    'find': ['find-entity-values', 
     22             ], 
     23 
     24    'find-entity-values': 
     25    'schevobenchmark.benchmarks.find_entity_values', 
     26 
     27    # --- 
    1828 
    1929    'updates': ['update-few-fields-entity-fields', 
     30                'update-indexed-entities', 
    2031                'update-several-fields-entity-fields', 
    21                 'update-indexed-entities', 
    2232                ], 
    2333 
    2434    'update-few-fields-entity-fields': 
    2535    'schevobenchmark.benchmarks.update_few_fields_entity_fields', 
     36 
     37    'update-indexed-entities': 
     38    'schevobenchmark.benchmarks.update_indexed_entities', 
    2639     
    2740    'update-several-fields-entity-fields': 
    2841    'schevobenchmark.benchmarks.update_several_fields_entity_fields', 
    29  
    30     'update-indexed-entities': 
    31     'schevobenchmark.benchmarks.update_indexed_entities', 
    3242    } 
    3343 
  • trunk/Schevo/schevo/database2.py

    r3596 r3598  
    720720        indices = extent_map['indices'] 
    721721        normalized_index_map = extent_map['normalized_index_map'] 
     722        field_id_name = extent_map['field_id_name'] 
    722723        field_name_id = extent_map['field_name_id'] 
    723724        # Convert from field_name:value to field_id:value. 
     
    740741            value = field._dump() 
    741742            field_id_value[field_id] = value 
    742         # First, see if the fields given can be found in an index. If 
    743         # so, use the index to return matches. 
    744         # 
    745         # XXX: Should be updated to use partial search via an index, 
    746         # and brute-force on the subset found via that index. 
     743        # Get results, using indexes and shortcuts where possible. 
     744        results = [] 
    747745        field_ids = tuple(sorted(field_id_value)) 
    748746        assert log(3, 'field_ids', field_ids) 
    749747        len_field_ids = len(field_ids) 
     748        # First, see if we can take advantage of entity links. 
     749        if len_field_ids == 1: 
     750            field_id = field_ids[0] 
     751            field_name = field_id_name[field_id] 
     752            value = criteria[field_name] 
     753            if isinstance(value, Entity): 
     754                # We can take advantage of entity links. 
     755                entity_map = self._entity_map(value._extent.name, value._oid) 
     756                entity_links = entity_map['links'] 
     757                extent_id = extent_map['id'] 
     758                key = (extent_id, field_id) 
     759                linkmap = entity_links.get(key, {}) 
     760                results = linkmap.keys() 
     761                return results 
     762        # Next, see if the fields given can be found in an index. If 
     763        # so, use the index to return matches. 
    750764        index_spec = None 
    751765        if field_ids in normalized_index_map: 
     
    754768                    index_spec = spec 
    755769                    break 
    756         results = [] 
    757770        if index_spec is not None: 
    758771            # We found an index to use.