Skip to content

Performance Slowdown With One Additional Column #2359

Description

@EmmettM

Describe the bug

Getting an unexpectedly high latency on a relatively simple query:

select ts, last(close) from 'ohlc_exchanges' where pair in 'btc-usd' and exchange in 'coinbase' and ts >= cast(1608864755 * 1000000L AS TIMESTAMP) and ts <= cast(1656125555 * 1000000L AS TIMESTAMP) sample by 1d align to calendar with offset '00:00' limit 5000

Table has ~65M rows. "Pair" and "exchange" are indexed and the table is partitioned by month. QDB 6.4.2. Query takes about 6000ms.

I have a similar table w/ ~25M rows that does not have the exchange column, and similar queries on this table take around 200ms.

To reproduce

No response

Expected Behavior

Expecting similar performance to the second table.

Environment

- **QuestDB version 6.4.2**:

Additional context

No response

Activity

  1. EmmettM commented on Jul 28, 2022

    @EmmettM
    Author

    Table Schema:

    {'column': 'ts', 'type': 'TIMESTAMP', 'indexed': False, 'indexBlockCapacity': 0, 'symbolCached': False, 'symbolCapacity': 0, 'designated': True}
    {'column': 'pair', 'type': 'SYMBOL', 'indexed': True, 'indexBlockCapacity': 0, 'symbolCached': True, 'symbolCapacity': 32, 'designated': False}
    {'column': 'exchange', 'type': 'SYMBOL', 'indexed': True, 'indexBlockCapacity': 0, 'symbolCached': True, 'symbolCapacity': 32, 'designated': False}
    {'column': 'open', 'type': 'DOUBLE', 'indexed': False, 'indexBlockCapacity': 0, 'symbolCached': False, 'symbolCapacity': 0, 'designated': False}
    {'column': 'high', 'type': 'DOUBLE', 'indexed': False, 'indexBlockCapacity': 0, 'symbolCached': False, 'symbolCapacity': 0, 'designated': False}
    {'column': 'low', 'type': 'DOUBLE', 'indexed': False, 'indexBlockCapacity': 0, 'symbolCached': False, 'symbolCapacity': 0, 'designated': False}
    {'column': 'close', 'type': 'DOUBLE', 'indexed': False, 'indexBlockCapacity': 0, 'symbolCached': False, 'symbolCapacity': 0, 'designated': False}
    {'column': 'volume', 'type': 'DOUBLE', 'indexed': False, 'indexBlockCapacity': 0, 'symbolCached': False, 'symbolCapacity': 0, 'designated': False}
    

    Row count: 62587165

    Distinct pair: 190
    Distinct exchange: 5

  2. bluestreak01 commented on Jul 28, 2022

    @bluestreak01
    Member

    hey Emmett, looking into it, bear with us. I got a hunch that you might want to drop those indexes on pair and exchange. But let me validate this thesis first

  3. EmmettM commented on Jul 28, 2022

    @EmmettM
    Author

    @bluestreak01 no worries– yes I have already dropped those indexes and it did decrease latency from 6000ms to ~1200ms. Just documenting here in case this is something you all want to look at

  4. bluestreak01 commented on Jul 28, 2022

    @bluestreak01
    Member

    could you try these things (all of them):

    in doesn't use JIT (we will fix that), = does

  5. bluestreak01 commented on Jul 28, 2022

    @bluestreak01
    Member

    @EmmettM the date range is 6 months, how many rows would you get with this SQL:

    select count() from 'ohlc_exchanges' 
    where pair = 'btc-usd'
          and exchange = 'coinbase' 
          and ts >= cast(1608864755 * 1000000L AS TIMESTAMP) 
          and ts <= cast(1656125555 * 1000000L AS TIMESTAMP)
  6. EmmettM commented on Jul 31, 2022

    @EmmettM
    Author

    @bluestreak01 the result of that query is 157,847. Trying the other fixes now.

  7. EmmettM commented on Jul 31, 2022

    @EmmettM
    Author

    Just updated the rest of the code– I initially thought there were performance improvements, but my queries are actually taking longer now (18+ seconds). Just to recap:

    QuestDB 6.4.3
    Updated query:
    select ts, last(close) from 'ohlc_exchanges_historical' where pair='btc-usd' and exchange='CPRO' and ts >= cast(0 * 1000000L AS TIMESTAMP) and ts <= cast(1656125555 * 1000000L AS TIMESTAMP) sample by 1d limit 5000
    This query in particular took 18.689 seconds to return 1705 records. There must be something wrong.

    Schema (removed both indexes):
    {'column': 'ts', 'type': 'TIMESTAMP', 'indexed': False, 'indexBlockCapacity': 0, 'symbolCached': False, 'symbolCapacity': 0, 'designated': True} {'column': 'pair', 'type': 'SYMBOL', 'indexed': False, 'indexBlockCapacity': 0, 'symbolCached': True, 'symbolCapacity': 256, 'designated': False} {'column': 'exchange', 'type': 'SYMBOL', 'indexed': False, 'indexBlockCapacity': 0, 'symbolCached': True, 'symbolCapacity': 256, 'designated': False} {'column': 'open', 'type': 'DOUBLE', 'indexed': False, 'indexBlockCapacity': 0, 'symbolCached': False, 'symbolCapacity': 0, 'designated': False} {'column': 'high', 'type': 'DOUBLE', 'indexed': False, 'indexBlockCapacity': 0, 'symbolCached': False, 'symbolCapacity': 0, 'designated': False} {'column': 'low', 'type': 'DOUBLE', 'indexed': False, 'indexBlockCapacity': 0, 'symbolCached': False, 'symbolCapacity': 0, 'designated': False} {'column': 'close', 'type': 'DOUBLE', 'indexed': False, 'indexBlockCapacity': 0, 'symbolCached': False, 'symbolCapacity': 0, 'designated': False} {'column': 'volume', 'type': 'DOUBLE', 'indexed': False, 'indexBlockCapacity': 0, 'symbolCached': False, 'symbolCapacity': 0, 'designated': False}

    This is a new table with 120,289,785 rows.

    There are no error messages in the logs that would indicate that there is some kind of error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions