首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >REQL命令耗时太长

REQL命令耗时太长
EN

Stack Overflow用户
提问于 2015-06-05 22:04:20
回答 1查看 115关注 0票数 0

我在rethinkdb数据库中有一个表,记录为580万条,下面提供了一个示例:

代码语言:javascript
复制
{
"release": {
    "genres": {
        "genre": "Electronic"
    },
    "identifiers": {
        "identifier": [
            {
                "description": "A-Side",
                "value": "MPO SK 032 A1 G PHRUPMASTERGENERAL T27 LONDON",
                "type": "Matrix / Runout"
            },
            {
                "description": "B-Side",
                "value": "MPO SK 032 B1",
                "type": "Matrix / Runout"
            },
            {
                "description": "C-Side",
                "value": "MPO SK 032 C1",
                "type": "Matrix / Runout"
            },
            {
                "description": "D-Side",
                "value": "MPO SK 032 D1",
                "type": "Matrix / Runout"
            }
        ]
    },
    "status": "Accepted",
    "videos": {
        "video": [
            {
                "title": "The Persuader (Jesper Dahlbäck) - Östermalm",
                "duration": 290,
                "description": "The Persuader (Jesper Dahlbäck) - Östermalm",
                "src": "http://www.youtube.com/watch?v=AHuQWcylaU4",
                "embed": true
            },
            {
                "title": "The Persuader - Vasastaden",
                "duration": 380,
                "description": "The Persuader - Vasastaden",
                "src": "http://www.youtube.com/watch?v=5rA8CTKKEP4",
                "embed": true
            },
            {
                "title": "The Persuader-Stockholm-Sodermalm",
                "duration": 335,
                "description": "The Persuader-Stockholm-Sodermalm",
                "src": "http://www.youtube.com/watch?v=QVdDhOnoR8k",
                "embed": true
            },
            {
                "title": "The Persuader - Norrmalm",
                "duration": 289,
                "description": "The Persuader - Norrmalm",
                "src": "http://www.youtube.com/watch?v=hy47qgyJeG0",
                "embed": true
            }
        ]
    },
    "labels": {
        "label": {
            "catno": "SK032",
            "name": "Svek"
        }
    },
    "companies": {
        "company": [
            {
                "id": 271046,
                "catno": "",
                "name": "The Globe Studios",
                "entity_type_name": "Recorded At",
                "resource_url": "http://api.discogs.com/labels/271046",
                "entity_type": 23
            },
            {
                "id": 56025,
                "catno": "",
                "name": "MPO",
                "entity_type_name": "Pressed By",
                "resource_url": "http://api.discogs.com/labels/56025",
                "entity_type": 17
            }
        ]
    },
    "styles": {
        "style": "Deep House"
    },
    "formats": {
        "format": {
            "text": "",
            "name": "Vinyl",
            "qty": 2,
            "descriptions": {
                "description": [
                    "12\"",
                    "33 ⅓ RPM"
                ]
            }
        }
    },
    "country": "Sweden",
    "id": 1,
    "released": "1999-03-00",
    "artists": {
        "artist": {
            "id": 1,
            "anv": "",
            "name": "Persuader, The",
            "role": "",
            "tracks": "",
            "join": ""
        }
    },
    "title": "Stockholm",
    "master_id": 5427,
    "tracklist": {
        "track": [
            {
                "position": "A",
                "duration": "4:45",
                "title": "Östermalm"
            },
            {
                "position": "B1",
                "duration": "6:11",
                "title": "Vasastaden"
            },
            {
                "position": "B2",
                "duration": "2:49",
                "title": "Kungsholmen"
            },
            {
                "position": "C1",
                "duration": "5:38",
                "title": "Södermalm"
            },
            {
                "position": "C2",
                "duration": "4:52",
                "title": "Norrmalm"
            },
            {
                "position": "D",
                "duration": "5:16",
                "title": "Gamla Stan"
            }
        ]
    },
    "data_quality": "Complete and Correct",
    "extraartists": {
        "artist": {
            "id": 239,
            "anv": "",
            "name": "Jesper Dahlbäck",
            "role": "Music By [All Tracks By]",
            "tracks": "",
            "join": ""
        }
    },
    "notes": "The song titles are the names of Stockholm's districts."
}}

我试图检索艺术家名字为"Persuader,The“的发行版标题。

我使用了以下命令:

代码语言:javascript
复制
r.db("discogs").table("releases").getField("release").filter(r.row("artists").getField("artist").getField("name").eq("Persuader, The")).getField("title")

时间太长了。然而,它在较小的数据库上快速工作。我该怎么加快速度?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-05 23:50:00

目前,查询中没有索引,这意味着数据库必须遍历艺术家筛选出的每个文档。

可以使用indexCreate命令为嵌套的艺术家名称属性创建索引:

代码语言:javascript
复制
r
  .db("discogs")
  .table("releases")
  .indexCreate('artistName', r.row('release')('artists')('artist')('name'));

之后,您可以使用getAll命令获取具有特定艺术家名称的所有行。

代码语言:javascript
复制
r
  .db("discogs")
  .table("releases")
  .getAll("Persuader, The", { index: 'artistName' });

这不仅更干净,而且更快。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30676485

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档