Code Monkey home page Code Monkey logo

data-lab-21-sql-vs-plpgsql's Introduction

Data-lab-21-SQL-vs-PLpgSQL

Create 2 funcs SQL and PLpgSQL

V6__Create_function_to_get_value_plpgsql.sql

create function get_table_value_plpgsql(id int)
returns varchar
language plpgsql
as
$$
declare
   table_value varchar;
begin
   select name
   from product1
   where product1.id = get_table_value_plpgsql.id
   into table_value;

   return table_value;
end;
$$;

V7__Create_function_to_get_value_sql.sql

create function get_table_value_sql1(id int)
returns varchar
language sql
as
$$
  SELECT name
  FROM product1
  WHERE id=id;
$$;

  • flyway migrate:
Снимок экрана 2023-05-25 в 00 05 39 Снимок экрана 2023-05-25 в 00 07 12

Benchmark Commands

For SQL func

-- my_benchmark_sql.sql

\set id random(1, 100000)
BEGIN;
SELECT get_table_value_sql(:id);
END;
pgbench -c 10 -T 300 flyway_test -f my_benchmark_sql.sql

Result:

Снимок экрана 2023-05-25 в 00 24 22

For PLpgSQL func

-- my_benchmark_plpgsql.sql

\set id random(1, 100000)
BEGIN;
SELECT get_table_value_plpgsql(:id);
END;
pgbench -c 10 -T 300 flyway_test -f my_benchmark_pplgsql.sql

Result:

Снимок экрана 2023-05-25 в 00 39 31

data-lab-21-sql-vs-plpgsql's People

Contributors

amir-gaifullin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.