• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
CUBRID Developer's Course
 

CUBRID Developer's Course

on

  • 6,494 views

This presentation reveals many important aspects of the CUBRID Database, including its unique features, future roadmap, comparison with other databases, architecture, etc.

This presentation reveals many important aspects of the CUBRID Database, including its unique features, future roadmap, comparison with other databases, architecture, etc.

Statistics

Views

Total Views
6,494
Views on SlideShare
6,481
Embed Views
13

Actions

Likes
0
Downloads
55
Comments
0

1 Embed 13

http://www.scoop.it 13

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    CUBRID Developer's Course CUBRID Developer's Course Presentation Transcript

    • CUBRIDDeveloper's Course
      Author: Bomyung Oh
      Team / Department: DBMS Development Lab
      Author(2): Kyungsik Seo
      Team / Department: DBMS Development Lab
    • Comparison of the featuredevelopment speed with MySQL
      CUBRID
      • CUBRID Cluster
      Cluster
      R3.2
      • SQL Compatibility
      • CUBRID FBO
      R3.1
      R3.0
      • HA Feature
      • Hierarchical Query
      R2.0
      • Views
      • Triggers
      • Stored Procedure
      • AUTO_INCREMENT
      • Query Plan Cache
      • Query Result Cache
      • Replication
      • Partitioning
      • Click Counter
      R1.0
      MySQL
      5.5
      5.4
      5.1
      5.0
      • Views
      • Triggers
      • Stored Procedures
      • AUTO_INCREMENT
      • Query Cache
      • Replication
      • Full Text Indexing
      • Partitioning
      • Event scheduler
      • MySQL Cluster
      • XML Functions
      4.1
      4.0
      3.23
      2003
      2001
      2002
      2004
      2005
      2006
      2007
      2008
      2009
      2010
    • Who are using CUBRID
      Over 100,000 Downloads
    • Introduction to CUBRID
      Overview and Architecture of CUBRID
      Using CUBRID
      Introduction to CUBRID HA
    • 1.1 Overview and Architecture of CUBRID
    • What is CUBRID?
      • Introduction
      CUBRIDis a comprehensive open source relational database management system that is highly optimized for Web Applications, particularly those with Read-intensive transactions.
      • Korea
      http://dev.naver.com/projects/cubrid/
      http://www.cubrid.com/online_manual/cubrid_830/index.htm
      http://www.cubrid.com
      http://devcafe.nhncorp.com/g_cubrid
      • Global
      http://www.cubrid.org/
      http://wiki.cubrid.org/index.php/CUBRID_Manuals/cubrid_2008_R3.0_manual
      • You Tube
      http://www.youtube.com/user/cubrid
    • CUBRIDArchitecture (Simplified)
      • A 3-tier structure that separates DB Servers from Brokers
      Broker : DB Server = 1 : N is possible
      Application Client
      Java Apps
      CUBRID Manager
      WAS
      WAS
      Query Editor
      DB Interface
      JDBC driver
      Manager port: 8001,8002
      JDBC
      JDBC
      connect
      Broker port: 30000
      Middleware
      cub_broker
      cub_auto
      Broker1
      Broker2
      cub_job
      cub_cas
      send_fd
      connect
      Server port: 1523
      DBServer
      cub_master
      cub_auto
      connect
      Server port: 1523
      send_fd
      cub_job
      cub_server
      DB Server2
      DB Server1
      Data
      Volume2
      Data
      Volume1
      volume file
      log file
      volume file
      log file
    • CUBRIDArchitecture (Detailed)
      CUBRID
      Manager
      GUI
      CUBRID
      Manager
      Interface
      ODBC
      CCI
      PHP
      OLE DB
      Python
      Ruby
      JDBC
      CM Server
      Broker
      Job
      Queuing
      Monitoring
      Connection
      Pooling
      Logging
      Client Library
      Native C API
      Parser
      Object
      Manager
      Schema
      Manager
      Transaction
      Manager
      Query
      Transform
      Workspace Manager
      Query
      Optimizer
      Memory Manager
      Plan
      Generation
      Communication Module
      Server
      Admin
      Utility
      Communication Module
      Create, Delete, Copy, Rename
      Transaction
      Manager
      Log
      Manager
      Lock
      Manager
      Query
      Manager
      Access
      Method
      B+Tree
      Module
      File Manager
      System
      Catalog Module
      Add Volume
      Buffer Manager
      Load /
      Unload
      Disk Manager
      Backup /
      Restore
      Active
      Log
      Compact /
      Optimize
      File Based
      Objects
      Data
      Volume
      Index
      Volume
      Temp
      Volume
      Check /
      Diag
      Archive
      Log
    • CUBRIDProcess (Detailed)
      JDBC driver
      CCI library
      API
      connect
      query &
      result
      port listening
      query &
      result
      File
      cub_broker
      cubrid_broker.conf
      fork
      parse
      descriptor pass
      Process
      cub_cas
      cub_cas
      shared memory
      csql
      cubridcs.so
      cubridcs.so
      Dynamic shared library
      connect
      cubridcs.so
      request &
      response
      TCP
      job queue
      multi-thread
      port listening
      parse
      descriptor pass
      parse
      cub_master
      cub_server
      cubrid.conf
      UDS
      cubrid.so
      mount
      (read/write)
      register
      read
      volume file
      log file
      databases.txt
      volume file
      log file
      cub_admin
      cubridsa.so
    • 1.2 Using CUBRID
    • Prerequisites for Installation
      Download CUBRID
      http://sourceforge.net/projects/cubrid
      Check supported platforms
      (Linux/Windows)
      uname –r
      rpm –qa | grepglibc
      Install JRE version 1.5 or higher and set up the environment variables(CUBRID Manager)
      http://java.sun.com/javase/downloads/index.jsp
      For Linux
      For Windows
      Visual C++ 2008 distribution pack installation
      Create DB users
      (multiple instances)
      http://www.microsoft.com/downloads/details.aspx?displaylang=ko&FamilyID=9b2da534-3e03-4391-8a4d-074b9f2bc1bf
      Install and launch CUBRID
    • CUBRIDInstallation and Starting CUBRID Service
      • How to install CUBRID and start CUBRID Service in the Windows environment
      • For detailed information, see the manual provided at the following link:. Run the exe file to start the installation wizard.http://www.cubrid.org/manual/gs/gs_install_windows.htm
      • Starting CUBRID Service in the CUBRIDtray
      • How to install CUBRID and start CUBRID Service in the Linux environment
      • For detailed information, see the manual provided at the following link:
      http://www.cubrid.org/manual/gs/gs_install_linux.htm
      • Starting CUBRID Service (CUBRID-related processes must be started)
      For detailed information, see the manual provided at the following link:
      http://www.cubrid.org/manual/gs/gs_must_svcstart.htm
      • Start the CUBRID service by using the following command:
      % sh CUBRID-8.3.0.0312-linux.x86_64.sh% . /home1/cub_user/.cubrid.sh
      % cubrid service start
    • DB Creation and DB Start
      • How to create a new DB and start itFor detailed information, see the manual provided at the following link:
      http://www.cubrid.org/manual/admin/admin_db_create_create.htm
      • Creating testdb and starting it with a command
      • Starting an existing DB(demodb is included in the installation of CUBRID, by default)For detailed information, see the manual provided at the following link:
      http://www.cubrid.org/manual/gs/gs_must_svcstart.htm
      • Creating demodb and starting it with a command
      % cubridcreatedbtestdb
      % cubrid server start testdb
      % cubrid server start demodb
    • CUBRID Manager - Configuration
      • Java-based GUI tools JRE/JDKversion 1.6 or higher is required
      • CUBRID Manager is a tool used to control the functions of servers and brokers, andto monitor and analyze logs
      • CUBIRD Manager consists of the search pane to the left, the query edit pane to the right, the top menu, and the toolbar
    • CUBRID Manager – start
      Start CUBRID Server
      Start CUBRID Manager
      inserthost connection information
      (Default manager account
      ID: admin / PW: admin)
      insert
      DB connection information
      (Default DB account
      ID: dba / PW: No password)
      Start DB Server
      Execute queries
    • CUBRID Manager - stop
      Stop DB Server
      Disconnect from the host
      Stop CUBRID Manager
    • 1.3 Introduction to CUBRID HA
    • Introduction to CUBRID HA
      • Replication
      • No-Automatic Fail-over  No-Automatic Sync
      • HA
      • Automatic Fail-over  Automatic Sync
    • HA Configuration and Usage– DB Server Redundancy
      AP
      Web Server
      AP
      Web Server
      Fail-back
      Fail-over
      Broker #2
      Broker #1
      Automatic failover
      Active
      Server
      Standby
      Server
      Node Fail
      Automatic failover
      Replication
    • HA Configuration and Usage– Broker Redundancy
      AP
      Web Server
      AP
      Web Server
      JDBC Driver
      CCI Library
      Automatic failover
      Fail-back
      Fail-over
      Broker #2
      Broker #1
      Node Fail
      Active
      Server
      Standby
      Server
      Replication
    • Diagram of HA Architecture (Detailed)
      Async
      Update
      Select
      A-Node
      Active Server Node
      S1-Node
      Standby Server Node
      applylogdb
      coyplogdb
      applylogdb
      coyplogdb
      Server
      Active
      Replica
      Standby
      Semi-Sync
      Sync
      active log
      archive logs
      A-node’s
      active & archive logs
      S1-node’s
      active & archive logs
      active log
      archive logs
      Replication Log is not included
      Replication Log is included
      #Configurations#
      #A-Node’s log path
      S1-Node’s active & archive logs
      = $CUBRID_DATABASES/database-name_S1-Node-hostname
      (ex. /home1/cubrid1/DB/tdb01_Snode1)
      copylogdb & applylogdberror logs
      = $CUBRID/log
      #S1-Node’s log path
      A-Node’s active & archive logs
      = $CUBRID_DATABASES/database-name_A-Node-hostname
      (ex. /home1/cubrid1/DB/tdb01_Anode1)
      copylogdb & applylogdberror logs
      = $CUBRID/log
      #Configurations#
      A-node & S1-node’s <cubrid.conf>
      ha_mode=yes
      ha_node_list=hagrpname@A-node:S1-node
      A-node & S1-node’s <cubrid-ha>
      CUBRID_USER=username
      DB_LIST=‘dbname‘
      broker node’s <databases.txt>
      dbnamevol_pathA-node:S1-nodelog_path
    • 2. CUBRIDArchitecture
      CUBRIDVolume Structure
      CUBRIDParameters
      Broker Parameters
      Error Log File
      System Catalog
    • 2.1 CUBRIDVolume Structure
    • CUBRIDVolume Structure
      • * : The table is mapped to aCUBRID file.
      • **: A CUBRID file can be separated to multiple CUBRID volumes.
      File_1
      File_2
      File_3
      Free_Pages
      Volumes
    • DB Volume Structure
    • DBVolume – InformationVolume
      • Information Volumes
      • Data volume
      • Saves the data of an application, such as tables or records
      • A record storage file, called heap, is created in a data volume
      • Index volume
      • A volume in which B+Tree indexes are saved for faster data access or queries
      • Temp volume
      • A volume in which intermediate results are saved to fetch result sets that exceed the size of the memory buffer, or to execute join queries
      • A temporary volume with an appropriate size must be created when creating a DB volume.
      • This is a permanent volume that is used for temporary purposes, and is different from temporary volumes that are used only temporarily.
      • Generic volume
      • The initial volume during DB creation, which can be used as the data, index, or temp volume.
      • If the usage of the volume (data, index, or temporary) is not specified, it can be used for general purposes.
    • DB Volume – Log Volume
      • Log Volumes
      • The active log volume includes the most recent updates that have been applied to a database.
      • Records the status of a committed, aborted, or active transaction.
      • It is used to recover a DB from a storage media failure.
      • When the space allocated to an active log is completely used up, the content of the active log will be copied to and stored in a new log (archive log).
      • Example: demodb_lgat(active log), demodb_lgar*(arcive log)
    • DB Volume – Control Volume
      • Control Information Volumes
      • Volume Information
      • Includes the location information on DB volumes to be created or added
      • This file cannot be manually modified, deleted, or moved.
      • The name of the file is in {dbname}_vinf format.
      • Log Information
      • Records the information of the current logs and archive logs
      • Records the information on a new archive log file and unnecessary archive log file.
      • The name of the file is in {dbname}_lginf format
      -5 C:CUBRIDdatabasesdemodbdemodb_vinf
      -4 C:CUBRIDdatabasesdemodbdemodb_lginf
      -3 C:CUBRIDdatabasesdemodbdemodb_bkvinf
      -2 C:CUBRIDdatabasesdemodbdemodb_lgat
      0 C:CUBRIDdatabasesdemodbdemodb
      1 C:CUBRIDDATABA~1demodbdemodb_x0010
      COMMENT: CUBRID/LogInfo for database /CUBRID/databases/demodb
      ACTIVE: /CUBRID/databases/demodb_lgat 5000 pages
      ARCHIVE: 0 /CUBRID/databases/demodb_lgar000 0 4997
      COMMENT: Log archive /CUBRID/databases/demodb_lgar000 is not needed any longer unless a database media crash occurs.
    • DB Volume – Backup Volume
      • Backup Volume Information
      • Records the location and backup information of a backup volume
      • Located in the same path in which log files are stored.
      • The name of the file is in {dbname}_bkvinf format.
      0 0 /Backup/demodb_bk000 0 level full backup of the first file.
      0 1 /Backup/demodb_bk001 0 level full backup of the second file.
      1 0 /Backup/demodb_bk100 1 level incremental backup of the first file.
      2 0 /Backup/demodb_bk200 2 level incremental backup of the first file.
      The path information of a backup
      file
      Backup level
      information
      The sequence number of a backup volume per
      level
    • DB Volume – $CUBRID/conf/databases.txt
      • databases.txt
      • Contains the name, path, and the name of the built host of a DB.
      • Records the information related to the DB that is created in the databases.txt file upon the creation of a DB.
      • Saved to the path in which the $CUBRID_DATABASES environment variables are specified.
      • If it does not exist in the directory specified by the environment variable, the current directory will be used instead.
      • Caution
      • If a host name has been changed or a DB deleted by an OS command, this file must be modified as well.
      • As the user must be able to modify the databases.txt file during DB creation or deletion, the user must have the privilege to write to this file. If a user without the appropriate privilege attempts to create a DB, the DB creation will fail. For this reason, a DBA should enable the user-write privilege for the directory, or create a databases.txt file in the directory of each user and configure the environment variables.
      demodb /CUBRID/databases/demodb hostname /CUBRID/databases/demodb
      DB name
      DB path
      Host name
      DB log path
    • DB Volume Management
      An example of volume configuration
      disk1
      disk3
      disk2
      db1
      db1_temp
      db1_log
      db1_data
      db1_index
      db_backup
      • Distributes according to usage to avoid the disk bottlenecks
      • Distributes data, index, temp, and log volume so that they are separated from each other
      • Avoids the disk bottlenecks and improves disk management
      • Distributes volumes that can be used simultaneously
      • data & log, data & index, data & temp
      • Configures a volume to an appropriate size to prevent it from adding more volumes while in service
      • Data, Index, Temp, Active Log: Page size and the number of pages must be considered
      • Backup: Backs up with the -r option, and then deletes unnecessary archive logs
    • 2.2 CUBRID Parameters
      $CUBRID/conf/cubrid.conf
    • Environment Configuration File - $CUBRID/conf/cubrid.conf
      • cubrid.conf
      • A file in which the value of CUBRIDsystem parameters are saved.
      • The file is located in a subdirectory of $CUBRID/conf . You are recommended to specify different values from one DB to another DB in the DB.
      • There are two types of parameters: DB server parameters and DB client parameters. If a parameter has been changed in a process, that process must be restarted.
      • SQL is used to change a client parameter.
      • Syntax for configuring parameters
      • Case-insensitive
      • The name and value of a parameter must be inserted on the same line.
      • An equals sign (=) can be used, and a blank character can be added at both sides of the sign..
      • If the value of a parameter is a string, insertthe string without quotation marks. If a blank character is included in the string, encase it with quotation marks.
      [commom]
      data_buffer_pages=250000
      [demodb]
      data_buffer_pages=500000
      • Higher in priority than the configuration of cubrid.conf
      • Add CUBRID_ at the beginning of the parameter to configure it as an environment variable
      • Configuring with an SQL statement
      • Only client parameters can be configured
      • Use “;” for multiple configurations
      Environment Configuration File- $CUBRID/conf/cubrid.conf
      set CUBRID_SORT_BUFFER_PAGE=512
      SET SYSTEM PARAMETERS 'parameter_name=value [{; name=value}...]‘
      SET SYSTEM PARAMETERS 'csql_history_num=70’
      SET SYSTEM PARAMETERS 'csql_history_num=70; index_scan_in_oid_order=1'
    • Memory Related Configurations
      • data_buffer_pages
      • The number of data pages cached to the memory by a DB server
      • Requires an amount of memory equivalent to num_data_buffers times database page size (the page size specified when the DB is initialized; default is 4KB). (The size of the required memory is 100MB if the default is 25,000)
      • The actual size of a DB, the size of the memory, and the number and size of other processes must be considered when determining the size
      • The larger the value, the more data needs to be cached to the memory, which means less disk I/O. However, a value that is too large will cause the full swapping of page buffers.
      • index_scan_oid_buffer_pages
      • Configure the number of buffer pages in which the OID list is to be temporarily stored when scanning indexes
      • The default value is 4, (0.05~16).
    • Memory Related Configurations
      • sort_buffer_pages
      • The number of pages used to process queries that require sorting.
      • One sort buffer is allocated to each active client request.
      • The allocated memory is released upon the completion of sorting.
      • A value between 16 and 500 is recommended.
      • temp_file_memory_size_in_pages
      • Determines the number of buffer pages that cache the temporary results of a query
      • The default value is 4, and the maximum value is 20.
    • Log Related Configurations
      • checkpoint_interval_in_mins, checkpoint_interval_in_npages
      • Configures the interval of a checkpoint execution in min./page
      • The larger the value, the more time it takes to recover a DB.
      • media_failure_support
      • Configures whether to keep an archive log in the event of a storage media failure
      • If it is configured to the default value (yes), all active logs will be copied to and stored in an archive log when changes are made to a transaction while the active logs are full.
      • Please note that any archive logs which have been created while active logs that are full will be deleted if this value is no.
    • On Concurrency Control and Locking
      • isolation_level
      • A parameter used to manage transaction concurrency
      • It must be an integer from 1 to 6 or a character string (Default: 3)
      • The larger the value of the parameter, the lower the concurrency
      • SERIALIZABLE: Inaccessible until transaction is complete
      • REPEATABLE: S_LOCK is maintained until the transaction is complete at SELECT
      • READ UNCOMMITTED: Allows incomplete transactions to be read
      • READ COMMITTED: Allows only completed transactions to be read
    • Configurations Related to Concurrency and Lock
      • deadlock_detection_interval_in_secs
      • Configures the interval, in seconds, of deadlock detection for stopped transactions.
      • Resolves deadlock by rolling back one of the deadlocked transactions
      • The default value is 1sec.Be sure not to set the interval to a large number, as doing so will allow deadlocks remain undetected for that length of time.
      • lock_escalation
      • Converts to table lock if the number of row locks belonging to a table is greater than the specified value.
      • The default value is 100,000.
      • If this value is small, the table management overhead will be reduced, but the concurrency will be decreased.
      • If this value is large, thetable management overhead is will be increased, but the concurrency will be improved.
      • lock_timeout_in_secs
      • Specifies the waiting time of a lock
      • If the lock has not been allowed within the specified period of time, the transaction is cancelled, and an error is returned.
      • The default value is -1, in which case the wait time is unlimited. If it is 0, there is no wait time.
    • Configurations Related to Query Caches
      • max_plan_cache_entries
      • Configures the maximum number of query plans to be cached to the memory (Default: 1,000)
      • If this value is lower than 1, it will not work - it works only when the value is at least 1.
      • Configures the hint so that query execution plans are created without using cache
      • Use /*+ RECOMPILE +/ in queries
      select /*+ RECOMPILE */ * from record where …
    • Configurations Related to Syntax and Type
      • block_ddl_statement
      • Limits Data Definition Language (as known as DDL)
      • The default value should not be no.
      • block_nowhere_statement
      • It does not execute queries if there are no WHERE clauses in an UPDATE/DELETE statement.
      • The default value should not be no.
      • single_byte_compare
      • When comparing strings, set it so that it will compare the strings by a single byte.When using Unicode, set it to Yes (for UTF-8).
      • Default:no
    • Other Parameters
      • Parameters related to communication services
      • cubrid_port_id
      • Master Process Port
      • The default valueis 1523
      • If 1523 is already in use, the parameter must be changed to another port number.
      • Client/server request-related
      • max_clients
      • This number represents maximum number of DB clients that can be connected to a DB server at the same time, which by extension also means the total number of concurrent transactions. (Defaultvalue:50)
      • The actual number of concurrent users must be considered
      • DB Server restart configuration
      • auto_restart_server
      • Automatically restarts a DB server that has been stopped due to a failure
      • The default value when restarting the DB is yes.
      • In the HA, the default value is no.
    • Other Parameters
      • Parameters related to transaction processing
      • async_commit
      • Enables the asynchronous commit function (Default value: must not be set to no)
      • Returns a commit to a client before the commit log is flushed to a disk
      • When a failure occurs in a DB server, all commit transactions that have not been flushed to a disk will not be able to be recovered.
      • group_commit_interval_in_msecs
      • Collects commits that have occurred during the setting in a group, and executes them (Default value: no need to configure)
      • Improves performance by collecting commit logs and flushing them to a disk
    • 2.3 Broker Parameters
      $CUBRID/conf/cubrid_broker.conf
    • Broker Environment Configuration - $CUBRID/conf/cubrid_broker.conf
      • Modifying environment configuration
      • Configuration file: $CUBRID/conf/cubrid_broker.conf
      • The file can be modified in an editor. Any changes made will be applied when the Broker restarts.
      • To modify the configuration without a restart, use the following command:
      • Configurable environment variables
      • APPL_SERVER_MAX_SIZE, SQL_LOG, TIME_TO_KILL
      • SESSION_TIMEOUT, KEEP_CONNECTION
      • If an environment variable and its value are incorrect, an error will occur during the restart, which will prevent the restart.
      % broker_changer <br-name> <conf-name> <conf-value>
      % broker_changerbroker1sql_log on
      OK
    • Introduction to Broker Parameters
    • Introduction to Broker Parameters
    • Introduction to Broker Parameters
    • 2.4 Error Log File
      $CUBRID/log/
      $CUBRID/log/server/
      $CUBRID/log/broker/
      $CUBRID/log/broker/sql_log
      $CUBRID/log/broker/error_log
      CUBRRENT_DIRECTORY, $HOME
    • Broker Log File – Connection Log$CUBRID/log/broker/
      • Checking connection log
      • The connection log is a record of the time it takes for each CAS to process a request by Broker.
      • This log has the name of "<broker name>.access" and resides in a directory specified in the ACCESS_LOG of cubrid_broker.conf.
      1 192.168.100.201 - - 1158198049.151 1158198049.246 2008/09/14 10:40:49 ~ 2008/09/14 10:40:49 29438 - -1
      2 192.168.100.201 - - 1158198049.401 1158198049.406 2008/09/14 10:40:49 ~ 2008/09/14 10:40:49 29438 - -1
    • Broker Log File – Error Log$CUBRID/log/broker/error_log
      • Checking error log
      • Records the information about an error that has occurred while processing the request from an application client into the broker_name_app_server_num.err file
      Time: 02/04/09 13:45:17.687 - SYNTAX ERROR *** ERROR CODE = -493, Tran = 1, EID = 38
      Syntax: Unknown class "unknown_tbl". select * from unknown_tbl
    • Broker Log File – SQL Log$CUBRID/log/broker/sql_log
      • SQL log
      • The SQL log file records the SQL that an application client requests, and is saved under the name of "broker_name_app_server_num.sql.log."
      02/04 13:45:17.687 (38) prepare 0 insert into unique_tbl values (1)
      02/04 13:45:17.687 (38) prepare srv_h_id 1
      02/04 13:45:17.687 (38) execute srv_h_id 1 insert into unique_tbl values (1)
      02/04 13:45:17.687 (38) execute error:-670 tuple 0 time 0.000, EID = 39
      02/04 13:45:17.687 (0) auto_rollback
      02/04 13:45:17.687 (0) auto_rollback 0
      *** 0.000
      02/04 13:45:17.687 (39) prepare 0 select * from unique_tbl
      02/04 13:45:17.687 (39) prepare srv_h_id 1 (PC)
      02/04 13:45:17.687 (39) execute srv_h_id 1 select * from unique_tbl
      02/04 13:45:17.687 (39) execute 0 tuple 1 time 0.000
      02/04 13:45:17.687 (0) auto_commit
      02/04 13:45:17.687 (0) auto_commit 0
      *** 0.000
      • The time at which the application sent the request
      • (39) : The sequence number of the SQL statement group, for prepared statement pooling
      • (PC) : Uses the content stored in the plan cache
      • SELECT... : The SQL statement to be executed.
      - When pooling statements, the binding variable of the WHERE clause is displayed as ?.
      • Execute 0 tuple 1 time 0.000
      - Onerow is executed, which takes 0.000 seconds.
      • auto_commit/auto_rollback
      - It signifies that the target will either be committed automatically or rolled back
      - The second auto_commit/auto_rollback is
      an error code. 0 signifies that the transaction has been completed without an error.
    • 2.5 System Catalog
    • Catalog Information
      • Provides schema information access through SQL
      • Tableinformation
      • db_class
      • Important fields: class_name and owner_name
      • Column information
      • db_attribute
      • Important fields: class_name, attr_name, and attr_type
      • Other
      • db_vclass
      • db_index
      • db_index_key
      • db_trig
      • db_partition
      • db_stored_procedure
      • db_auth
    • Catalog Information – Checking Table Information
      • Searching for table information in the catalog (db_class)
      • Searching for table information in the catalog (db_index)
    • 3. CUBRID SQL
      Types, Operators, and Functions
      Comparison of Major SQLs
      Query Plans and Hints
    • 3.1 Types, Operators, and Functions
    • CUBRIDIdentifiers
    • CUBRID Data Types
    • CUBRID Data Types
    • CUBRID Operators
    • CUBRIDFunctions(2008 R3.0 based)
    • CUBRID Functions
    • 3.2 Comparison of Major SQLs
    • Cautions regarding CUBRIDSQL
      • Does not support implicit type conversion.
      Cannot process quotation marks in numeric data.
      • Does not support character sets.
      • Saves and displays the character set configured in an application as it is.
      • Can specify a character set via the JDBC connection url.
      • Does not support multi-byte characters.
      • Column sizes must be defined to allow sufficient space for multi-byte characters.
      • The length or position value in a string function is processed byte by byte.
      • Functions for joining DBs are not supported.
      • Cannot change the column size by using the ALTER TABLE statement.
      • This will be fixed in a future version.
      • If the prepare statement pooling is used, only one result set can be handled per connection.
      • It is recommended to open multiple connections for use.
    • Join Query
      [Inner] Join
      SELECT select_list
      FROM TABLE1T1
      INNER JOIN TABLE2T2 ON T1.COL1 = T2.COL2
      WHERE T1.A = 'test' AND T2.B = 1;
      Left [Outer] Join
      SELECT select_list
      FROM TABLE1 T1
      LEFT OUTER JOIN TABLE2 T2 ON T1.COL1 = T2.COL2 AND T2.B=1
      WHERE T1.A = 'test';
    • Pagination(LIMIT RESULT SET)
      ROWNUM
      SELECT select_list FROM TABLE1 T1
      WHERE T1.A = 'test' AND ROWNUM <= 100
      ORDER BY ORDER_COLUMN;
      ORDERBY_NUM()
      SELECT select_list FROM TABLE1 T1
      WHERE T1.A = 'test'
      ORDER BY ORDER_COLUMN
      FOR ORDERBY_NUM() <= 100;
      LIMIT (from R3.0)
      SELECT select_list FROM TABLE1 T1
      WHERE T1.A = 'test'
      ORDER BY ORDER_COLUMN
      LIMIT 1,100;
    • AUTO_INCREMENT and SERIAL
      SERIAL
      CREATE SERIAL SERIAL_NAME START WITH 1 MAXVALUE 1000 NOCYCLE;
      CREATE TABLE TABLE1( seqnumINT,
      name VARCHAR);
      INSERT INTO TABLE1 VALUES (SERIAL_NAME.next_value, 'test'); //seqnum=1
      AUTO_INCREMENT
      CREATE TABLE TABLE1( seqnum INT AUTO_INCREMENT(1,1000) NOT NULL,
      name VARCHAR);
      INSERT INTO TABLE1 (name) VALUES ('test'); //seqnum=1
    • INDEX
      CREATE INDEX on TABLE1(zipcode,lastname,address);
      SELECT * FROM TABLE1
      WHERE zipcode=1000 AND name LIKE '%test%' AND address LIKE '%seoul‘;
      CUBRIDinternal process:
      • Step 1: Searches for a target in which zipcode=1000 at the index level
      • Step 2: Extracts targets that satisfy the name and address conditions by accessing them at the data level.
      (In contrast, MySQL accesses all the data in which zipcode=1000 at the data level, and then extracts the data that satisfy the other conditions.)
      INDEX usage tips:
      • Thesmaller the size of an index key, the better the performance.
      • Configure an index for columns with a good distribution (narrow range), basic keys, and columns which are the connection point for a join.
      • When configuring indexes, use columns that are infrequently updated.
    • IndexDefinition and Using USING INDEX
      CREATE [ UNIQUE ] INDEX [ index_name ]
      ON table_name ( column_name[(prefix_length)] [ASC | DESC] [ {, column_name[(prefix_length)] [ASC | DESC]} ...] ) [ ; ]
      • The UNIQUE index creates an index that is used for uniqueness constraints.
      • If no index name has been specified, it will be automatically created.
      • You can define an index only for the front part of a character string (Prefix Index)
      SELECT/UPDATE/DELETE...USING INDEX {NONE | index_name[(+)],…};
      • Index names are distinguished by table and are used as table_name.index_name.
      • Scans indexes only when the cost of index scan specified in the USING INDEX clause is lower than the sequential scan.
      • USING INDEX The index scan is executed unconditionally in the case of index_name(+).
      • For USING INDEX NONE, the sequential scan is executed unconditionally.
      • If more than two index names are specified behind the USING INDEX clause, the appropriate index will be selected by the optimizer.
      • If more than two tables are joined, index names must be specified for all tables.
    • IndexDefinition and Using USING INDEX - Tuning
      • If an index column (yymm) is processed by a function in the WHERE clause,there is no index scan.
    • IndexDefinition and Using USING INDEX - Tuning
      • When defining an index, this configures Covering Index while checking the query plan.
      • When comparing the value of an index column to NULL,there will be no index scan.Modifying query
      • Create an index to be able to cover search conditions
      • Create an index to be able to cover the ORDER BY sorting condition
      • The index scan is not available if you perform the LIKE search by binding a dynamic parameter.
      SELECT * FROM tbl WERE col1 LIKE ? || '%‘ //A sequential scan occurs
      • SELECT * FROM tbl WHERE col1 LIKE 'AAA‘ || '%‘//insert a static value
    • 3.3 QueryPlans and Hints
    • Query Plans and Hints
      • Creates a query plan based on the scan methods (sscan and iscan) and the join methods (nl-join, idx-join, and m-join)
    • Configuring the Display and Check of a Query Plan (CUBRIDManager)
      Display Query Plan
    • An Example of Display Query Plan (sscan)
      SELECT * FROM athlete WHERE name='Yoo Nam-Kyu';
      (card, page#)
      • sscan:A sequential scan
      • card: Number of records in an expected result set
      • page#: Expected number of page accesses
      • sel(selectivity): Expected selectivity that satisfies search conditions
      (card, page#)
      sel
    • Example of a Display Query Plan (iscan)
      CREATE INDEX ON athlete(name);
      SELECT * FROM athlete WHERE name='Yoo Nam-Kyu';
      • iscan:An index scan
    • Example of a Display Query Plan (nl-join)
      SELECT * FROMolympic, nation WHEREolympic.host_nation=nation.name;
      • outer table: Contains a small number of records
      • inner table: Contains many records and has indexes
    • Example of a Display Query Plan (idx-join)
      SELECT * FROM game, athlete WHEREgame.athlete_code=athlete.code;
    • Example of a Display Query Plan (m-join)
      SELECT/*+ USE_MERGE */
      * FROM game, athlete WHEREgame.athlete_code=athlete.code;
    • 4 JDBCandOther Management
      JDBC Programming
      Transaction Management
    • 4.1 JDBC Programming
    • The SQL Type and the Java Type
    • JDBCMain Interfaces
      • Supports the JDBC 2.0 standard specifications.
    • How to use JDBC
      • Connect to DB by using JDBC
      1. Loading Driver
      • Class.forName("cubrid.jdbc.driver.CUBRIDDriver")
      • Can connect to DB when a driver is loaded
      2. Making the Connection
      • Connection con = DriverManager.getConnection(url, “user", “passwd");
      • URL style example: jdbc:CUBRID:localhost:33000:demodb:::
      3. Creating a statement object
      • Statement stmt = con.createStatement();
      4. Executing SQLstatement
      • stmt.executeUpdate(“….”);
      • ResultSetrs = stmt.executeQuery( “…..");
    • Make a connection
      Build SQL statement
      Send SQL statement
      Close SQL statement
      Close a connection
      Example of JDBCusage
      import java.sql.*;
      class SimpleExample {
      public static void main(String args[]) {
      String url = “jdbc:CUBRID:localhost:33000:demodb:::”;
      try {
      Class.forName(“cubrid.jdbc.driver.CUBRIDDriver”);
      } catch (ClassNotFoundException e) {
      System.out.println(e.getMessage());
      }
      try {
      Connection myConnection =
      DriverManager.getConnection(url, “user”,”passwd”);
      Statement myStatement = myConnection.createStatement();
      ResultSetrs =
      myStatement.executeQuery("select sysdate from db_root");
      myStatement.close();
      myConnection.close();
      } catch (java.lang.Exception ex) {
      ex.printStackTrace();
      }
      }
      }
    • ResultSetMetaData
    • Send SQL statement
      Fetch row
      Get columns
      Yes
      More columns
      No
      Yes
      More rows
      No
      ResultSet
      ...

      Connection myConnection =
      DriverManager.getConnection(url,”user”,”passwd”);
      Statement myStatement = myConnection.createStatement();
      ResultSetrs = myStatement.executeQuery(“SELECT name,
      title, salary FROM employee”);
      int I = 0;
      while (rs.next()) {
      I++;
      String empName = rs.getString(“name”);
      String empTitle = rs.getString(“title”);
      long empSalary = rs.getLong(“salary”);
      System.out.println(“Employee ” + empName + ” is “
      + empTitle + “ and earns $” + empSalary);
      }

      ...
    • Cautions on CUBRIDJDBCusage
      • Returning resources
      • Make sure to return a DB object such as ResultSet or Statement,Connection after it is used.
      • Return occurs when the close() method is called for a corresponding object.
      • If AutoCommit False is used, return occurs after the transaction for a connection(Commit/Rollback) is explicitly finished.
      • If you execute inner query statements, you must allocate a different connection object to each of them.
      • When other transactions occur in a cycle statement that uses retrieved data
      • When a transaction(Commit/Rollback) occurs for a connection object that is being used, the ResultSet being used is finished.
    • 4.3 Transaction Management
    • Introduction to CUBRIDlocking protocol
      • locking
      • Lockis managed for each transaction, for tables and records
      • For a record, S-lock is acquired for reading, and X-lock is acquired for writing.
      • To get S-lock for a record, you must get IS-lock for the corresponding table.
      • To get S-lock for a record, you must get IX-lock for the corresponding table.
      • Features
      • Configuring SIX-lock for a table
      • When a transaction that has S-lock for a table requests X-lock
      • Valid range of lock
      • X-lock : The time a transaction is finished (i.e., confirmation or withdrawal time)
      • S-lock : REP (the time when a transaction is finished), COMMIT (the time when reading is finished), UNCOMMIT (does not request lock)
    • Features of CUBRIDlocking protocol
      • Configuring S-lock for a table
      • When reading the schema of a corresponding table
      • When reading the higher-tier or lower-tier table of a corresponding table
      • When the number of records a transaction reads is greater than the lock_escalationvalue
      • Configuring X-lock for a table
      • When modifying a corresponding table
      • When the number of records a transaction writes is greater than the lock_escalationvalue
    • Checking locking information
      • You can check the current locking status of the DB.
      • Creates an object for lock object unit: table, record)
      • Displays information for each object
      • Provided information
      • Lock related configuration of a DB server
      • Information of DB clients connected to a DB server
      • Lock table information of an object
    • Checking locking information – lockdbutility
      • Command: lockdb
      • Shows a current snapshot of the locking status of the DB.
      cubrid lockdb [OPTION] database-name
      Options: -o
      • Saves output to a file
      cubrid lockdbdemodb
      Lock-related configuration of a DB server
      Lock Escalation at = 100000, Run Deadlock interval = 1
       Number of locks that can be converted from a row rock to a table lock
    • Checking locking information – lockdbutility
      • Lock information of an object
      OID = 0| 1780| 7
      Object type: Instance of class ( 0| 288| 6) = table_a.
      Total mode of holders = X_LOCK, Total mode of waiters = X_LOCK.
      Num holders= 1, Num blocked-holders= 0, Num waiters= 1
      LOCK HOLDERS:
      Tran_index = 2, Granted_mode = X_LOCK, Count = 2
      LOCK WAITERS:
      Tran_index = 1, Blocked_mode = X_LOCK
      Start_waiting_at = Wed Sep 23 12:06:06 2009
      Wait_for_nsecs = -1
      lock target object information
      No. 2 transaction has X_LOCK for this object.
      No. 1 transaction is waiting to acquire X_LOCK for this object.
    • Checking locking information – lockdbutility
      • Transaction information
      Transaction (index 1, cub_cas, dba@mycom|2908)
      Isolation REPEATABLE CLASSES AND READ UNCOMMITTED INSTANCES
      State TRAN_ACTIVE
      Timeout_period -1
      Transaction (index 2, cub_cas, dba@mycom|2980)
      Isolation REPEATABLE CLASSES AND READ UNCOMMITTED INSTANCES
      State TRAN_ACTIVE
      Timeout_period -1
      No. 1 transaction, cub_casprocess,
      logging into dba, processID:2908
      Lock level: Guaranteeing table read, Dirty read is allowed for the record
      No.2 transaction, cub_cas process,
      logging into dba, processID:2980
      Waiting time to acquire lock, -1: no timeout
    • Checking locking information – CUBRID Manager
      • CUBRID Manger
      • Only visible to dbauser
    • Checking locking information – CUBRID Manager
      • Transaction info
    • Checking locking information – CUBRID Manager
      • Checking an application that has a transaction
      • For CAS, check its information in the CUBRID broker.
      • Check the order of ID in a broker by using a processID.
      • As the process IDs in the above example are 2908 and 2980, they correspond to ID1 and ID2 of query_editor broker.
      • As 2980is occupying X_LOCK, the corresponding transaction (ID2)must be forced to stop, if necessary.
      • For an application, logic change, etc. may be necessary for the application.
      • For a query editor or CSQL, stop the transaction (commit/rollback).
    • Transaction Management
      • Stopping a broker transaction
      • Forcibly stop the corresponding transaction (rollback) by using the Killtran command
      % usage: cubridkilltran [OPTION] database-name
      valid options:
      -i, --kill-transaction-index=INDEX kill transaction with transaction INDEX
      --kill-user-name=ID kill all transactions with user ID
      --kill-host-name=HOST kill all transactions with client HOST
      --kill-program-name=NAME kill all transactions with client program NAME
      -p, --dba-password=PASS password of the DBA user; will prompt if don't specify
      -d, --display-information display information about active transactions
      -f, --force kill the transaction without a prompt for verification
    • 5 Practice
    • CUBRID Installation
      Installing CUBRID (for Windows)
      Downloading and installing CUBRID.
      Creating demodb
      Checking if the CUBRID service tray
      has started
      Checking if the CUBRID service
      has started
      service, process
    • CUBRID Installation
      CUBRID manager client
      Checking if DB is created
      Starting DB server
      Checking if there is aJAVA related error message during start
      Using the Query Editor
      Executing a simple query: select * from db_class
    • CUBRID Installation
      Stopping DB Server
      Stopping CUBRID service
      Checking process
      Starting CUBRID service
    • DB creation
      Creating a DB that satisfies the following conditions
      Creation location and size of each volume
      Page size: 4Kb
      First volume: 5,000p, C:CUBRIDdatabases<DB name>
      Log volume: 100,000p, C:CUBRIDdatabases<DB name>log
      Data volume: 500,000p, C:CUBRIDdatabases<DB name>
      Index volume: 250,000p, C:CUBRIDdatabases<DB name>
      Temp volume: 250,000p, C:CUBRIDdatabases<DB name>
    • DB creation
      Checking the created volume
      Checking the content of databases.txt
      Checking the files in each directory by referring to the volume information file
      control volumes
      information volumes
      log volumes
      Computer name
    • Schema management
      Creating a table that satisfies the following conditions
      Company table (company)
      Company ID (integer): primary key, company name (string)
      Customer table (client)
      CustomerID (integer): not duplicated
      Customer name, title, email, telephone no., address: Character string
      create table company (
      comp_idint primary key, // company ID
      comp_namevarchar(200) // company name
      );
      create table client (
      client_idint primary key, // customer ID
      comp_idint, // company ID
      client_namevarchar(20), // customer name
      title varchar(10), // title
      email varchar(100), // email
      phone varchar(20), // phone no.
      address varchar(200), // address
      );
    • Schema management
      Viewing table information in a CUBRID Manager client
    • Schema management
      Modifying a table according to the following conditions
      Re-creating after deleting a primary key
      Changing type
      Title: charvarcharor varchar char
      Adding/changing an initial value
      Title: Specifying an initial value to ‘new staff’ and deleting it
      alter class client drop constraint pk_client_client_id
      alter class client add primary key(client_id)
      // or (possible to assign PKname),alter class client add constraint pk_id primary key (client_id)
      alter class client rename attribute title as old_title
      alter class client add attribute title char(20)
      update client set title = cast(old_title as char(20))
      alter class client drop attribute old_title
      alter class client change title default 'new staff'
      alter class client change title default NULL
    • Schema management
      Index
      Client
      A customer name is unique. Add an index whose name is u_name.
      Title is in reverse order. Add an index whose name is idx1to sort customer names in forward direction.
      Searching table information by using a catalog
      Checking the information of a created table
      Table name, column information, index information
      create unique index u_name on client(client_name)
      create index idx1 on client(title desc, client_name)
      select * from db_class
      select * from db_attribute where class_name = 'client'
      select * from db_index where class_name = 'client'
    • Data search and manipulation
      Insertingdata
      Insert (10,’company10’), (20,’company20’) into the company table.
      Insert an arbitrary id,name, and the company ID whose comp_id is 20 into a client table in the insert-select format.
      Check inserteddata information by selecting rows from the client table.
      insert into company values (10, 'company10');
      insert into company values (10, 'company10'),(20, 'company20');
      insert into company (comp_id, comp_name) values (20, 'company20');
      insert into client (comp_id, client_id, client_name) select comp_id, 20, 'new staff20'from company where comp_id = 20
    • Data search and manipulation
      Modifying data
      insert an arbitraryid and name into a client table.
      Check the inserted data information by searching for the client table.
      Change the comp_id to 10 for the data inserted in the client table.
      Check inserted data information by searching for the client table.
      insert into client (client_id, client_name) values (30, 'new staff30')
      update client set comp_id = 10 where client_id = 30
    • Data search and manipulation
      Data search
      Retrieve the countries that achieved medals in the 1988 Olympics from the participants and their medal information
      Table where participants are listed: participant
      Medal information table : game
      - Retrievemedal information of the participants in the 1988 Olympics
      select (select name from nation where code = a.nation_code), medal
      from participant a, game b
      where a.host_year = 1988 and a.nation_code = b.nation_code and a.host_year = b.host_year
      select (select name from nation where code = a.nation_code), medal
      from participant a left outer join game b on a.nation_code = b.nation_code and a.host_year = b.host_year
      where a.host_year = 1988
    • Data search and manipulation
      Usingindex
      Sorting the cities that have hosted the Olympics in chronological order
      Table in which the names of cities that have hosted the Olympics are listed: olympic
      Sorting the cities that have hosted the Olympics, so that the most recent ones appear at the front
      select host_year,host_nation,host_city from olympic where host_year > '' using index pk_olympic_host_year(+)
      create index r_year on olympic(host_yeardesc)
      select host_year, host_nation, host_city from olympic where host_year > '' using index r_year(+) order by host_yeardesc
    • Operatorsand functions
      Arithmetic/Join/Type conversion operators
      Checking how many months and days are left until Christmas
      Displaying how many hours, minutes, and seconds are left until a training session is finished
      • Finding out what year this is through more than two methods.
      Checking the date of the last day of this month
      select months_between(to_date('12/25/2008'), sysdate), '12/25/2008' - sysdate from db_root
      select to_char(t1/3600) + 'hour'+to_char(abs(mod(t1,3600)/60)) + 'minute'+ to_char(abs(mod(t1,60))) + 'second'
      from (select '17:00' - systime from db_root) as t(t1)
      select to_char(sysdate, 'yyyy') from db_root
      select extract(year from sysdate) from db_root
      select extract(day from last_day(sysdate)) from db_root
    • Operators and functions
      Function
      Finding an arbitrary number between 1 and 100
      Rounding 3.141592653 to the nearest millionth
      Finding out the number of bus stops where you can catch the No. 10 bus
      Length of the following string (‘substring xyzxxy’), position of ‘str’, extracting 6 characters from the 4th character, removing ‘xy’ from the string, replacing ‘s’ with ‘S’
      select mod(rand(), 100) + 1 from db_root
      select round(3.141592653, 6), trunc(3.141592653, 6) from db_root
      select count(sation_id) from bus where bus_num = '10'
      select length('substring xyzxxy'), instr ('substring xyzxxy', 'str'), substr('substring xyzxxy', 4, 6), rtrim('substring xyzxxy', 'xy'), replace(('substring xyzxxy', 's', 'S')from db_root
    • Operators and functions
      For the Olympic medals, use 'G' for a 'gold medal,' 'S' for a 'silver medal,' and 'B' for a 'bronze medal.'
      Olympic medal table : game
      Use '1900s' for the Olympics held in the 1900s, '2000s' for 2000s, and 'Other' for other years, and calculate the number Olympics held.
      Table showing Olympics years: olympic
      select decode(medal, 'G'. 'gold medal', 'S', 'silver medal', 'B', 'bronze medal') from game
      select case when host_year between 1900 and 1999 then '1900s'
      when host_year between 2000 and 2999then '2000s'
      else 'other years'end as years, count(*)
      from olympic
      group by case when host_year between 1900 and 1999 then '1900s'
      when host_year between 2000 and 2999then '2000s'
      else 'other years'end
    • Operators and functions
      rownum
      • Selectinghosting information of the 11th to 20th Olympics
      Olympics hosting information table: olympic
      • Selecting 11th to 20th by sorting Olympics hosting information by year chronological order
      • Modifying the above query using index hint
      • Grouping by host_nation column
      select * from olympic where rownum between 11 and 20
      select * from olympic order by host_year for orderby_num() between 11 and 20;
      select * from olympic order by host_year limit 11, 20;
      select * from olympic where host_year > 0 and rownum between 11 and 20 using index pk_olympic_host_year(+)
      select host_nation from olympicwhere rownum between 11 and 20 group by host_nation
    • Operators and functions
      serial
      • Create an arbitrary serial object, get the subsequent value, and check the current value.
      create serial seq_no
      select seq_no.next_value from db_root
      select seq_no.current_value from db_root
    • Operators and functions
      Auto increment
      • Create a table having an auto increment column
      • Insertdata to the autoincrement column
      • Insert no date to the auto increment column
      • Select rows and check the auto increment column values
      • Delete rows and re-insertdata
      create table bbs (
      id intauto_increment,
      title string,
      cntint default 0
      )
      insert into bbs(id, title) values(5, 'arbitrary inserting for auto increment')
      insert into bbs(title) values('auto inserting for auto increment')
      select * from bbs
      delete from bbs
      insert into bbs(title) values('auto inserting for auto increment')