Symfony2 Sonata Admin Bundle,提高排序性能

时间:2016-03-24 15:00:34

标签: symfony doctrine-orm sonata-admin symfony-sonata sonata

好的:

 protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
                ->add('oidval')
                ->add('xxxUserCategory', null, array(
                    'sortable' => true,
                    'sort_field_mapping' => array('fieldName' => 'name'),
                    'sort_parent_association_mappings' => array(array('fieldName' => 'xxxUserCategory')
                    ))
                )
                ->add('xxxUserStatus', null, array(
                    'sortable' => true,
                    'sort_field_mapping' => array('fieldName' => 'name'),
                    'sort_parent_association_mappings' => array(array('fieldName' => 'xxxUserStatus')
                    ))
                )
                ->add('mailboxSize')
                ->add('copyStatus', null, array(
                    'sortable' => true,
                    'sort_field_mapping' => array('fieldName' => 'name'),
                    'sort_parent_association_mappings' => array(array('fieldName' => 'copyStatus')
                    ))
                )
                ->add('copyErrorCount', null, array('label' => 'Copy Error'))
                ->add('currentSiteList.name')
        ;
    }

对于每个可排序的字段的索引,结果查询将为:

SELECT 
  DISTINCT i0_.id AS id_0, 
  c1_.name AS name_1 
FROM 
  xxxuser i0_ 
  LEFT JOIN site_list s2_ ON i0_.current_site_list_id = s2_.id 
  LEFT JOIN xxxuser_category i3_ ON i0_.xxxuser_category_id = i3_.id 
  LEFT JOIN xxxuser_status i4_ ON i0_.xxxuser_status_id = i4_.id 
  LEFT JOIN copy_status c1_ ON i0_.copy_status_id = c1_.id 
ORDER BY 
  c1_.name ASC 
LIMIT 
  33 OFFSET 0

在解释时给出:

id selected_type table type possible_keys key key_len ref rows Extra
1 SIMPLE i0_ ALL (NULL) (NULL) (NULL) (NULL) 1.000.000 Using temporary; using filesort;
2 SIMPLE c1_ eq_ref PRIMARY PRIMARY 4 xxx.i0_.copy_status_id 1

为了让我自己制作自定义排序查询或改进现有的奏鸣曲策略进行排序,我有哪些选择? 鉴于临时使用;使用filesort,对于1000000行,每次排序都会得到30秒,这是不可行的。

0 个答案:

没有答案