zoukankan      html  css  js  c++  java
  • Sybase tempdb

    Tempdb的作用
    sybase server端内部使用
    排序
    创建worktables
    reformatting
    存储临时表和index

    Tempdb用途分类
    Turely temp tables
    Regular user tables
    worktables

    (1)Truly temporary tables
    这种表是正在的临时表, 通过create table #tablename或select into #tablename创建,只在当前session中有效,session结束时,这些表或index自动被drop

    create table #temptable (...)
    or:
    select select_list
        into #temptable ...

    (2)Regular user tables
    通过tempdb..tablename 可以创建RUT,
    create table tempdb..temptable
    or:
    select select_list
        into tempdb..temptable
    在什么情况下使用RUT表呢?
    要在不同session间共享数据,通过grant permission共享
    用于bulk copy
    用完以后用户必须显示的drop掉,否则会一直存在,知道sybase server重启

    (3)Worktables
    在sybase处理join, sort或其他内部操作是创建,这种表不能共享,命令处理完后马上自动被drop


    tempdb的大小
    默认2MB,存储在master device上。
    我们可以用sp_helpdb系统存储过程查看tempdb的大小
    isql>sp_helpdb tempdb
    name      db_size  owner  dbid   created     status
    --------- -------- ------ ------ ----------- --------------------
    tempdb    2.0 MB   sa     2     May 22, 1999 select into/bulkcopy


    device_frag  size    usage        free kbytes
    ------------ -------- ------------ ---------
    master       2.0 MB  data and log 1248

    用户量越大,并发越多,将tempdb大小设置越大越好。通常情况下,设置tempdb的大小为你的数据库大小的20%~25%


    tempdb和lock
    在tempdb中create或drop表,索引会引起system table上锁争用,这些system table包括sysobjects, syscolumns和sysindexes。
    如果在tempdb重复create或drop表和索引,那么最好的办法是在程序启动时将临时表建好,结束时truncate table来删除数据以减少system table上锁的争用。

    tempdb性能优化
    (1) 减少log,多用select into,少用create table #xxx and insert,select into产生最少的log

      (2) 避免在tempdb中创建大的表,如果创建了大的表,记得建index

    (3) 用嵌套SQL,嵌套调用Stored proc 代替大的表

  • 相关阅读:
    结对项目之感
    调查问卷之体会
    我的软件工程课程目标
    关于软件工程的课程建议
    结对编程--fault,error,failure
    结对编程总结
    结对编码感想
    我的软件工程课目标
    《软件工程》课之-调查问卷的心得体会
    软件工程课程讨论记录
  • 原文地址:https://www.cnblogs.com/xzpp/p/2599962.html
Copyright © 2011-2022 走看看