This project is designed to compare the performance of inserting data into a PostgreSQL database using two different approaches: a JSONB column and a traditional table structure.
scripts/jsonb_test.sql: Contains SQL commands to create a table with a JSONB column and insert sample data for performance testing.scripts/table_test.sql: Contains SQL commands to create a proper table structure with defined columns and insert sample data for performance testing.scripts/performance_test.js: A Node.js script that connects to the database, executes the SQL scripts, measures the time taken for inserts, and compares the performance of both approaches.tsconfig.json: TypeScript configuration file specifying compiler options and files to include.package.json: npm configuration file listing dependencies and scripts for the project.
-
Install Dependencies: Run the following command to install the necessary dependencies:
npm install -
Database Configuration: Ensure you have a PostgreSQL database set up and update the connection details in
performance_test.js. -
Run Performance Tests: Execute the performance test script using Node.js:
node scripts/performance_test.js -
Review Results: After running the tests, review the console output for the time taken for inserts using both JSONB and traditional table structures.
This project aims to provide insights into the performance implications of using JSONB columns versus traditional table structures in PostgreSQL, particularly focusing on insert operations.
JSONB Insert Performance: 6.035s
Table Insert Performance: 18.844s
JSONB Insert Performance: 5.681s
Table Insert Performance: 18.947s