Skip to content

Commit

Permalink
ready for next release
Browse files Browse the repository at this point in the history
  • Loading branch information
hyee committed Jun 14, 2022
1 parent e28bb10 commit 6fb3efc
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 103 deletions.
74 changes: 59 additions & 15 deletions lib/misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,40 @@ end

local spaces={}
local s=' \t\n\v\f\r\0'
local allspace={
'\t', --0x9
'\n', --0xa
'\x0b', --0xb
'\x0c', --0xc
'\r', --0xd
' ', --0x20
'\xa3\xa0',--
'\xc2\x85', --0x85
'\xc2\xa0', --0xa0
'\xe1\x9a\x80', --0x1680
'\xe1\xa0\x8e', --0x180e
'\xe2\x80\x80', --0x2000
'\xe2\x80\x81', --0x2001
'\xe2\x80\x82', --0x2002
'\xe2\x80\x83', --0x2003
'\xe2\x80\x84', --0x2004
'\xe2\x80\x85', --0x2005
'\xe2\x80\x86', --0x2006
'\xe2\x80\x87', --0x2007
'\xe2\x80\x88', --0x2008
'\xe2\x80\x89', --0x2009
'\xe2\x80\x8a', --0x200a
'\xe2\x80\x8b', --0x200b
'\xe2\x80\x8c', --0x200c
'\xe2\x80\x8d', --0x200d
'\xe2\x80\xa8', --0x2028
'\xe2\x80\xa9', --0x2029
'\xe2\x80\xaf', --0x202f
'\xe2\x81\x9f', --0x205f
'\xe2\x81\xa0', --0x2060
'\xe3\x80\x80', --0x3000
'\xef\xbb\xbf', --0xfeff
}
for i=1,#s do spaces[s:byte(i)]=true end
local ext_spaces={}
local function exp_pattern(sep)
Expand All @@ -110,12 +144,16 @@ local function exp_pattern(sep)
end

local function rtrim(s,sep)
local ary=exp_pattern(sep)
local ary,f=exp_pattern(sep)
if type(s)=='string' then
local len=#s
for i=len,1,-1 do
local p=s:byte(i)
if not spaces[p] and not (ary and ary[p]) then
if f then
f=nil
elseif p==160 and (s:byte(i-1)==194 or s:byte(i-1)==163) then
f=true
elseif not spaces[p] and not (ary and ary[p]) then
return i==len and s or s:sub(1,i)
elseif i==1 then
return ''
Expand All @@ -126,12 +164,16 @@ local function rtrim(s,sep)
end

local function ltrim(s,sep)
local ary=exp_pattern(sep)
local ary,f=exp_pattern(sep)
if type(s)=='string' then
local len=#s
for i=1,len do
local p=s:byte(i)
if not spaces[p] and not (ary and ary[p]) then
if f then
f=nil
elseif (p==194 or p==163) and s:byte(i-1)==160 then
f=true
elseif not spaces[p] and not (ary and ary[p]) then
return i==1 and s or s:sub(i)
elseif i==len then
return ''
Expand Down Expand Up @@ -258,19 +300,21 @@ function math.round(exact, quantum)
return (quant + (frac > 0.5 and 1 or 0))/quantum
end

function table.clone (t,depth) -- deep-copy a table
if type(t) ~= "table" or (depth or 1)<=0 then return t end
local meta = getmetatable(t)
local target = {}
for k, v in pairs(t) do
if type(v) == "table" then
target[k] = table.clone(v,(tonumber(depth) or 99)-1)
else
target[k] = v
if not table.clone then
table.clone=function(t,depth) -- deep-copy a table
if type(t) ~= "table" or (depth or 1)<=0 then return t end
local meta = getmetatable(t)
local target = {}
for k, v in pairs(t) do
if type(v) == "table" then
target[k] = table.clone(v,(tonumber(depth) or 99)-1)
else
target[k] = v
end
end
setmetatable(target, meta)
return target
end
setmetatable(target, meta)
return target
end

function table.week(typ,gc)
Expand Down
1 change: 0 additions & 1 deletion lua/alias.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ function alias.make_command(name, args, is_print)
end
target = target:gsub("%$(%d%w*)%[(.-)%]", alias.parser)
target = target:gsub("%f[%w%$%%]%$([%d%*]%w*)", alias.parser)
--target = target:gsub("%s+$", "")
target = target:gsub("[%$%%](%$[%d%*])", "%1")..is_pivot
--if env.COMMAND_SEPS.match(target)==target then target=target..env.COMMAND_SEPS[1] end
if is_print ~= false and type(alias.cmdlist[name].text) == "string" and not target:find('[\n\r]') then
Expand Down
2 changes: 1 addition & 1 deletion lua/db_core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ function db_core:call_sql_method(event_name,sql,method,...)
local res,obj=pcall(method,...)
if res==false then
self:is_connect(nil,true)
local info,internal={db=self,sql=sql,error=tostring(obj):gsub('%s+$','')}
local info,internal={db=self,sql=sql,error=tostring(obj):rtrim()}
local code=''

if obj.getErrorCode then
Expand Down
8 changes: 4 additions & 4 deletions lua/env.lua
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ function env.format_error(src,errmsg,...)
end
end
errmsg=errmsg:gsub("\n%s+at%s+.*$","")
errmsg=errmsg:gsub("^.*000%-00000%:%s*",""):gsub("%s+$","")
errmsg=errmsg:gsub("^.*000%-00000%:%s*",""):rtrim()
if src then
local name,line=src:match("([^\\/]+)%#(%d+)$")
if name then
Expand Down Expand Up @@ -639,7 +639,7 @@ function env.parse_args(cmd,rest,is_cross_line)
arg_count=_CMDS[cmd].ARGS
end

if rest then rest=rest:gsub("%s+$","") end
if rest then rest=rest:rtrim() end
if rest=="" then
rest = nil
elseif rest then
Expand Down Expand Up @@ -704,9 +704,9 @@ function env.parse_args(cmd,rest,is_cross_line)
local name=args[count]:upper()
local is_multi_cmd=char~=quote and is_cross_line==true and _CMDS[name] and _CMDS[name].MULTI
if count>=arg_count-2 or is_multi_cmd then--the last parameter
piece=rest:sub(i+1):gsub("^(%s+)",""):gsub('^"(.*)"$','%1')
piece=rest:sub(i+1):ltrim():gsub('^"(.*)"$','%1')
if terminator and piece:find(terminator_str,1,true)==1 then
piece=piece:sub(#terminator_str+1):gsub("^%s+","")
piece=piece:sub(#terminator_str+1):ltrim()
end
if is_multi_cmd and _CMDS[name].ARGS==1 then
args[count],piece=args[count]..' '..piece,''
Expand Down
4 changes: 2 additions & 2 deletions lua/grid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ function grid:wellform(col_del, row_del)
row_del = (row_del or grid.row_del):sub(1, 1)
local pivot = grid.pivot
local indx = rownum == "on" and 1 or 0
fmt = col_del:gsub("^%s+", "")
fmt = col_del:ltrim()
local format_func = grid.fmt
grid.colsize = self.colsize
if type(self.ratio_cols) == "table" and grid.pivot == 0 then
Expand Down Expand Up @@ -813,7 +813,7 @@ function grid:wellform(col_del, row_del)
del = col_del
end

if k == cols then del = del:gsub("%s+$", "") end
if k == cols then del = del:rtrim() end

if siz == 0 then
fmt = fmt .. "%s".. (k==cols and nor or '').. del
Expand Down
4 changes: 2 additions & 2 deletions lua/process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ function process:call_process(cmd,is_native)
To switch to the native CLI mode, execute '-n' or '.%s -n'.
Type 'lls' to list the files in current working dir, to change the working dir, execute 'lcd <path>'.
Type '.<cmd>' to run the root command, 'bye' to leave, or 'exit' to terminate.]]
help=help:format(self.name,self.work_dir,self.name):gsub("%s%s%s+",'\n'):gsub("^%s+","")
help=help:format(self.name,self.work_dir,self.name):gsub("%s%s%s+",'\n'):ltrim()
print(env.ansi.mask("PromptColor",help))
env.set_subsystem(self.name,self.prompt)
return
end

local command=cmd:upper():gsub("^%s+","")
local command=cmd:upper():ltrim()
if command=='BYE' then
self.enter_flag=false
return env.set_subsystem(nil)
Expand Down
4 changes: 2 additions & 2 deletions lua/ssh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function ssh:load_script(alias,filename,...)
else
txt=filename:sub(2)
end
txt=txt:gsub("\r\n","\n"):gsub("^%s+",""):gsub(self.comment,"\n",1)
txt=txt:gsub("\r\n","\n"):ltrim():gsub(self.comment,"\n",1)
local intepreter=txt:match("^#!([^\n])+")
if not intepreter then intepreter="/bin/bash" end
self:getresult(alias.."='"..txt.."'\n")
Expand All @@ -296,7 +296,7 @@ function ssh:upload_script(filename)
local txt,args,_,file,cmd=self:get_script(filename,{},false)
if not file then return end
self:check_connection()
txt=txt:gsub("\r\n","\n"):gsub("^%s+","")
txt=txt:gsub("\r\n","\n"):ltrim()
local intepreter=txt:match("^#!([^\n])+")
if not intepreter then intepreter="/bin/bash" end
cmd=file:match("[^\\/]+$")
Expand Down
4 changes: 2 additions & 2 deletions lua/subsystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ function system:call_process(cmd,is_native)
To switch to the native CLI mode, execute '-n' or '.%s -n'.
Type 'lls' to list the files in current working dir, to change the working dir, execute 'lcd <path>'.
Type '.<cmd>' to run the root command, 'bye' to leave, or 'exit' to terminate.]]
help=help:format(self.name,self.work_dir,self.name):gsub("%s%s%s+",'\n'):gsub("^%s+","")
help=help:format(self.name,self.work_dir,self.name):gsub("%s%s%s+",'\n'):ltrim()
print(env.ansi.mask("PromptColor",help))
env.set_subsystem(self.name,self.prompt)
return
end

local command=cmd:upper():gsub("^%s+","")
local command=cmd:upper():ltrim()
if command=='BYE' then
self.enter_flag=false
return env.set_subsystem(nil)
Expand Down
2 changes: 1 addition & 1 deletion oracle/dbmsoutput.lua
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ function output.getOutput(item)

local result=args.lob or args.buff
if (enabled == "on" or autotrace~="off") and result and result:match("[^\n%s]+") then
result=result:gsub("\r\n","\n"):gsub("%s+$","")
result=result:gsub("\r\n","\n"):rtrim()
if result~="" then
if autotrace~="off" and result:find('Plan hash value',1,true) then
local rows=env.grid.new()
Expand Down
114 changes: 59 additions & 55 deletions oracle/ora/actives.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@
}
&V1 : sid={''||sid},wt={wait_secs desc},ev={event},sql={sql_text},o={logon_time}
&fil1: {
default={event NOT LIKE 'Streams%' or wait_class!='Idle' or event not like 'SQL*%'}
default={NOT(wait_class='Idle' and (event like 'SQL*%' or event LIKE 'Streams%'))}
f={}
u={schemaname=nvl(upper('&0'),sys_context('userenv','current_schema'))}
i={wait_class!='Idle'}
i={wait_class!='Idle' &0}
}

&fil2: {
default={}
sql={--}
f={JOIN (select inst_id,sid from gv$session where &0) using(inst_id,sid)}
i={JOIN (select inst_id,sid from gv$session where wait_class!='Idle') using(inst_id,sid)}
u={JOIN (select inst_id,sid from gv$session where schemaname=nvl(upper('&0'),sys_context('userenv','current_schema'))) using(inst_id,sid)}
sql={AND 1=1}
f={AND &0}
i={AND &fil1}
u={AND &fil1}
}
&text: default={} sql={AND upper(sql_fulltext) like upper(q'~%&0%~')}
&ouj : default={(+)} sql={/**/}
&smen : default={0}, m={&CHECK_ACCESS_M}
&ord : default={} cpu={cpu desc nulls last,} io={preads desc nulls last,} log={lreads desc nulls last,}
&ord : default={} cpu={"CPU%" desc nulls last,} io={"Physical|Reads" desc nulls last,} log={"Logical|Reads" desc nulls last,}
@COST : 11.0={1440*(sysdate-sql_exec_start)},10.0={sql_secs/60}
@CHECK_ACCESS_OBJ: dba_objects={dba_objects},all_objects={all_objects}
@CHECK_ACCESS_PX11: {
Expand Down Expand Up @@ -154,54 +154,58 @@ BEGIN
OR (ROOT_SID =1 OR status='ACTIVE' and wait_class!='Idle')
ORDER BY r}' USING :fil2;
$IF &smen=1 $THEN
OPEN time_model FOR
SELECT r "#",
sid || ',' || serial# || ',@' || inst_id session#,
px dop,
schemaname usr,
nvl(regexp_substr(program,'\(.\S+\)'),substr(regexp_replace(program,'[@\(\-].*'),1,30)) program,
nullif(CPU,0) "CPU%",
nullif(ppct,0) "Physical|Reads%",
nullif(lpct,0) "Logical|Reads%",
nullif(preads,0) "Physical|Reads",
nullif(lreads,0) "Logical|Reads",
nullif(pga,0) "PGA|MEM",
nullif(hparses,0) "HARD|PARSE",
nullif(spares,0) "SOFT|PARSE",
nvl(a.sql_id,b.sql_id) "LAST|SQL",
SQL_ACTIVE "LAST SQL|ACTIVE",
SQL_OP_TYPE "LAST SQL|OPERATION",
SQL_MEM "LAST SQL|MEM",
TEMP "LAST SQL|TEMP",
passes "HASH JOIN|PASSES"
FROM (SELECT ROWNUM r,a.*
FROM (SELECT nvl(nvl2(a.qcsid,a.qcinst_id,b.qcinst_id),inst_id) inst_id,
coalesce(a.qcsid,b.qcsid, sid) sid,
greatest(count(1),nvl(max(degree),0)) px,
round(ratio_to_report(SUM(CPU)) over(),4) CPU,
MAX(SQL_ID) SQL_ID,
MAX(OPERATION_TYPE) KEEP(DENSE_RANK LAST ORDER BY ACTIVE_TIME) SQL_OP_TYPE,
SUM(ACTIVE_TIME) SQL_ACTIVE,
SUM(ACTUAL_MEM_USED) SQL_MEM,
SUM(TEMPSEG_SIZE) TEMP,
SUM(NUMBER_PASSES) PASSES,
SUM(PHYSICAL_READS) preads,
SUM(LOGICAL_READS) lreads,
SUM(PGA_MEMORY) pga,
SUM(HARD_PARSES) hparses,
SUM(SOFT_PARSES) spares,
round(ratio_to_report(SUM(PHYSICAL_READ_PCT)) over(),4) ppct,
round(ratio_to_report(SUM(LOGICAL_READ_PCT)) over(),4) lpct
FROM (SELECT a.*,session_id sid FROM gv$sessmetric a)
&fil2
LEFT JOIN gv$px_session a USING (inst_id, sid)
LEFT JOIN gv$sql_workarea_active b USING (inst_id, sid)
GROUP BY nvl(nvl2(a.qcsid,a.qcinst_id,b.qcinst_id),inst_id),
coalesce(a.qcsid,b.qcsid, sid)
ORDER BY &ord nvl(CPU,0) + nvl(ppct/2,0) + nvl(lpct / 15,0) DESC,pga desc,hparses desc,spares desc) a
WHERE ROWNUM <= 50) a
JOIN gv$session b USING(inst_id, sid)
ORDER BY r;
OPEN time_model FOR q'~
SELECT rownum "#",a.*
FROM (SELECT session#,
MAX(usr) usr,
MAX(program) program,
greatest(count(1),nvl(max(degree),1)) dop,
round(ratio_to_report(SUM(CPU)) over(),4) "CPU%",
round(ratio_to_report(SUM(PHYSICAL_READ_PCT)) over(),4) "Physical|Reads%",
round(ratio_to_report(SUM(LOGICAL_READ_PCT)) over(),4) "Logical|Reads%",
SUM(PHYSICAL_READS) "Physical|Reads",
SUM(LOGICAL_READS) "Logical|Reads",
SUM(PGA_MEMORY) "PGA|MEM",
SUM(HARD_PARSES) "HARD|PARSE",
SUM(SOFT_PARSES) "SOFT|PARSE",
MAX(SQL_ID) "LAST|SQL",
SUM(ACTIVE_TIME) "LAST SQL|ACTIVE",
MAX(OPERATION_TYPE) KEEP(DENSE_RANK LAST ORDER BY ACTIVE_TIME) "LAST SQL|OPERATION",
SUM(ACTUAL_MEM_USED) "LAST SQL|MEM",
SUM(TEMPSEG_SIZE) "LAST SQL|TEMP",
SUM(NUMBER_PASSES) "HASH JOIN|PASSES"
FROM TABLE(GV$(CURSOR(
SELECT /*+use_hash(m s p w)*/
coalesce(p.qcsid,w.qcsid,sid)
||',' ||nvl(p.qcserial#,s.serial#)
||',@'||nvl(nvl2(p.qcsid,p.qcinst_id,w.qcinst_id),inst_id) session#,
s.schemaname usr,
nvl(regexp_substr(s.program,'\(.\S+\)'),substr(regexp_replace(s.program,'[@\(\-].*'),1,30)) program,
nvl(w.sql_id,s.sql_id) sql_id,
w.OPERATION_TYPE,
w.ACTIVE_TIME,
w.ACTUAL_MEM_USED,
w.TEMPSEG_SIZE,
w.NUMBER_PASSES,
m.CPU,
m.PHYSICAL_READS,
m.LOGICAL_READS,
m.PGA_MEMORY,
m.HARD_PARSES,
m.SOFT_PARSES,
m.PHYSICAL_READ_PCT,
m.LOGICAL_READ_PCT,
p.degree
FROM (SELECT m.*,session_id sid FROM v$sessmetric m) m
JOIN (SELECT s.*,userenv('instance') inst_id FROM V$SESSION s) s USING (sid)
LEFT JOIN v$px_session p USING (sid)
LEFT JOIN v$sql_workarea_active w USING (sid)
WHERE inst_id=nvl('&instance',inst_id)
&fil2
))) a
GROUP BY session#
ORDER BY &ord nvl("CPU%",0) + nvl("Physical|Reads%"/2,0) + nvl("Logical|Reads%"/15,0) DESC,"PGA|MEM" desc
) a WHERE ROWNUM<=50~';
$END
:time_model:=time_model;
END;
Expand Down
2 changes: 1 addition & 1 deletion oracle/ora/gather.sql
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ BEGIN
IF lst(hv)<=1000 THEN
val := tabs(lst(hv)).argtype;
tabs(lst(hv)).argtype:=val-bitand(val,power(2,j-1))+power(2,j-1);
IF (j=1 OR val=1) AND &nopart=1 THEN
IF j=1 AND &nopart=1 THEN
tabs(lst(hv)).cardinality:=tabs(lst(hv)).cardinality+1;
tabs(lst(hv)).TABLEPARTITIONUPPER:=NULL;
tabs(lst(hv)).TABLEPARTITIONLOWER:=NULL;
Expand Down
Loading

0 comments on commit 6fb3efc

Please sign in to comment.