Hello everyone,
I am running Yugabyte 2.12.1.0 on single node, and I am in the process of porting our database from PostgreSQL to Yugabyte. In doing so, I have noticed that certain queries are taking much more time to complete in Yugabyte than in PostgreSQL for the exact same data set. Here is an example of a table I am querying:
CREATE TABLE IF NOT EXISTS demo (name VARCHAR, ts TIMESTAMP(3) WITH TIME ZONE NOT NULL);
CREATE INDEX IF NOT EXISTS demo_name_idx ON demo (name);
CREATE INDEX IF NOT EXISTS demo_like_name_idx ON demo (name varchar_pattern_ops);
CREATE INDEX IF NOT EXISTS demo_ts_idx ON demo (ts DESC);
Then I insert rows in this table with the following statements from within ysqlsh:
DO $$
DECLARE
i INTEGER;
j INTEGER;
baseTime TIMESTAMP(3) WITH TIME ZONE;
BEGIN
baseTime := ‘2022-03-10 11:00:01.000+02’;
FOR i IN 1…1000
LOOP
FOR j IN 1…1000
LOOP
INSERT INTO demo (name, ts) SELECT ‘object_’ || i, baseTime - CAST(j || ‘milliseconds’ AS interval);
END LOOP;
END LOOP;
END $$;
The following are examples of queries that take significantly longer to complete on YugabyteDB than in PostgreSQL:
- SELECT name, ts FROM demo WHERE ts BETWEEN ‘2022-03-10 11:00:00.200+02’ AND ‘2022-03-10 11:00:00.500+02’ ORDER BY ts DESC; – 10.3 sec on YB vs. 235 ms on PG
- SELECT name, ts FROM demo WHERE ts BETWEEN ‘2022-03-10 11:00:00.200+02’ AND ‘2022-03-10 11:00:00.500+02’ AND name LIKE ‘object_62%’ ORDER BY ts desc; – 10.3 sec on YB vs. 49 ms on PG
- SELECT name, ts FROM demo WHERE ts >= ‘2022-03-10 11:00:00.200+02’ ORDER BY ts DESC; – 27.8 sec on YB vs. 578 ms on PG
- SELECT name, ts FROM demo WHERE name LIKE ‘object_62%’ ORDER BY ts DESC; – 34.2 sec on YB vs. 58 ms on PG
I ran “EXPLAIN ANALYZE” on the above queries, and for the queries (1) and (3) the query plan is the same for both YugabyteDB and PostgreSQL (index scan on demo_ts_idx index). For queries (2) and (4), in YugabyteDB index scan is performed using demo_ts_idx index and then the filter ((name)::text ~~ ‘object_62%’::text) is applied. No sequential scan was found in any of the query execution plans.
I tried substituting VARCHAR with TEXT in my table definition (and using text_pattern_ops in the relevant index), but the result was the same. I also tried bringing up tserver with flag --read_buffer_memory_limit=0 (unlimited), but there was still no improvement. Neither did anything change when I attempted to increase the shared buffers on the postgres server that YugabyteDB starts up (using “–ysql_pg_conf=shared_buffers=2GB” flag) .
I would greatly appreciate any guidance and advice with respect to what we need to specify and/or change (either in our DB schema, or in the configuration of the YugabyteDB servers) to achieve performance improvement on the above queries in YugabyteDB.
Thank you