DatabaseProcApplicationCreatedLinks
sybsystemprocssp_flushstats  14 déc. 14Defects Propagation Dependencies

1     
2     /*
3     ** Messages for "sp_flushstats" 
4     **
5     ** 17460, "Object must be in the current database."
6     ** 17461, "Object does not exist in this database."
7     */
8     
9     create or replace procedure sp_flushstats
10        @objname varchar(767) = NULL /* object name we're after */
11    as
12    
13        declare @objid int
14        declare @dbid int
15        declare @nullarg char(1)
16        declare @dummy int
17        declare @status int
18        declare @gp_enabled int
19    
20    
21        if @@trancount = 0
22        begin
23            set chained off
24        end
25    
26        set transaction isolation level 1
27    
28        set nocount on
29    
30        select @dbid = db_id()
31    
32        /*
33        ** If granular permissions is not enabled then sa_role is required in 
34        ** dbcc flushstats so we will check for it here.
35        ** If granular permissions is enabled then the permission
36        ** 'monitor qp performance' is required.  proc_role and proc_auditperm will
37        ** also do auditing if required. Both will print an error message if
38        ** required.
39        */
40    
41        select @nullarg = NULL
42        execute @status = sp_aux_checkroleperm "sa_role", "monitor qp performance",
43            @nullarg, @gp_enabled output
44        /* For Auditing */
45        if (@gp_enabled = 0)
46        begin
47            select @dummy = proc_role("sa_role")
48        end
49        else
50        begin
51            select @dummy = proc_auditperm("monitor qp performance", @status)
52        end
53        if (@status != 0)
54        begin
55            return (1)
56        end
57    
58        if @objname is NULL
59        begin
60    
61            declare cs cursor for
62            select O.id
63            from sysobjects O
64            where O.sysstat & 15 in (1, 3)
65            open cs
66            fetch cs into @objid
67    
68            set switch on print_output_to_client with no_info
69    
70            while @@sqlstatus = 0
71            begin
72                dbcc flushstats(@dbid, @objid)
73                fetch cs into @objid
74            end
75    
76            set switch off print_output_to_client with no_info
77    
78            close cs
79            deallocate cursor cs
80            return (0)
81        end
82    
83        /*
84        **  Make sure the @objname is local to the current database.
85        */
86        if @objname like "%.%.%" and
87            substring(@objname, 1, charindex(".", @objname) - 1) != db_name()
88        begin
89            /* 17460, "Object must be in the current database." */
90            raiserror 17460
91            return (1)
92        end
93    
94        /*
95        **  Now check to see if the @objname is in sysobjects.
96        */
97        select @objid = object_id(@objname)
98    
99        if not exists (select *
100               from sysobjects
101               where id = @objid
102                   and sysstat & 15 in (1, 3))
103       begin
104           /* 17461, "No table as specified exists in this database." */
105           raiserror 17461
106           return (1)
107       end
108   
109   
110       set switch on print_output_to_client with no_info
111   
112       dbcc flushstats(@dbid, @objid)
113   
114       set switch off print_output_to_client with no_info
115   
116       return (0)
117   


exec sp_procxmode 'sp_flushstats', 'AnyMode'
go

Grant Execute on sp_flushstats to public
go
DEFECTS
 CUNU 3 Cursor not updated: cursor should contain 'for read only' clause cs 62
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 62
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 101
 MGTP 3 Grant to public sybsystemprocs..sp_flushstats  
 MGTP 3 Grant to public sybsystemprocs..sysobjects  
 MUCO 3 Useless Code Useless Brackets 45
 MUCO 3 Useless Code Useless Brackets 53
 MUCO 3 Useless Code Useless Brackets 55
 MUCO 3 Useless Code Useless Brackets 80
 MUCO 3 Useless Code Useless Brackets 91
 MUCO 3 Useless Code Useless Brackets 106
 MUCO 3 Useless Code Useless Brackets 116
 QISO 3 Set isolation level 26
 VNRD 3 Variable is not read @dummy 51
 CUPD 2 Updatable Cursor Marker (updatable by default) 62
 MSUB 2 Subquery Marker 99
 MTR1 2 Metrics: Comments Ratio Comments: 29% 9
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 7 = 10dec - 5exi + 2 9
 MTR3 2 Metrics: Query Complexity Complexity: 55 9

DEPENDENCIES
PROCS AND TABLES USED
reads table sybsystemprocs..sysobjects  
calls proc sybsystemprocs..sp_aux_checkroleperm  
   reads table master..syscurconfigs (1)  
   reads table master..sysconfigures (1)