DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • PostgreSQL vs MySQL Performance
  • Top 8 PostgreSQL GUI Software in 2021
  • 5 Key Postgres Advantages Over MySQL
  • MySQL Instant DDL: Metadata Locks, Waiting Writers, and Query Pileups

Trending

  • The Three Tiers of Agentic Incident Response: When to Trust AI Autonomy
  • ScyllaDB in Enterprise Java: High-Performance NoSQL With Eclipse JNoSQL
  • Avoiding AI Debt as a Team
  • The Self-Hosting Math Changed While We Were Still Arguing About Sovereignty

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Databases
  4. Sysbench-tpcc Supports PostgreSQL (No, Really This Time)

Sysbench-tpcc Supports PostgreSQL (No, Really This Time)

When I initially announced sysbench-tpcc, I mentioned that it potentially could run against PostgreSQL, but it was more like wishful thinking than reality.

By 
Vadim Tkachenko
·
Apr. 25, 18 · Analysis
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
4.9K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

This time, we really mean it when we say sysbench-tpcc supports PostgreSQL.

When I initially announced sysbench-tpcc, I mentioned that it potentially could run against PostgreSQL, but it was more like wishful thinking than reality. The reality was that even though both databases speak SQL, the difference in dialects was too big and the queries written for MySQL could not run without modification on PostgreSQL.

Well, we introduced needed changes, and now you can use sysbench-tpcc with PostgreSQL. Just try the latest commit to https://github.com/Percona-Lab/sysbench-tpcc.

If you're interested, here is a quick overview of what changes we had to make:

It appears that PostgreSQL does not support the tinyint and datatime data types. We had to use smallint and timestamp fields, even if using makes the database size bigger.

PostgreSQL does not have a way to disable Foreign Key checks like MySQL: SHOW TABLES. The best replacement we found is:

select * from pg_catalog.pg_tables where schemaname != 'information_schema' and schemaname != 'pg_catalog'

PostgreSQL does not have a way to disable Foreign Key checks like MySQL:

SET FOREIGN_KEY_CHECKS=0

With PostgreSQL, we needed to create and load tables in a very specific order to avoid Foreign Keys violations. PostgreSQL requires you to have a unique index name per the whole database, white MySQL requires it only per table. So instead of using:

CREATE INDEX idx_customer ON customer1 (c_w_id,c_d_id,c_last,c_first)
CREATE INDEX idx_customer ON customer2 (c_w_id,c_d_id,c_last,c_first)

We need to use:

CREATE INDEX idx_customer1 ON customer1 (c_w_id,c_d_id,c_last,c_first)
CREATE INDEX idx_customer2 ON customer2 (c_w_id,c_d_id,c_last,c_first)

PostgreSQL does not have a STRAIGHT_JOIN hint, so we had to remove this from queries. But it is worth mentioning that we use STRAIGHT_JOIN mostly as a hack to force MySQL to use a correct execution plan for one of the queries.

PostgreSQL is very strict on GROUP BY queries. All fields that are not in the GROUP BY clause must use an aggregation function. So PostgreSQL complained on queries like:

SELECT d_w_id,sum(d_ytd)-w_ytd diff FROMdistrict,warehouse WHERE d_w_id=w_id AND w_id=1 GROUP BY d_w_id

...even when we know that only single value for w_ytd is possible. We had to rewrite this query as:

SELECT d_w_id,SUM(d_ytd)-MAX(w_ytd) diff FROMdistrict,warehouse WHERE d_w_id=w_id AND w_id=1 GROUP BY d_w_id

So, you can see there was some work involved when we tried to migrate even a simple application from MySQL to PostgreSQL.

Hopefully, now, sysbench-tpcc supports PostgreSQL. It is a useful tool to evaluate a PostgreSQL performance. If you find that we did not optimally execute some transaction, please let us know!

PostgreSQL Database MySQL

Published at DZone with permission of Vadim Tkachenko. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • PostgreSQL vs MySQL Performance
  • Top 8 PostgreSQL GUI Software in 2021
  • 5 Key Postgres Advantages Over MySQL
  • MySQL Instant DDL: Metadata Locks, Waiting Writers, and Query Pileups

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook