dc11512555
dc11512555
  • 发布:2024-12-21 23:55
  • 更新:2025-01-03 01:01
  • 阅读:96

2万条数据 阿里云空间数据库联表查询超时 请教如何优化数据库查询性能

分类:uniCloud

//数据源为collectionList  
<unicloud-db ref="udb" :collection="collectionList" :where="where" page-data="replace" :orderby="orderby"  
                :getcount="true" :page-size="options.pageSize" :page-current="options.pageCurrent"  
                v-slot:default="{data,pagination,loading,error,options}" :options="options" loadtime="manual"  
                @load="onqueryload">  

//collectionList的定义  
                collectionList: [  
                    db.collection('Wenzhou-order').field(  
                        'ReceivingOrders_id,deliveryer_id'  
                    ).getTemp(),   
                    db.collection('uni-id-users').field('nickname as text, _id').getTemp()  
                ],  

//界面搜索传入的参数  
                        <uni-th align="center" filter-type="search"  
                            @filter-change="filterChange($event, 'ReceivingOrders_id.text')">下单员名称</uni-th>  
                        <uni-th align="center" filter-type="search"  
                            @filter-change="filterChange($event, 'deliveryer_id.text')">配送员名称</uni-th>  

//执行搜索的函数  
            filterChange(e, name) {  
                this._filter[name] = {  
                    type: e.filterType,  
                    value: e.filter  
                }  
                console.log(e.filter)  
                console.log(name)  

                    this.where = name + "== '" + e.filter  + "'"  

                console.log(this.where);  
                this.$nextTick(() => {  
                    this.$refs.udb.loadData()  
                })  
            }  

//schema  
        "ReceivingOrders_id": {  
            "bsonType": "string",  
            "title": "下单员名称",  
            "description": "下单者ID,参考`uni-id-users` 表",  
            "foreignKey": "uni-id-users._id",  
            "defaultValue": {  
                "$env": "uid"  
            }  
        },  
        "deliveryer_id": {  
            "bsonType": "string",  
            "title": "配送员名称",  
            "description": "配送员ID,参考`uni-id-users` 表",  
            "foreignKey": "uni-id-users._id",  
            "enum": {  
                "collection": "uni-id-users",  
                "field": "nickname as text, _id as value"  
            },  
            "defaultValue": ""  
        },  

数据表大约有2万条数据,我的疑问是ReceivingOrders_id字段在界面搜索能成功,但是deliveryer_id字段就搜索超时,要求优化,我看了https://doc.dcloud.net.cn/uniCloud/db-performance.html 这里也没看的懂,不知道怎么设置索引和优化联表才可以生效,麻烦赐教

2024-12-21 23:55 负责人:DCloud_uniCloud_CRL 分享
已邀请:
DCloud_uniCloud_CRL

DCloud_uniCloud_CRL

  1. 设置给order表ReceivingOrders_id,deliveryer_id设置索引。
  2. 联表时增加一些条件缩小联表查询数据量。
  3. 数量大的话不建议使用skip进行分页,例如:可以使用_id进行倒序排序后查询。
  • hws007

    请问怎么利用_id分页!_id可以比大小吗!

    2025-01-03 00:45

  • DCloud_uniCloud_CRL

    回复 hws007: 可以了解一下游标分页

    2025-01-03 13:05

hws007

hws007 - 我就是我!

文档有写优化!先过滤主表!再联表查询!速度会快,也就是你要先条件查询Wenzhou-order表!

要回复问题请先登录注册