Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8622559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:05:10+00:00 2026-06-12T07:05:10+00:00

I have PostgreSQL 9.2 and MySQL 5.5 (InnoDB) installed on my laptop. Both database

  • 0

I have PostgreSQL 9.2 and MySQL 5.5 (InnoDB) installed on my laptop.
Both database engines using default installation and populated from the same CSV file.
I have ‘sales_reports’ table with ca. 700K rows.

Scenario 1:

  • following query:

    select name, year, region, branch from sales_reports group by name,
    year, region, branch;

  • PostgreSQL 9.2: Total query runtime: 42.14 sec, 18064 rows retrieved

  • PostgreSQL explain:
    Group  (cost=165091.16..174275.61 rows=73476 width=58) (actual time=35196.959..41896.739 rows=18064 loops=1)
    ->  Sort  (cost=165091.16..166928.05 rows=734756 width=58) (actual time=35196.956..41704.549 rows=734756 loops=1)
        Sort Key: name, year, region, branch
        Sort Method: external merge  Disk: 49920kB
        ->  Seq Scan on sales_reports  (cost=0.00..38249.56 rows=734756 width=58) (actual time=0.048..282.331 rows=734756 loops=1)
    Total runtime: 41906.628 ms
    
  • MySQL 5.5 : Total query runtime: 4.4 sec, 18064 rows retrieved
  • MySQL explain:
    +----+-------------+---------------+------+---------------+------+---------+------+--------+---------------------------------+
    | id | select_type | table         | type | possible_keys | key  | key_len | ref  | rows   | Extra                           |
    +----+-------------+---------------+------+---------------+------+---------+------+--------+---------------------------------+
    |  1 | SIMPLE      | sales_reports | ALL  | NULL          | NULL | NULL    | NULL | 729433 | Using temporary; Using filesort |
    +----+-------------+---------------+------+---------------+------+---------+------+--------+---------------------------------+
    
  • PostgreSQL 10x times slower

Scenario 2:

  • following query:
    select name, year, region, branch, sum(sale) as sale from sales_reports group by name, year, region, branch;
  • PostgreSQL 9.2: Total query runtime: 42.51 sec, 18064 rows retrieved
  • PostgreSQL explain:
    GroupAggregate  (cost=165091.16..176847.26 rows=73476 width=64) (actual time=35160.911..42254.060 rows=18064 loops=1)
    ->  Sort  (cost=165091.16..166928.05 rows=734756 width=64) (actual time=35160.489..41857.986 rows=734756 loops=1)
        Sort Key: name, year, region, branch
        Sort Method: external merge  Disk: 54760kB
        ->  Seq Scan on sales_reports  (cost=0.00..38249.56 rows=734756 width=64) (actual time=0.047..296.347 rows=734756 loops=1)
    Total runtime: 42264.790 ms
    
  • MySQL 5.5 : Total query runtime: 8.15 sec, 18064 rows retrieved
  • MySQL explain:
    +----+-------------+---------------+------+---------------+------+---------+------+--------+---------------------------------+
    | id | select_type | table         | type | possible_keys | key  | key_len | ref  | rows   | Extra                           |
    +----+-------------+---------------+------+---------------+------+---------+------+--------+---------------------------------+
    |  1 | SIMPLE      | sales_reports | ALL  | NULL          | NULL | NULL    | NULL | 729433 | Using temporary; Using filesort |
    +----+-------------+---------------+------+---------------+------+---------+------+--------+---------------------------------+
    
  • PostgreSQL 5x times slower

Scenario 3:

  • following query:
    select name, year, region, sum(sale) as sale from sales_reports group by name, year, region;
  • PostgreSQL 9.2: Total query runtime: 1 sec, 18064 rows retrieved
  • PostgreSQL explain:
    HashAggregate  (cost=45597.12..45655.62 rows=5850 width=37) (actual time=758.396..759.756 rows=4644 loops=1)
    ->  Seq Scan on sales_reports  (cost=0.00..38249.56 rows=734756 width=37) (actual time=0.061..116.541 rows=734756 loops=1)
    Total runtime: 760.133 ms
  • MySQL 5.5 : Total query runtime: 5.8 sec, 18064 rows retrieved
  • MySQL explain:
    +----+-------------+---------------+------+---------------+------+---------+------+--------+---------------------------------+
    | id | select_type | table         | type | possible_keys | key  | key_len | ref  | rows   | Extra                           |
    +----+-------------+---------------+------+---------------+------+---------+------+--------+---------------------------------+
    |  1 | SIMPLE      | sales_reports | ALL  | NULL          | NULL | NULL    | NULL | 729433 | Using temporary; Using filesort |
    +----+-------------+---------------+------+---------------+------+---------+------+--------+---------------------------------+
    
  • PostgreSQL 5x times faster

Any ideas why first two scenarios are so slow on PostgreSQL?

BTW, I created indexes for fields I’m using in the query on PostgreSQL, I didn’t create any indexes on MySQL.

Thanks,

Marek

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:05:11+00:00Added an answer on June 12, 2026 at 7:05 am

    Default postgresql config is rather conservative. For starters, try increasing shared_buffers to 1GB. (Remember about restarting the server for the change to take effect.)

    Also, try increasing work_mem until the GroupAggregate switches to HashAggregate in the explain. You can change this without a restart.

    A word of warning: Before messing with the settings in production, please read the friendly manual, there are some gotchas involved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have changed database from postgresql to mysql , but I don't know how
I have the same question as #1895500 , but with PostgreSQL not MySQL. How
I have a postgresql database and am using it for a project which handles
I have an application in migrating to MySQL and PostgreSQL and I both have
Typically I use a database such as MySQL or PostGreSQL on the same machine
I'm trying to migrate my app from MySql to Postgresql, using Rails3-pre and the
I'm trying to port a database from MySQL to PostgreSQL. I've rebuilt the schema
My database knowledge is reasonable I would say, im using MySQL (InnoDb) for this
I recently switched from MySQL to PostgreSQL. I have one problem left however. Previously,
I'm trying to update supplier table on both PostgreSQL and MySQL using the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.