CREATE TABLE application (
    id                      SERIAL          NOT NULL    PRIMARY KEY,
    name                    VARCHAR(100)    NOT NULL,
    version                 VARCHAR(100)    DEFAULT '1.0',
    description             TEXT, 
    language                VARCHAR(100)    NOT NULL,    
    para_diag               VARCHAR(100),
    usage_text              TEXT,
    execution_options       TEXT,
    experiment_table_name   VARCHAR(100)    DEFAULT 'experiment'    
);

CREATE TABLE experiment (
    id                      SERIAL          NOT NULL    PRIMARY KEY,
    application             INT             NOT NULL,
    system_info             TEXT            DEFAULT 'Sys_Info.xml', 
    configuration_info      TEXT            DEFAULT 'Config_Info.xml',
    instrumentation_info    TEXT            DEFAULT 'Instru_Info.xml',
    compiler_info           TEXT            DEFAULT 'Compiler_Info.xml',
    trial_table_name        VARCHAR(100)    DEFAULT 'trial'
);


CREATE TABLE xml_file (
    id                      SERIAL          NOT NULL     PRIMARY KEY,
    trial                   INT,
    metric                  VARCHAR(50),
    name                    TEXT            NOT NULL
);

CREATE TABLE trial (
    id                      SERIAL          NOT NULL    PRIMARY KEY,
    experiment              INT             NOT NULL,
    time                    TIMESTAMP       WITHOUT TIME ZONE,
    problem_size            INT,
    node_count              INT,
    contexts_per_node       INT,
    threads_per_context     INT
);

CREATE TABLE function (
    id                      SERIAL          NOT NULL    PRIMARY KEY,
    trial                   INT             NOT NULL,
    function_number         INT,
    name                    TEXT            NOT NULL,
    metric                  VARCHAR(50),
    group_name              VARCHAR(50)
);

CREATE TABLE user_event (
    id                      SERIAL           NOT NULL    PRIMARY KEY,
    trial                   INT              NOT NULL,
    name                    TEXT             NOT NULL,
    group_name              VARCHAR(50)
);

CREATE TABLE interval_location_profile (
    id                      SERIAL           NOT NULL    PRIMARY KEY,
    function                INT              NOT NULL,
    node                    INT              NOT NULL,             
    context                 INT              NOT NULL,
    thread                  INT              NOT NULL,
    inclusive_percentage    DECIMAL,
    inclusive               DECIMAL,
    exclusive_percentage    DECIMAL,
    exclusive               DECIMAL,
    call                    DECIMAL,
    subroutines             DECIMAL,
    inclusive_per_call      DECIMAL
);

CREATE TABLE atomic_location_profile (
    id                      SERIAL           NOT NULL    PRIMARY KEY,
    user_event              INT              NOT NULL,
    node                    INT              NOT NULL,             
    context                 INT              NOT NULL,
    thread                  INT              NOT NULL,
    sample_count            INT    ,         
    maximum_value           DECIMAL,
    minimum_value           DECIMAL,
    mean_value              DECIMAL,
    standard_deviation      DECIMAL
);

CREATE TABLE interval_total_summary (
    function                INT              NOT NULL   PRIMARY KEY,
    inclusive_percentage    DECIMAL,
    inclusive               DECIMAL,
    exclusive_percentage    DECIMAL,
    exclusive               DECIMAL,
    call                    DECIMAL,
    subroutines             DECIMAL,
    inclusive_per_call      DECIMAL
);

CREATE TABLE interval_mean_summary (
    function                INT              NOT NULL   PRIMARY KEY,
    inclusive_percentage    DECIMAL,
    inclusive               DECIMAL,
    exclusive_percentage    DECIMAL,
    exclusive               DECIMAL,
    call                    DECIMAL,
    subroutines             DECIMAL,
    inclusive_per_call      DECIMAL
);


