Adamek
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Datovy typ primarniho klice -- testovani ## Priprava databaze Vychazime z nasledujicho schematu pro testovani daneho typu. ![](https://i.imgur.com/vWvpIW0.png) ### Integer Pro integer se pridala sekvence generovani id. ```sql= CREATE TABLE IF NOT EXISTS integer_primary_key ( id serial PRIMARY KEY, zero smallint ); ``` ### Textové typy Jelikoz jsme pouzili stejnou funkci na "nahodne" generovani textu, pote budou rozdili v case naklady na rezii okolo ruznych textovych typu. ```sql= CREATE OR REPLACE FUNCTION text_pk_gen() RETURNS text AS $$ BEGIN return MD5(random()::text); END; $$ LANGUAGE plpgsql; CREATE TABLE IF NOT EXISTS text_primary_key ( id text PRIMARY KEY DEFAULT text_pk_gen(), zero smallint ); ``` ```sql= CREATE OR REPLACE FUNCTION char_pk_gen() RETURNS char(128) AS $$ BEGIN return MD5(random()::text); END; $$ LANGUAGE plpgsql; CREATE TABLE IF NOT EXISTS char128_primary_key ( id char(128) PRIMARY KEY DEFAULT char_pk_gen(), zero smallint ); ``` ```sql= CREATE OR REPLACE FUNCTION varchar_pk_gen() RETURNS varchar AS $$ BEGIN return MD5(random()::text); END; $$ LANGUAGE plpgsql; CREATE TABLE IF NOT EXISTS varchar_primary_key ( id varchar PRIMARY KEY DEFAULT varchar_pk_gen(), zero smallint ); ``` ```sql= CREATE OR REPLACE FUNCTION varchar128_pk_gen() RETURNS varchar(128) AS $$ BEGIN return MD5(random()::text); END; $$ LANGUAGE plpgsql; CREATE TABLE IF NOT EXISTS varchar128_primary_key ( id varchar(128) PRIMARY KEY DEFAULT varchar128_pk_gen(), zero smallint ); ``` ### UUID ```sql= CREATE TABLE IF NOT EXISTS uuid_primary_key ( id uuid PRIMARY KEY DEFAULT gen_random_uuid (), zero smallint ); ``` ### Network address ```sql= --Functions for generating ip addresses CREATE OR REPLACE FUNCTION inet_pk_gen() RETURNS inet AS $$ BEGIN return CONCAT( TRUNC(RANDOM() * 255 + 1), '.' , TRUNC(RANDOM() * 255 + 1), '.', TRUNC(RANDOM() * 255 + 1), '.', TRUNC(RANDOM() * 255 + 1) )::INET; END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION varchar_pk_gen() RETURNS inet AS $$ BEGIN return CONCAT( TRUNC(RANDOM() * 255 + 1), '.' , TRUNC(RANDOM() * 255 + 1), '.', TRUNC(RANDOM() * 255 + 1), '.', TRUNC(RANDOM() * 255 + 1) ); END; $$ LANGUAGE plpgsql; --Definitions of tables create table inet_primary_key( id inet primary key default inet_pk_gen(), zero smallint ); create table varchar18_primary_key( id varchar(18) primary key default varchar_pk_gen(), zero smallint ); ``` ## Testovanie Pouzivame pgbench na simulovani poctu useru a requestu. Každý test sme opakovali 5x. Výsledky meraní sme spriemerovali. #### Insert test ```bash pgbench -c 10 -t 1000 -j 1 pa036 -f <script>.sql ``` #### Select test ```bash pgbench -c 10 -t 1 -j 1 pa036 -f <script>.sql ``` Sledovane hodnoty: - latency average (ms) - transactions per second (tps) ### Testovací stroj - Ryzen 5900HS 8c/16t 3.0-4.6Ghz - 512GB PCI-E gen4 SSD - 16GB RAM ### Nastavenia postresql PostgreSQL 14.2 (Ubuntu 14.2-1.pgdg21.10+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.2.0-7ubuntu2) 11.2.0, 64-bit - work_mem = 4 MB - effective_cache_size = 524288 disk pages (usuall 8 KB) ## Insert V tomto teste sme vkladali do tabuľky 10000 záznamov. Tabuľky sme medzi testami nepremazávali. ### Integer ```sql= insert into integer_primary_key (zero) VALUES (0); ``` | Nazev | hodnota | | ----------------------- | -------- | | latency average | 1,0948 ms | | transactions per second | 9134,1049 | ### Textové typy ### text ```sql= insert into text_primary_key (zero) VALUES (0); ``` | Nazev | hodnota | | ----------------------- | ------- | | latency average | 1,0470 ms | | transactions per second | 9305,3862 | ### char128 ```sql= insert into char128_primary_key (zero) VALUES (0); ``` | Nazev | hodnota | | ----------------------- | ------- | | latency average | 1,041 ms | | transactions per second | 9606,702611 | ### varchar ```sql= insert into varchar_primary_key (zero) VALUES (0); ``` | Nazev | hodnota | | ----------------------- | ------- | | latency average | 1,09 ms | | transactions per second | 9147,844848 | ### varchar128 ```sql= insert into varchar128_primary_key (zero) VALUES (0); ``` | Nazev | hodnota | | ----------------------- | ------- | | latency average | 1,0778 ms | | transactions per second | 9281,56095 | ### UUID ```sql= insert into uuid_primary_key (zero) VALUES (0); ``` | Nazev | hodnota | | ----------------------- | ------- | | latency average | 1,0677 ms | | transactions per second | 9345,7541 | ### Network address ### inet ```sql= insert into inet_primary_key (zero) VALUES (0); ``` | Nazev | hodnota | | ----------------------- | ------- | | latency average | 1,1490 ms | | transactions per second | 8701,3498 | ### varchar18 ```sql= insert into varchar18_primary_key (zero) VALUES (0); ``` | Nazev | hodnota | | ----------------------- | ------- | | latency average | 1,1432 ms | | transactions per second | 8748,894 | ## Select V tomto teste sme predpripravili tabuľky s miliónom záznamov a testovali sme select pre desať tisíc záznamov #### Integer ```sql= ... select * from integer_primary_key where id = 764662 ... ``` | Nazev | hodnota | | ----------------------- | ------- | | latency average | 554,3968 | | transactions per second | 18,0919764 | ### Textové typy ### text ```sql= ... SELECT id, zero FROM text_primary_key WHERE id = '1e1FCVOnjWoxdOmXAkosDB0LRlkag0chzK5KSNwZBbmozYudeitkDe3atsojzdpe9HYOXIqKMyMg6lRP2jS9txmeqy'; ... ``` | Nazev | hodnota | | ----------------------- | ------- | | latency average | 651,4806 | | transactions per second | 15,3508308 | ### char128 ```sql= ... SELECT id, zero FROM char128_primary_key WHERE id = 'sBn55B4z9HaU3b3yPfMFaLFes6n5tUi87VSyWFGmtkExoeEme6DqpBNv3OOGolemuMOHEmf0waOPe7mqcyV8vlv2PU4XKSpDOwy40k3oR4adKQIEkoDADWZgEQ9BZ79p'; ... ``` | Nazev | hodnota | | ----------------------- | ------- | | latency average | 614,9822 | | transactions per second | 16,2692894 | ### varchar ```sql= ... SELECT id, zero FROM varchar_primary_key WHERE id = 'TfzREatZQEEBs1UVII5g4ufIaXF3AU1qspsedkUhx7JF8teyWQBDTxPdOCuqC9FotOFNsbyPp6DkxoNsTK51EhV0zksXOpx1FthAiORAMtogX8Kdkvf2KNR'; ... ``` | Nazev | hodnota | | ----------------------- | ------- | | latency average | 630,8586 | | transactions per second | 15,8634568 | ### varchar128 ```sql= ... SELECT id, zero FROM varchar128_primary_key WHERE id = 'b8n3aZ6Q7qTFTmZfjJT7mBAIs64OmJEMCHuJlCuNAQYTJPbhJMz1FaqInd93QLyHonxY5wZMNMtUkkWY0ZAUoJSi9jSzLYRVTfA9BW7V5Okhu'; ... ``` | Nazev | hodnota | | ----------------------- | ------- | | latency average | 620,5056 | | transactions per second | 16,124905 | ### bigtext ```sql= ... SELECT id, zero FROM bigtext_primary_key WHERE id = 'nyLWjG4F24tyxurf5x7jEMBUWnT6WRTtTxK0e2BJQrzvDrdiDWgkodYpkzpUxDhTqL3vWixfnHymaud9xRkYh0ANJwYumgMbiuLoNlAZkgyxd5Xsdo1lzm54ApPgSB63iuAOAn9Ue3pRqJM6VvJKvLan5ZrdLZ2LgVPm0BEP1XjDHoC1ligSVY7CtfxN0mc9VH8fmgQc6nwJTMuz3hP9xtUX50hVpzBhg0ZJY69BVOwTqSe5ufiOdxRLqjLoJaN55VyiORAw0fErus14MCEcjrNag9DjVEtLeznqx5MTiu8auClDlHUeu2oGNNh7v2GstQAqj6DK65kvHOYj1vEHCjFLo2oUxSvdyclAjEw4NPNeOuw4CYbgv0Bt9Qw1xQr2LKnXP9UOXeWPTepKDk4XZ6udAMJA9lUdJlhnSPXfoOLrfGhpyP0I8Q9R7Gqmkw9hv9LovJETsi5ZtNdaE8jsPSKpopLPzpoOpo6cVlkj4ch6lt4YTzeUvbyW4UzR0m7i4wxrdjtL64rO2MB5AYZC7NVZ0DPUtzHWsDTTviJhAWlbQlyDKgAjxytRN3eQkfGj2cqjELGBufzmOL2Kx4MitHPyKGU2JPtCqiwYHQtRVzsZ3QpjhwskwdknMD7X6LGc1yWI'; ... ``` | Nazev | hodnota | | ----------------------- | ------- | | latency average | 698,372 | | transactions per second | 14,323184 | #### UUID ```sql= ... select * from uuid_primary_key where id = '16dc56d7-269b-4ff1-bea8-d5ca8533a4c8'; ... ``` | Nazev | hodnota | | ----------------------- | ------- | | latency average | 561,6474 | | transactions per second | 17,8225532 | ### Network address ### inet ```sql= ... select id, zero from inet_primary_key where id = '184.200.130.67'; ... ``` | Nazev | hodnota | | ----------------------- | ------- | | latency average | 570,0558 | | transactions per second | 17,558676 | ### varchar18 ```sql= ... select id, zero from varchar18_primary_key where id = '184.200.130.67'; ... ``` | Nazev | hodnota | | ----------------------- | ------- | | latency average | 621,0332 | | transactions per second | 16,1045912 | ## Velikosti tabulek | Table name | index size | table size | total size | | ---------------------- | ---------- | ---------- | ---------- | | varchar18_primary_key | 46 MB | 38 MB | 84 MB | | varchar128_primary_key | 99 MB | 122 MB | 222 MB | | varchar_primary_key | 99 MB | 122 MB | 222 MB | | uuid_primary_key | 50 MB | 39 MB | 88 MB | | text_primary_key | 99 MB | 122 MB | 221 MB | | integer_primary_key | 35 MB | 21 MB | 56 MB | | inet_primary_key | 42 MB | 29 MB | 72 MB | | char128_primary_key | 160 MB | 214 MB | 373 MB | | bigtext_primary_key | 538 MB | 920 MB | 1458 MB | ### Grafy ![](https://i.imgur.com/jvoL98P.png) ![](https://i.imgur.com/5QqJMfg.png) ![](https://i.imgur.com/AcGPzWc.png) ![](https://i.imgur.com/NX4mKgD.png) ![](https://i.imgur.com/90hXZCq.png) ![](https://i.imgur.com/BGxcEuw.png) ## Sumár Na základe našich testov sme zistili, že rýchlosť vkladania do tabuľky sa medzi jednotlivými typmi líši len málo. Pre selecty 10000 nahodnych hodnot z vlozenych sme zaznamenali vacsie rozdiely. Napriklad inet bol o 9 % rýchlejší ako varchar18. Keďže inet poskytuje aj ďalšie funkcie na zisťovanie príslušnosti k sieti, nevidíme význam v používaní charakterového typu pre ukladanie internetových adries. #### Veľkosti tabuliek Veľkosť tabuliek a teda aj indexov sa zvyšovala podľa priestorovej náročnosti dátového typu. Integer mal veľkosť najmenšiu. Textové typy mali veľkosti podľa množstva textu uloženého v riadkoch. Z tohto pohľadu je najhorši char128, ktorý na rozdiel od varchar a text má vždy 128 znakov a teda potencionálne plytvá miesto doplnením znakov. Neintuitívne bolo, že velkosť indexov v prípade varchar 18, uuid, integer a inet bola väčšia ako velkosť samotnej tabulky.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully