8000 Indexing for query on data->>'created_at' · Issue #28 · dbazhenov/github-stat · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Indexing for query on data->>'created_at' #28
Open
@FranckPachot

Description

@FranckPachot

For the following query (PostgresSwitch4):

SELECT data
            FROM github.pulls
            WHERE (to_timestamp((data->>'created_at')::text, 'YYYY-MM-DD"T"HH24:MI:SS"Z"') >= NOW() - INTERVAL '3 months')
            LIMIT 10;

Why is it cast from text to timestamp and then back to text?
The problem is that this function is not immutable and cannot be indexed.

With the followingquery, an index on github.pulls ((data->>'created_at') asc) could be used

SELECT data
            FROM github.pulls
            WHERE data->>'created_at' >= to_char(NOW() - INTERVAL '3 months','YYYY-MM-DD"T"HH24:MI:SS"Z"')
            LIMIT 10;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0