review

MySQL核心技术与最佳实践
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
                               Mysql 一些常见的问题
#@主从复制@ 的原理以及实现的过程 及如何处理 @延时@ 问题
#  1.搭建与主数据库完全一样的数据库环境,称为从数据库。
#  2.主数据库一般是实时的业务从数据库
#  3.从数据库一般用于数据的备份,当主数据库发生故障时切换到从数据库继续工作
#  4.可在从数据库作备份、数据统计等工作,这样不影响主数据库的性能
#
#流程: 主数据库数据发生更新-->触发一个mysql 的服务线程 -->产生一个二进制日志-->
#   触发IO线程[打开一个连接,]-->产生一个中继日志-->触发sql线程-->更新从库
#延时解决方案:[1]mysql_proly中间件  [2]提高服务配置  [3]修改mysql.ini binlog_checksum=none
#
#三大线程:IO线程,sql 线程,服务线程
#
#数据如何同步:日志@@@@@@@@ ,sql 语句,两者之间
#
#请求方式: 插件 4.url hash 5.ip hash [12位]
#
#
#
#
#  @读写分离@的搭建
# 首先要有两台数据库服务,master数据库主要用于数据的更新操作[update ,delete,insert ],slave 数据库主要用于[select]
# 代码实现截取sql前6个字符 if($sql_sub=='select'){slave}else{master}

#mysql 动静分离
#
#
#
#
#Mysql 的缓存,存储过程,触发器,事务的实现和原理
#Mysql 缓存
#1. 服务器接收SQL,以SQL和一些其他条件为key查找缓存表(额外性能消耗)
#2. 如果找到了缓存,则直接返回缓存(性能提升)
#3. 如果没有找到缓存,则执行SQL查询,包括原来的SQL解析,优化等.
#4. 执行完SQL查询结果以后,将SQL查询结果存入缓存表(额外性能消耗)
#
#Mysql的储存过程
# 储存过程是一个可编程的函数,它可以有sql 语句和一些特殊的字符串组成,其实就像
# 我们opp中封装的方法,允许控制数据访问
# 优势:1.操作一个函数可执行大量的Transaction-SQL代码,批量处理执行速度很快
#       2.比较灵活,可以完成复杂的逻判断,运算处理
#       3系统管理员可以执行某一储存过程的权限进行限制,实现数据的访问权限控制,避免非授权的限制    
#
<!-- http://www.cnblogs.com/ivictor/p/5045378.html
DELIMIT $   #声明结束字符
CREATE PROCEDURE pro_test2(OUT user_id INT) #创建储存过程的名字
BEGIN
select * from f_user_1 limit 100;#sql 语句+流程控制
end $
#执行储存过程
call pro_test2(1);
#查看
show create procedure pro_test1 
-- 删除存储过程
DROP PROCEDURE pro_test;

IN:   表示输入参数,可以携带数据带存储过程中
OUT: 表示输出参数,可以从存储过程中返回结果
INOUT: 表示输入输出参数,既可以输入功能,也可以输出功能
-->
#
#Mysql的触发器
#
#在MySQL Server里面也就是对某一个表的一定的操作,触发某种条件(Insert,Update,Delete 等),
#从而自动执行的一段程序。从这种意义上讲触发器是一个特殊的存储过程
<!-- 

    DELIMITER $$

    USE `test`$$
    --判断数据库中是否存在tr_a_update触发器
    DROP TRIGGER /*!50032 IF EXISTS */ `tr_a_update`$$
    --不存在tr_a_update触发器,开始创建触发器
    --Trigger触发条件为update成功后进行触发
    CREATE
        TRIGGER `tr_a_update` AFTER UPDATE ON `t_a` 
        FOR EACH ROW BEGIN 
        --Trigger触发后,当t_a表groupid,username数据有更改时,对t_b表同步一条更新后的数据
          IF new.groupid != old.groupid OR old.username != new.username THEN
            UPDATE `t_b` SET groupid=NEW.groupid,username=NEW.username WHEREusername=OLD.username AND groupid=OLD.groupid;
          END IF;

        END;
    $$

    DELIMITER ;
 -->
#Mysql的事务处理
#事务 ACID
#原子性: 确保工作单元内的所有操作都成功完成,否则事务将被中止在故障点,和以前的操作将回滚到以前的状态。
#一致性: 确保数据库正确地改变状态后,成功提交的事务。
#隔离性: 使事务操作彼此独立的和透明的。
#持久性: 确保提交的事务的结果或效果的系统出现故障的情况下仍然存在
#MYSQL的事务处理主要有两种方法
#1.用begin,rollback,commit来实现
    begin开始一个事务
    rollback事务回滚
    commit 事务确认
#2.直接用set来改变mysql的自动提交模式
    mysql默认是自动提交的,也就是你提交一个query,就直接执行!可以通过
    set autocommit = 0 禁止自动提交
    set autocommit = 1 开启自动提交
#Mysql的优化
#1.避免子查询[select * from test1 where id in (select id from test2 where xx=1)]
#2.有顺序的读取 3.避免重复的读写  4.设置自增id  5.避免使用select *  6. 合理的设置字段的类型
#7.数据读写分离  8.分区、分表  9.建立合适的索引  10.避免使用耗费资源的操作 null 
#11.不要使用rand() 12. 尽量不用or 查询 13.查询一条数据的使用加上limit 1 14.开启查询缓存
#15.前期对数据进行合理的评估,进行分区、分表  16.避免使用%前缀的模糊查询  17. 避免使用mysql 自带函数
#18.开启慢日志 19.选择合适的数据库引擎 20.尽量不要在sql 中进行一些逻辑操作 21. 小心“永久链接” mysql_pconnect

#Mysaim 和 Innodb 的区别
#  innodb 支持事务 mysaim 不支持
#  mysaim 支持全文索引 innodb 不支持
#  mysaim 在支持查询操作效率较高,innodb 执行写入操作效率较高
#  mysaim 支持表锁 innodb 支持行锁
#
#  存储结构:
#   myisam --> 储存成三个文件。第一个文件以表的名字开始,扩展名指出文件的类型。
#  .frm 文件存储表定义 。数据文件扩展名为.MYD[MYData]。索引文件扩展MYI[MYINDEX]
#   innodb -->所有的表都保存在同一数据文件, innodb 的受操作系统的限制,一般为2GB
#  存储空间:
#   myisam -->可被压缩,储存空间较小。三种储存格式:静态表,动态表,压缩表。
#   innodb -->需要更多的内存和储存,它会在内存中建立高速的缓冲索引。
#  事务的支持:
#   mysiam --> 强调的是性能,每次查询具有原子性,执行速度比innodb 类型更快,但不提供事务支持
#   Innodb --> 提供事务支持,外部建等高级数据功能。
#  CURD操作:
#   mysaim --> 如果执行select 操作,MyISAM 时更好的选择,在增删的时候需要锁定整张表,效率会低一些。
#   Innodb --> 支持行级锁,删除插入数据的时候只需要锁定该行就行,效率较高。
#  外键:
#   MyISAM -->不支持
#   Innodb -->支持
#Sql 语句的执行速度
#mysql> set profiling=1;
#mysql> show profiles;
# mysql 的分表、分区操作
#横向分表[可以自增id去模,订单生成的时间] [用union 和union all(去重) 联查][select username from  table1 
#union select username from table2]
#纵向分表 [用户表,用户信息表,地区表]
#分区:
#分表是将一个大表按照一定的规则分解成多张具有独立存储空间的实体表,我们可以称为子表,
#每个表都对应三个文件,MYD数据文件,.MYI索引文件,.frm表结构文件。这些子表可以分布在同一块磁盘上,也可以在不同的机器上

#分区:分区和分表相似,都是按照规则分解表。不同在于分表将大表分解为若干个独立的实体表,
#而分区是将数据分段划分在多个位置存放,可以是同一块磁盘也可以在不同的机器。分区后,表面上还是一张表,但数据散列到多个位置了。
#http://www.cnblogs.com/shengdimaya/p/5384884.html
#
#Mysql 索引的建立 / 索引的优化

#mysql> create index name_primary_index on test(name(255));  #创建索引

#mysql> alter table test add FULLTEXT index `title_fulltext_index` (`title`); #通过创建全文索引修改表的结构

#mysql> drop index addtime_unique_index on test;             #删除索引

#mysql> show index from test\G;                              #查看表中的索引

#索引方法hast 和 btree 的区别
# 1.hast 索引能快速定位数据,在数据精确查找方面hast 索引的效率高于btree
# 2.对于like 查询,hast 方法无效,hast 算法基于等值运算
# 3.hast 不支持索引排序,
#
#
#



#索引的优化:
#
#
#
#
#
#
#mysql 的数据备份的方式 
# @@全量备份     @@ 增量备份  
#1.sql 语句备份
#H:\phpStudy2\MySQL\bin>mysqldump -uroot -p ddhong > /phpstudy2/www/ddhong.sql
#
#全量备份:msyqldown /   mysql < asql / data 目录  /保存biglog
#增量备份:重启服务器后产生的binlog日志,将biglog 进行备份
#mysql 字段选择的类型及参数说明
#
#
#Mysql 的行锁和表锁
#http://www.phpddt.com/db/mysql-locking.html
#mysql 的锁机制主要是针对不懂储存引擎支持不同锁机制。
#例如:MYSAIM 和MEMORY 支持表锁,BDB 储存引擎支持页面锁,INNODB支持表锁也支持行锁,默认情况下采用行级索
#锁的特性归纳:
#·表级锁:开销小,加锁快;不会出现死锁;锁定粒度大,发生锁冲突的概率最高,并发度最低。
#·行级锁:开销大,加锁慢;会出现死锁;锁定粒度最小,发生锁冲突的概率最低,并发度也最高。
#·页面锁:开销和加锁时间界于表锁和行锁之间;会出现死锁;锁定粒度界于表锁和行锁之间,并发度一般。
#
#@@表锁分为:【读锁 | 写锁】
#
#共享读锁:当我们对表进行读操作,不会堵塞其他进程对表进行读操作,但会堵塞表的写请求,只有当读锁释放后,才执行其他写操作
#表独占写锁:堵塞其他进程的读写操作
#
#病发操作
#锁调度
#
#@@行锁
#共享锁:允许事务去读一行,阻止事务取得相同的数据                      LOCK IN SHARE MODE  #共享锁
#排他锁:允许事务去更新数据,阻止其他事务取得相同的数据或更新其他数据  FOR UPDATE  #排他锁

#mysql> show status like 'innodb_row_lock%';   查看锁的使用期情况


#非关系型数据库和关系型数据库的区别
#关系型数据库:Oracle,Sql server ,mysql 
#非关系型:Nosql cloudant
#nosql 和关系型数据库的比较:
#优点:1.容易部署,基本属于开源软件,不需花费大量成本
#      2.查询速度快,储存于缓存中。关系型数据库储存在硬盘中
#      3.以key /value 的形式储存,文档形式,图片形式    
#缺点:1.新型的数据库,维护工具和资料有限
#       2.不支持事务的处理
#
#Mysql 的日志有哪些
#
#错误日志
#慢日志
#查询日志
#二进制日志
#查询日志
/***************Mysql 常用命令********************/
#mysql 缓存的命令
#mysql> show full processlist;                              查看mysql 的连接数

#mysql> select @@query_cache_type;                          查看查询缓存的状态

#mysql> set session query_cache_type=on;                    打开查询缓存

#mysql> set session query_cache_type=off;                   关闭查询缓存

#mysql> show variables like 'have_query_cache';             查询缓存是否可用 

#mysql> select @@global.query_cache_size;                   查询缓存大小  

#mysql> show status like 'Qcache';                          查询缓存状态

#mysql> show status like 'Com_select';                      查询缓存的使用情况




#mysql表操作
#mysql> show create table test;                             查看表的结构 

#mysql> show engines\G;                                     查看但前系统支持的引擎

#mysql> alter table test engine=MYISAM;                      修改表的引擎



#mysql> alter table test1 rename test11;                     修改表的名称
#H:\phpStudy2\MySQL\bin>mysql -h localhost -P 3306           链接mysql 终端

 PHP 的操作

#
#cookie 和 session 的工作原理
#
#setcookie(name,value,expire,path,domain,secure)
#setcookie('key','value',time,服务器路径,作用域,规定的https 安全协议);
#
#session:客户端发送请求-->服务器端开启session-->浏览器的消息头set-cookie就存入PHPSESSID
#-->当用户发送请求时将PHPSESSID 带到请求头中-->通过请求头就session_id 带到服务端
#
#两者的区别:
#cookie 存在客户端,session 存在服务器端
#cookie不是很安全,别人可以分析本地的cookie 进行cookie 进行cookie欺骗
#session 存在服务器端,当访问量增多会给服务器带来压力
#单个cookie 保存的数据不超过4k ,很多浏览器最多可以保存20cookie 
#建议:将登陆信息重要的存在session中
#     其他信息存在cookie  

#session 共享
#1、db[会造成数据库压力]、
#2、memcache/redis[一般选择|抗病发能力强|读写数度快]
#3、cookie[关闭浏览器就没了
#4、nfs【】)文件共享/文件同步rsync [每台服务上都生成session文件 浪费资源]
#5、ip哈希 [ 例:学校用ip公网 所有人都用一个ip | vpn也用一个ip 早服务器压力 ]
#
#如何实现:
#1.配置php.ini
#session.save_handler =redis;
#session.save_path="tcp://";
#2.在php 脚本
#ini_set("session.save_handler","redis");
#ini_set("session.save_path","tcp://");
#3.修改.htaccess(超文本入库)
#php_value.session_save_handler='redis';
#php_value session.save_path  "tcp://IP:11211"
#http://www.cnblogs.com/wangxusummer/p/6382151.html
#系统面对 高并发 问题怎么解决【处理方案】
#HTML 静态化
#资源分离[img,mp4]
#数据库集群 ,读写分离
#数据缓存【memcache | reids】
#负载均衡
#单点登录的实现原理
#
#用户请求网站[没登录]--->访问sso 站点[判断有没有token,没有token]-->返回登录也
#--->输入用户信息--->sso 站点验证用户信息--->验证通过后将用户信息生成token 存入cookie 
#
#
#第三方登录原理
#优势:不需要单独的注册账号,提高用户的体验,有利于推广网站
#流程:用户点击登录[根据appid生成临时的code[我们的网站作为第三方的应用,告诉第三方的请求和发和认可]]
#--->引导用户到第三方登录的界面[引导用户授权]--->用户授权后返回code--->再次请求第三方服务器[带上appid,appkey]
#--->验证通过后返回access_token-->网站通过access_token获取有户的唯一标识open_id ;
#
#
#关于电商的购物车流程,及下订单和支付流程【商家入驻模块】
#
#
#
#
#
#
#
#Api 接口与数据量有关吗?Api 接口实现的步骤
#整个过程:
#1.写接口文档//说明,url,请求方式,地址,返回值,请求实例,更新日志
#2.定义数据类型
#3.开始封装类:【1防刷新 2认证 3防改 4签名[接口加密]】
#4.接口测试:postman , phpstrom ,swagger
#5.接口调用:file_get_contents ,curl,snoopy,jsonp,fopen
#
#Memcache 和redis 的应用及区别 [redis做一个队列]
#memcahce add,set,get ,delete,flush,replace
#
#memcache 是将数据存储在内存中           
#memcache 主要是以简单的key-value 的形式储存
#memcache 挂机后数据就没了
#memcache 使用多核而redis是单核
#memcache 通讯协议比较简单、使用高效的内存管理、互不通讯的服务器集群
# redis是将数据存入磁盘
# redis 不仅仅支持简单的key-value类型的数据 还可以存储set list hast 等结构的数据结构
# redis 可以持久缓存,数据备份 即master-slave模式的数据备份。
# redis 在储存比较小的数据时比memcache 性能更高,100k 以上memcache性能高于redis
# redis 操作:open,connect,set,add,sadd,setnx,iset,delete,remove,exists,incr,decr,lpush,rpush,lpop,rpop,
#             lsize,Iget,lGetRange[获取某个区间的值],lReMove,smove[将某个值移动到因一个键上]
#应用场景
#数据交互比较频繁 
#高读写比(热新闻)
#秒杀
#不经常变化
#
#提高缓存的命中率:提前做好缓存预热,增加存储容量,调整缓存颗粒,更新缓存
#
#如何实现网站全静态化
#优势:
#一、减轻服务器负担,浏览网页无需调用系统数据库。
#二、有利于搜索引擎优化SEO,Baidu、Google都会优先收录静态页面,不仅被收录的快还收录的全;
#三、加快页面打开速度,静态页面无需连接数据库打开速度较动态页面有明显提高;
#四、网站更安全,HTML页面不会受php程序相关漏洞的影响;观看一下大一点的网站基本全是静态页面,
#     而且可以减少攻击,防sql注入。数据库出错时,不影响网站正常访问。
#五、数据库出错时,不影响网站的正常访问。
#最主要是可以增加访问速度,减轻服务器负担,当数据量有几万,几十万或是更多的时候你知道哪个更快了
#1.file_get_content();
#2.fopen();
#3.ob_start(); ob_get_contents();
#
#
#非对称加密和对称加密
#对称加密: 加密速度快、最简单的一种加密方式。加密和解密用的是同一把钥匙
#           但是秘钥不好管理和分配,很有可能在传输过程中被拦截,一般采用将对称加密的秘钥进行非对称加密
#非对称加密:相对而言比较安全
#           它使用了一对公钥和私钥,私钥由一方安全保管,公钥可以分发给任何请求的人
#           
#
#
#
#
#php 的代码优化
#1.设置一些静态成员属性,提高数据的
#2.使用循环时,最好设置可控的长度
#3.经历使用单引号
#4.尽量避免一些自调用的魔术方法,__Get,__Set
#5.在使用的include 和 require 的时候,尽量使用绝对路径
#6.使用多个判断时,用switch case
#7.使用数据连接尽量不要用长连接
#8.尽量使用静态页面,apache 解析php 脚本比html慢2-10 倍
#9.尽量使用缓存,php的内置函数
#10.声明一个变量之后,不用就销毁掉
#Tcp 和udp还有ip的区别 
#ip协议:传输层协议,主要解决数据如何在网络中传播
#tcp和udp 使用传输控制协议从一个网络传送数据包到另个个网络
#可以ip想象成一种高速公路,那么tcp和udp就可以看成高速高速公路的卡车
#HTTP:应用层协议,主要解决如何包装数据
#
#三次握手
#
#在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接。 
#第一次握手:建立连接时,客户端发送syn包(syn=j)到服务器,并进入SYN_SEND状态,等待服务器确认; 
#第二次握手:服务器收到syn包,必须确认客户的SYN(ack=j+1),同时自己也发送一个SYN包
#(syn=k),即SYN+ACK包,此时服务器进入SYN_RECV状态; 
#第三次握手:客户端收到服务器的SYN+ACK包,向服务器发送确认包ACK(ack=k+1),此包发送完毕,客户端和服务器进入ESTABLISHED状态,完成三次握手。 完成三次握手,客户端与服务器开始传送数据.
#客户端和服务端简历链接--》等待服务端确认--》服务端确认用户,同事发送一个包---》客户端收到服务端的包后发送确认包
#Sql注入,csrf 攻击,xss 攻击怎么解决,web 常见的攻击和解决方法
#sql:1.过滤特殊字符串,
#    2.pdo 的预处理
#csrf:1.验证码
#     2.token 验证
#
#xss:1.强制过滤字符串
#
#浏览器消息头,响应头参数详情
#消息头:客户端浏览器的信息
#响应头:服务器返回客户端的信息
select r.review_id as reviewid, r.delete_flag as deleteflag, ecu.emp_sub_role as empsubrole, r.emp_sub_role_tech as empsubroletech, nvl(r.review_mng_flag, 'N') as reviewmngflag, r.submit_date as submitdate, r.last_submit_date as lastsubmitdate, r.approve_signatory_id as approvesignatoryid, case when r.status in ('0', '1', '5', '10') then null else r.middle_position_conf end as middlepositionconf, case when r.status in ('0', '1', '5', '10') then null else r.high_position_conf end as highpositionconf, decode(r.status, '5', null, nvl(r.approve_signatory_conf, 'N')) as approvesignatoryconf, case when r.status = '5' then null else r.min_position_condition end as minpositioncondition, case when r.status = '5' then null else r.max_position_condition end as maxpositioncondition, r.standard_auditor_id as standardauditorid, r.final_hw_position as finalhwposition, r.depty_palce as deptypalce, l6.item_code as deptypalcecode, r.operator_date as operatordate, r.flow_busi_key as flowbusikey, r.item_condition as itemcondition, r.institute_hr_condition as institutehrcondition, r.institute_pdu_condition as institutepducondition, r.business_reviewer_id as businessreviewerid, r.comprehensive_reviewer_id as comprehensivereviewerid, ( select u.lname from tpl_user_t u where u.user_id = r.business_reviewer_id ) as businessreviewername, ( select u.lname from tpl_user_t u where u.user_id = r.comprehensive_reviewer_id ) as comprehensivereviewername, r.trial_run_dept_condition as trialrundeptcondition, r.hr_config as hrconfig, r.pdu_rep_config as pdurepconfig, r.pdu_mng_config as pdumngconfig, r.flow_version as flowversion, r.entry_model as entrymode, nvl(technical_model, '0') as technicalmode, decode(r.status, '9', '录用', '12', '撤销', '13', '复核不通过', '待定') as reviewresult, nvl(r.review_palace, r.depty_palce) as reviewpalace, case when r.status in ('5', '7', '8', '9', '13', '15', '16', '17') then r.review_start_date else null end as reviewstartdate, case when r.status in ('5', '7', '8', '9', '13', '15', '16', '17') then to_char(r.review_start_date, 'yyyy-MM-dd hh24:mi:ss') else null end as reviewstartdatestr, r.review_desc as reviewdesc, r.review_next_handler as reviewnexthandler, case when r.status in ('7', '8', '9') then r.position_time else null end as positiontime, r.review_date as reviewdate, to_char(r.review_date, 'yyyy/MM/dd') as reviewdatestr, decode(r.is_exception, 'Y', '是', '否') as isexception, nvl(r.exception_type, '无') as exceptiontype, r.pdu_rep_id as pdurepid, r.pdu_mng_id as pdumngid, ( select u.lname from tpl_user_t u where u.user_id = r.pdu_rep_id ) as pdurepname, ( select u.lname from tpl_user_t u where u.user_id = r.pdu_mng_id ) as pdumngname, r.emp_employee_id as empemployeeid, r.last_updated_by as lastupdatedby, r.creation_date as creationdate, r.review_mng_id as reviewmngid, r.project_no as projectno, r.examine_status as examinestatus, r.status as status, r.remark as remark, case when r.flow_version = 'V3' then decode(r.status, '0', '申请', '1', '离司审查', '5', '复核结果录入', '15', '技术复核', '16', '综合复核', '17', '技术复核', '7', '筛选结果审批', '8', '筛选结果审批', '9', '完成', '10', '重新申请', '11', '已删除', '12', '已撤单', '13', '结束') else decode(r.status, '0', '申请', '1', '离司审查', '2', '接收推荐信息', '3', '初步复核(研究所HR)', '4', '初步复核(产品线HR)', '5', '复核结果录入', '15', '技术复核', '16', '综合复核', '17', '技术复核', '6', '规范审核', '7', '筛选结果审核', '8', '筛选结果审批', '9', '完成', '10', '重新申请', '11', '已删除', '12', '已撤单', '13', '结束') end as statusname, r.created_by as applicatedby, ( select u.lname from tpl_user_t u where u.user_id = r.created_by ) as creationusercn, r.cooperate_rank_type as cooperateranktype, l5.item_code as cooperateranktypecode, r.last_update_date as lastupdatedate, r.institute_hr_id as institutehrid, r.project_team as projectteam, r.cooperate_secretary_id as cooperatesecretaryid, r.dept_rep_id as deptrepid, p1.assignee_ as operatorid, decode(r.status, '9', null, '12', null, '13', null, ( select u.lname from tpl_user_t u where u.user_id = p1.assignee_ )) as operatorname, r.review_no as reviewno, r.cooperate_position as cooperateposition, l7.item_code as cooperatepositioncode, r.prodline_hr_id as prodlinehrid, r.employee_type as employeetype, l4.item_code as employeetypecode, r.is_check_files as ischeckfiles, decode(ecu.is_archived, 'Y', '***', 'N', ecu.emp_name) as empname, ecu.is_archived as isarchived, to_char(ecu.archived_date, 'yyyy-MM-dd') as archiveddate, ecu.emp_number as empnumber, decode(ecu.is_archived, 'Y', '***', 'N', ecu.emp_pyname) as emppyname, ecu.emp_sex as empsex, ecu.emp_userid as empuserid, ecu.emp_userid_mask as empuseridmask, l1.item_code as emppositioncode, ecu.emp_position as empposition, ecu.emp_university_name as empuniversityname, nvl(ecu.is_second_degree_flag, decode(undergraduate_level, null, 'N', 'Y')) as isseconddegreeflag, decode(is_211, '1', 'Y', 'N') as is211universityflag, ecu.emp_graduated_date as empgraduateddate, to_char(ecu.emp_graduated_date, 'yyyy-MM-dd') as empgraduateddatestr, trim(ecu.is_common_recruit_flag) as iscommonrecruitflag, ecu.emp_speciality as empspeciality, ecu.emp_role as emprolecode, ecu.emp_role as emprole, l2.item_code as empskillcode, ecu.emp_skill as empskill, ecu.doc_edoc_id as docedocid, decode(ecu.doc_edoc_id, null, '请上传简历', '已上传简历') as recommendinfostatus, p.project_id as projectid, p.project_name as projectname, c.abbr_name as vendorname, ecu.vendor_code as vendorcode, ecu.certificate_no as certificateno, ecu.is_checked_items as ischeckeditems, ecu.compliance_confirm_item4 as complianceconfirmitem4, ecu.compliance_confirm_item5 as complianceconfirmitem5, ecu.emp_country as empcountry, ecu.birthday as birthday, ecu.emp_role_code as emprolecode, r.previous_hw_position as previoushwposition, r.previous_position_time as previouspositiontime, r.review_score_status as reviewscoreflag, p.po_num as ponum, p.pr_num as prnum, p.commerical_model as commericalmodel, p.hw_pm_work as hwpmid, ( select u.lname from tpl_user_t u where u.user_id = p.hw_pm_work ) as hwpmname, p1.proc_inst_id_ as procinstanceid, p1.task_id as taskid, nvl(org_v.l1_id, org1.prodline_id) as prodlineid, nvl(org_v.l2_id, org1.product_id) as subprodlineid, nvl(org_v.l3_id, org1.pdu_id) as pduid, nvl(org_v.l4_id, org1.develop_id) as developid, org1.org_full_name as pduname, p.hw_dept_code as hwdeptcode, nvl(org_v.l1_org_name, org1.prodline_name) as prodlinename, nvl(org_v.l2_org_name, org1.product_name) as subprodlinename, nvl(org_v.l3_org_name, org1.pdu_name) as pdu, nvl(org_v.l4_org_name, org1.develop_name) as developname, org1.org_full_name as pdunamevalue, nvl(org_v.id, org1.local_org_id) as localorgid, nvl(r.local_org_id, r.pdu_code) as pduidvalue, r.approve_edoc_ids as approveedocids, case when ( select count(1) from tpl_lookup_item_t li where li.classify_code = 'EMP_RESULT_ROLE_CONF' and li.item_name = org_v.l2_org_name ) > 0 then 'Y' else 'N' end as ischangedroleflag, nvl(( select item_attr2 from tpl_lookup_item_t where classify_code = 'REVIEW_REVOKE_CONFITION' and item_code = 'MAIL_RENDER' ), '20') as limitdays, case when r.status in ('5', '15', '16', '17') then to_number(date_part('epoch', trunc(sysdate) - trunc(r.operator_date)) / 86400) else null end as delaydays, case when r.status in ('1', '5', '7', '8', '15', '16', '17', '10') then to_number(date_part('epoch', trunc(sysdate) - trunc(r.submit_date)) / 86400) else null end as costdays, case when r.status in ('0', '10') then sd.execute_service_duration else r.execute_service_duration end as serviceduration, case when r.status in ('0', '10') then get_nearly_four_performance(ecu.emp_number, null) else r.nearly_four_performance end as nearlyfourperformance, ecu.pass_cert_records as passcertrecords, case when ecu.pass_cert_records = '是' then ecu.title else null end as title, r.old_created_by as oldapplicatedby, r.old_dept_rep_id as olddeptrepid, r.old_review_mng_id as oldreviewmngid, r.old_business_reviewer_id as oldbusinessreviewerid, r.old_comprehensive_reviewer_id as oldcomprehensivereviewerid, r.old_approve_signatory_id as oldapprovesignatoryid, r.old_pdu_rep_id as oldpdurepid, r.old_pdu_mng_id as oldpdumngid from omp_emp_review_t r join omp_emp_review_user_t ecu on ecu.emp_employee_id = r.emp_employee_id left join omp_emp_service_duration_t sd on sd.emp_number = ecu.emp_number and sd.vendor_code = ecu.vendor_code left join ( select p.business_key_, p.proc_inst_id_, rt.id_ as task_id, nvl(rt.assignee_, ( select u.user_id from tpl_user_t u where lower(u.lname) = replace(lower(wpf.bs_handlers_), 'u.', '') )) as assignee_, wpf.bs_created_by_ from act_hi_procinst p join act_re_procdef rpd on p.proc_def_id_ = rpd.id_ join tpl_wf_hi_procform_t wpf on p.proc_inst_id_ = wpf.bs_proc_inst_id_ left join act_ru_task rt on rt.proc_inst_id_ = p.proc_inst_id_ where p.proc_def_id_ like 'ReviewProcess%' and p.business_key_ like 'RE%' ) p1 on p1.business_key_ = r.flow_busi_key left join tpl_lookup_item_t l1 on l1.classify_code = 'DEGREE' and l1.item_name = ecu.emp_position and l1.status = '1' left join tpl_lookup_item_t l2 on l2.classify_code = 'SKILL' and l2.item_name = ecu.emp_skill and l2.status = '1' left join tpl_lookup_item_t l4 on l4.classify_code = 'EMP_TYPE' and l4.item_name = r.employee_type and l4.status = '1' left join tpl_lookup_item_t l5 on l5.classify_code = 'EMP_POSITION_TYPE' and l5.item_name = r.cooperate_rank_type and l5.status = '1' left join omp_coop_t c on c.code = ecu.vendor_code and c.status = 'ACTIVE' left join ( select distinct u.university_name, u.undergraduate_level, u.is_211, u.is_985 from omp_university_t u ) u on u.university_name = ecu.emp_university_name left join omp_project_prpo_info_query_v p on p.project_no = r.project_no left join omp_local_org_t org_v on org_v.id = p.local_org_id left join omp_local_org_develop_v org1 on org1.local_org_id = r.local_org_id left join tpl_lookup_item_t l6 on l6.classify_code = 'REGION_DIMENSION' and l6.item_name = r.depty_palce and l6.status = '1' left join tpl_lookup_item_t l7 on l7.classify_code = 'EMP_POSITION' and l7.item_name = r.cooperate_position and l7.status = '1' where 1 = 1 and r.flow_busi_key = 'RE2025081200002N' and r.review_id is not null and ((1 = 1) or (1 = 1) or p1.bs_created_by_ = 340809824852183 or exists ( select 1 from act_hi_identitylink i where i.proc_inst_id_ = p1.proc_inst_id_ and i.type_ = 'participant' and (i.user_id_ = 340809824852183) union select 1 from act_hi_identitylink i where i.proc_inst_id_ = p1.proc_inst_id_ and i.type_ = 'candidate' and (i.user_id_ = 340809824852183) union select 1 from act_hi_identitylink i where i.proc_inst_id_ = p1.proc_inst_id_ and i.type_ = 'CC' and (i.user_id_ = 340809824852183) )) limit 1 select '笔试(或机试)' as "reviewType1", ( select rr.review_record_id from omp_emp_review_record_t rr where rr.review_type = '笔试(或机试)' and rr.review_id = '5336020' ) as "reviewRecordId1", ( select rr.record_result from omp_emp_review_record_t rr where rr.review_type = '笔试(或机试)' and rr.review_id = '5336020' ) as "recordResult1", ( select rr.review_score from omp_emp_review_record_t rr where rr.review_type = '笔试(或机试)' and rr.review_id = '5336020' ) as "reviewScore1", '技术复核' as "reviewType2", ( select rr.review_record_id from omp_emp_review_record_t rr where rr.review_type = '技术复核' and rr.review_id = '5336020' ) as "reviewRecordId2", ( select rr.record_result from omp_emp_review_record_t rr where rr.review_type = '技术复核' and rr.review_id = '5336020' ) as "recordResult2", ( select rr.review_score from omp_emp_review_record_t rr where rr.review_type = '技术复核' and rr.review_id = '5336020' ) as "reviewScore2", ( select rr.rank_type from omp_emp_review_record_t rr where rr.review_type = '技术复核' and rr.review_id = '5336020' ) as "reviewRankType2", ( select rr.hw_position from omp_emp_review_record_t rr where rr.review_type = '技术复核' and rr.review_id = '5336020' ) as "reviewHwPosition2", ( select rr.reviewer_id from omp_emp_review_record_t rr where rr.review_type = '技术复核' and rr.review_id = '5336020' ) as "reviewerId2", ( select u.lname from omp_emp_review_record_t rr, tpl_user_t u where rr.reviewer_id = u.user_id and rr.review_type = '技术复核' and rr.review_id = '5336020' ) as "reviewerName2", ( select rr.review_method from omp_emp_review_record_t rr where rr.review_type = '技术复核' and rr.review_id = '5336020' ) as "reviewMethod2", ( select rr.review_evaluation from omp_emp_review_record_t rr where rr.review_type = '技术复核' and rr.review_id = '5336020' ) as "reviewEvaluation2", ( select rr.review_date from omp_emp_review_record_t rr where rr.review_type = '技术复核' and rr.review_id = '5336020' ) as "reviewDate2", '综合复核' as "reviewType4", ( select rr.review_record_id from omp_emp_review_record_t rr where rr.review_type = '综合复核' and rr.review_id = '5336020' ) as "reviewRecordId4", ( select rr.record_result from omp_emp_review_record_t rr where rr.review_type = '综合复核' and rr.review_id = '5336020' ) as "recordResult4", ( select rr.review_score from omp_emp_review_record_t rr where rr.review_type = '综合复核' and rr.review_id = '5336020' ) as "reviewScore4", ( select rr.rank_type from omp_emp_review_record_t rr where rr.review_type = '综合复核' and rr.review_id = '5336020' ) as "reviewRankType4", ( select rr.hw_position from omp_emp_review_record_t rr where rr.review_type = '综合复核' and rr.review_id = '5336020' ) as "reviewHwPosition4", ( select rr.reviewer_id from omp_emp_review_record_t rr where rr.review_type = '综合复核' and rr.review_id = '5336020' ) as "reviewerId4", ( select u.lname from omp_emp_review_record_t rr, tpl_user_t u where rr.reviewer_id = u.user_id and rr.review_type = '综合复核' and rr.review_id = '5336020' ) as "reviewerName4", ( select rr.review_method from omp_emp_review_record_t rr where rr.review_type = '综合复核' and rr.review_id = '5336020' ) as "reviewMethod4", ( select rr.review_evaluation from omp_emp_review_record_t rr where rr.review_type = '综合复核' and rr.review_id = '5336020' ) as "reviewEvaluation4", ( select rr.review_date from omp_emp_review_record_t rr where rr.review_type = '综合复核' and rr.review_id = '5336020' ) as "reviewDate4", '复核扫描件' as "reviewType5", ( select rr.review_record_id from omp_emp_review_record_t rr where rr.review_type = '复核扫描件' and rr.review_id = '5336020' ) as "reviewRecordId5", ( select rr.review_edoc_id from omp_emp_review_record_t rr where rr.review_type = '复核扫描件' and rr.review_id = '5336020' ) as "reviewEdocId", ( select d.doc_name from omp_emp_review_record_t rr, tpl_document_t d where rr.review_edoc_id = d.doc_edoc_id and rr.review_type = '复核扫描件' and rr.review_id = '5336020' ) as "reviewEdocName" -- 6 -- ==> select emp_role from ( select c.emp_role from omp_emp_resource_t r join omp_emp_cooperate_user_t c on r.emp_employee_id = c.emp_employee_id where c.emp_number = 'WB334479' and c.vendor_code = 'C51134' and r.emp_state != '4' union all select c.emp_role from omp_emp_activity_t a join omp_emp_cooperate_user_t c on a.emp_employee_id = c.emp_employee_id where c.emp_number = 'WB334479' and c.vendor_code = 'C51134' and a.emp_state != '4' ) uu limit 1 -- 7 -- ==> select v.research_min_position as researchminlevel, v.operate_max_position as operationmaxlevel, case when '5' in ('0', '1', '5', '10') then v.middle_position_conf else nvl(null, v.middle_position_conf) end as middlepositionconf, case when '5' in ('0', '1', '5', '10') then v.high_position_conf else nvl(null, v.high_position_conf) end as highpositionconf, decode('5', '5', v.signatory_conf, nvl(null, 'N')) as approvesignatoryconf, case when '5' = '5' and v.middle_position_conf is not null and to_number(replace( replace(replace(replace(replace(nvl(v.middle_position_conf, '0'), 'A', ''), 'B', ''), '初级', '0'), '级', ''), '初', '')) > to_number(replace( replace(replace(replace(replace(nvl('4B', '0'), 'A', ''), 'B', ''), '初级', '0'), '级', ''), '初', '')) then 'Y' when '5' = '5' and v.middle_position_conf is not null and to_number(replace( replace(replace(replace(replace(nvl(v.middle_position_conf, '0'), 'A', ''), 'B', ''), '初级', '0'), '级', ''), '初', '')) <= to_number(replace( replace(replace(replace(replace(nvl('4B', '0'), 'A', ''), 'B', ''), '初级', '0'), '级', ''), '初', '')) then 'N' else null end as minpositioncondition, case when '5' = '5' and v.high_position_conf is not null and to_number(replace( replace(replace(replace(replace(nvl(v.high_position_conf, '10'), 'A', ''), 'B', ''), '初级', '0'), '级', ''), '初', '')) > to_number(replace( replace(replace(replace(replace(nvl('4B', '0'), 'A', ''), 'B', ''), '初级', '0'), '级', ''), '初', '')) then 'N' when '5' = '5' and v.high_position_conf is not null and to_number(replace( replace(replace(replace(replace(nvl(v.high_position_conf, '10'), 'A', ''), 'B', ''), '初级', '0'), '级', ''), '初', '')) <= to_number(replace( replace(replace(replace(replace(nvl('4B', '0'), 'A', ''), 'B', ''), '初级', '0'), '级', ''), '初', '')) then 'Y' else null end as maxpositioncondition from omp_emp_review_position_conf_v v where v.pdu_id = '700' and rownum = 1 -- 8 -- ==> select a6.entrust_order_id as oldentryorderid from omp_emp_activity_t a6, omp_emp_cooperate_user_t u6, ( select u9.emp_number, max(a9.dimission_date) as dimission_date from omp_emp_activity_t a9, omp_emp_cooperate_user_t u9 where u9.emp_employee_id = a9.emp_employee_id and a9.emp_state = '4' and u9.emp_userid = 'pwjNN1L2/Q1dag+9am6S5zCu7ADNygTh2G5/9HOAFB8=' and u9.vendor_code != 'C51134' group by u9.emp_number ) a7 where u6.emp_employee_id = a6.emp_employee_id and u6.emp_number = a7.emp_number and a6.dimission_date = a7.dimission_date and u6.emp_userid = 'pwjNN1L2/Q1dag+9am6S5zCu7ADNygTh2G5/9HOAFB8=' and u6.vendor_code != 'C51134' and a6.emp_state = '4' and rownum = 1 -- 9 -- ==> select doc_edoc_id as docid, doc_name as docname, doc_v as docversion, doc_size as docsize, doc_server as servername from tpl_document_t doc where doc.doc_edoc_id = 'M3T1A904N1164612586533650526' -- 10 -- ==> select v.user_id as userid, v.employee_number as useraccount, v.w3_account as w3account, v.user_name as username from omp_user_privilege_conf_v v where 1 = 1 and v.apartment_code in ('OUTSOURC_MANAGER', 'PDU_MANAGER') and v.prodline_value_code in ('458', '@ALLCONDITION@') and v.subprodline_value_code in ('487', '@ALLCONDITION@') and v.pdu_value_code in ('700', '@ALLCONDITION@') and v.develop_value_code in ('56454', '@ALLCONDITION@') group by v.user_id, v.employee_number, v.w3_account, v.user_name -- 11 -- ==> select count(1) as rscount from t_hoas_resttime t where date_format(concat(concat(t.restyear, '-'), t.restdate), '%Y-%m-%d') > date_format('2025-08-19T17:14:46.000+0800', '%Y-%m-%d') and date_format(concat(concat(t.restyear, '-'), t.restdate), '%Y-%m-%d') <= date_format('2025-09-09', '%Y-%m-%d') -- 19 -- ==> select count(1) from ( select * from ( select v.emp_employee_id as empemployeeid, v.record_no as recordno, v.emp_number as empnumber, v.emp_userid as empuserid, v.emp_userid_mask as empuseridmask, v.emp_name as empname, v.creation_date as creationdate, v.last_update_date as lastupdatedate, v.vendor_code as vendorcode, v.status_name as statusname, v.event_name as eventname, v.event_type as eventtype, v.depty_palce as deptypalce, v.rank_type as ranktype, v.hw_position as hwposition, v.new_hw_position as newhwposition, v.created_by as applicatedby, v.project_team as projectteam, v.vendor_name as vendorname, v.project_no as projectno, v.project_name as projectname, v.po_num as ponum, v.pr_num as prnum, v.commerical_model as commericalmodel, v.hw_dept_code as hwdeptcode, v.hw_org_name as hworgname, v.created_name as applicatedname, v.hw_pm_work_name as hwpmname, v.proc_inst_id as procinstid, v.handlers as handlerbyname, v.bg as prodlinename, v.bu as subprodlinename, v.pdu as pdu from omp_user_flow_query_t v where 1 = 1 and v.is_archived = 'N' and v.emp_number = upper('WB334479') ) t ) -- 20 -- ==> select data_from as "dataFrom", flow_key as "flowKey", decode(is_archived, 'Y', '***', 'N', emp_name) as "empName", emp_number as "empNumber", vendor_code as "vendorCode", abbr_name as "vendorName", emp_position as "empPosition", emp_speciality as "empSpeciality", last_update_date as "lastUpdateDate" from ( select '0' as data_from, '人员基本信息' as flow_key, ecu.emp_name, ecu.emp_number, ecu.vendor_code, c.abbr_name, ecu.emp_position, ecu.emp_speciality, ecu.is_archived, ecu.last_update_date from omp_emp_cooperate_user_t ecu join omp_emp_activity_t a on a.emp_employee_id = ecu.emp_employee_id left join omp_coop_t c on c.status = 'ACTIVE' and c.code = ecu.vendor_code where ecu.emp_number = 'WB334479' union all select '1' as data_from, r.flow_busi_key as flow_key, ru.emp_name, ru.emp_number, ru.vendor_code, c.abbr_name, ru.emp_position, ru.emp_speciality, ru.is_archived, ru.last_update_date from omp_emp_review_user_t ru join omp_emp_review_t r on ru.emp_employee_id = r.emp_employee_id left join omp_coop_t c on c.status = 'ACTIVE' and c.code = ru.vendor_code where r.delete_flag = 'N' and r.status = '9' and ru.emp_number = 'WB334479' ) order by data_from, last_update_date desc 帮我优化SQL输出,并添加便于阅读的注释
最新发布
09-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值