Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MS SQL Optimization #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 27 additions & 35 deletions src/main/java/com/alfresco/support/alfrescodb/DAOMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import com.alfresco.support.alfrescodb.beans.AppliedPatchesBean;
import com.alfresco.support.alfrescodb.beans.ArchivedNodesBean;
import com.alfresco.support.alfrescodb.beans.ContentModelBean;
import com.alfresco.support.alfrescodb.beans.DbMSSQLBean;
import com.alfresco.support.alfrescodb.beans.DbMsSQLIndexBean;
import com.alfresco.support.alfrescodb.beans.DbMsSQLTableBean;
import com.alfresco.support.alfrescodb.beans.DbMySQLBean;
import com.alfresco.support.alfrescodb.beans.DbOracleBean;
import com.alfresco.support.alfrescodb.beans.DbPostgresBean;
Expand Down Expand Up @@ -75,37 +76,25 @@ public interface DAOMapper {
"group by u.segment_name, i.table_name")
List<DbOracleBean> findIndexesInfoOracle();

// MS SQL Queries
@Select("SELECT \n" +
" s.Name as SchemaName, t.NAME AS TableName, p.rows AS RowCounts,\n" +
" (SUM(a.total_pages) * 8 * 1024) AS TotalSpace, \n" +
" (SUM(a.used_pages) * 8 * 1024) AS UsedSpace, \n" +
" ((SUM(a.total_pages) - SUM(a.used_pages)) * 8 *1024 ) AS UnusedSpace \n" +
"FROM sys.tables t \n" +
"INNER JOIN sys.schemas s ON s.schema_id = t.schema_id \n" +
"INNER JOIN sys.indexes i ON t.OBJECT_ID = i.object_id \n" +
"INNER JOIN sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id \n" +
"INNER JOIN sys.allocation_units a ON p.partition_id = a.container_id \n" +
"WHERE \n" +
" t.NAME NOT LIKE 'dt%' -- filter out system tables for diagramming \n" +
" AND t.is_ms_shipped = 0 \n" +
" AND i.OBJECT_ID > 255 \n" +
"GROUP BY \n" +
" t.Name, s.Name, p.Rows")
List<DbMSSQLBean> findTablesInfoMSSql();

@Select("SELECT\n" +
" s.Name as SchemaName, OBJECT_NAME(i.OBJECT_ID) AS TableName,\n" +
" i.name AS IndexName,\n" +
" i.index_id AS IndexID,\n" +
" (8 * SUM(a.used_pages) * 1024) AS 'IndexSize'\n" +
"FROM sys.indexes AS i\n" +
"JOIN sys.partitions AS p ON p.OBJECT_ID = i.OBJECT_ID AND p.index_id = i.index_id \n" +
"JOIN sys.allocation_units AS a ON a.container_id = p.partition_id \n" +
"JOIN sys.tables t ON t.OBJECT_ID = i.object_id \n" +
"JOIN sys.schemas s ON s.schema_id = t.schema_id \n" +
"GROUP BY i.OBJECT_ID,i.index_id,i.name")
List<DbMSSQLBean> findIndexesInfoMSSql();
// MS SQL Queries - table stats are from first index, usually the PK
@Select("SELECT OBJECT_NAME(t.object_id) AS tableName, SUM(u.total_pages) * 8 * 1024 AS totalReservedBytes, " +
"SUM(u.used_pages) * 8 * 1024 AS usedSpaceBytes, MAX(p.rows) AS rowsCount, STATS_DATE(p.object_id,s.stats_id) AS statisticsUpdateDate " +
"FROM sys.allocation_units AS u " +
"JOIN sys.partitions AS p ON u.container_id = p.hobt_id " +
"JOIN sys.tables AS t ON p.object_id = t.object_id " +
"JOIN sys.stats AS s ON p.object_id = s.object_id and s.stats_id = 1 " +
"GROUP BY OBJECT_NAME(t.object_id), STATS_DATE(p.object_id,s.stats_id) ")
List<DbMsSQLTableBean> findTablesInfoMSSql();

@Select("SELECT OBJECT_NAME(i.OBJECT_ID) AS tableName, " +
"i.name AS indexName, i.index_id AS indexID, 8 * 1024 * SUM(a.used_pages) AS indexSizeBytes, " +
"STATS_DATE(p.object_id,i.index_id) AS statisticsUpdateDate " +
"FROM sys.indexes i " +
"JOIN sys.partitions p ON p.OBJECT_ID = i.OBJECT_ID AND p.index_id = i.index_id " +
"JOIN sys.allocation_units a ON a.container_id = p.partition_id " +
"GROUP BY i.OBJECT_ID,i.index_id,i.[name],STATS_DATE(p.object_id,i.index_id) " +
"ORDER BY OBJECT_NAME(i.OBJECT_ID),i.index_id ")
List<DbMsSQLIndexBean> findIndexesInfoMSSql();

/*
* Large Folders
Expand Down Expand Up @@ -210,22 +199,22 @@ public interface DAOMapper {
/*
* Activities Feed
*/
@Select("select count(*) as count, CAST(post_date AS DATE) postDate, site_network as siteNetwork, activity_type as activityType "
@Select("select count(*) as count, TRIM(cast(CAST(post_date AS date) as char)) postDate, site_network as siteNetwork, activity_type as activityType "
+
"from alf_activity_feed " +
"where feed_user_id = post_user_id " +
"group by CAST(post_date AS DATE), site_network, activity_type ")
List<ActivitiesFeedByTypeBean> listActivitiesByActivityType();

@Select("select count(*) as count, CAST(post_date AS DATE) postDate, site_network as siteNetwork, feed_user_id as feedUserId "
@Select("select count(*) as count, TRIM(cast(CAST(post_date AS date) as char)) postDate, site_network as siteNetwork, feed_user_id as feedUserId "
+
"from alf_activity_feed " +
"where feed_user_id != '@@NULL@@' " +
"and feed_user_id = post_user_id " +
"group by CAST(post_date AS DATE), site_network, feed_user_id ")
List<ActivitiesFeedByUserBean> listActivitiesByUser();

@Select("select count(*) as count, CAST(post_date AS DATE) postDate, site_network as siteNetwork, app_tool as appTool "
@Select("select count(*) as count, TRIM(cast(CAST(post_date AS date) as char)) postDate, site_network as siteNetwork, app_tool as appTool "
+
"from alf_activity_feed " +
"where feed_user_id != '@@NULL@@' " +
Expand Down Expand Up @@ -269,6 +258,9 @@ public interface DAOMapper {
@Select("select count(*) as count from alf_auth_status where authorized is TRUE")
String countAuthorizedUsers();

@Select("select count(*) as count from alf_auth_status where authorized = 1")
String countAuthorizedUsersMicrosoft();

@Select("select count(*) as count from alf_node_properties where qname_id in (select id from alf_qname where local_name = 'authorityName')")
String countGroups();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import java.io.Serializable;
import java.math.BigInteger;
import java.sql.Date;

public class ActivitiesFeedByApplication implements Serializable {
private BigInteger count;
private Date postDate;
private String postDate;
private String siteNetwork;
private String appTool;

Expand All @@ -16,10 +15,10 @@ public BigInteger getCount() {
public void setCount(BigInteger count) {
this.count = count;
}
public Date getPostDate() {
public String getPostDate() {
return postDate;
}
public void setPostDate(Date postDate) {
public void setPostDate(String postDate) {
this.postDate = postDate;
}
public String getSiteNetwork() {
Expand All @@ -34,5 +33,4 @@ public String getAppTool() {
public void setAppTool(String appTool) {
this.appTool = appTool;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import java.io.Serializable;
import java.math.BigInteger;
import java.sql.Date;

public class ActivitiesFeedByTypeBean implements Serializable {
private BigInteger count;
private Date postDate;
private String postDate;
private String siteNetwork;
private String activityType;

Expand All @@ -16,10 +15,10 @@ public BigInteger getCount() {
public void setCount(BigInteger count) {
this.count = count;
}
public Date getPostDate() {
public String getPostDate() {
return postDate;
}
public void setPostDate(Date postDate) {
public void setPostDate(String postDate) {
this.postDate = postDate;
}
public String getSiteNetwork() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import java.io.Serializable;
import java.math.BigInteger;
import java.sql.Date;

public class ActivitiesFeedByUserBean implements Serializable {
private BigInteger count;
private Date postDate;
private String postDate;
private String siteNetwork;
private String feedUserId;

Expand All @@ -16,10 +15,10 @@ public BigInteger getCount() {
public void setCount(BigInteger occurrences) {
this.count = occurrences;
}
public Date getPostDate() {
public String getPostDate() {
return postDate;
}
public void setPostDate(Date post_date) {
public void setPostDate(String post_date) {
this.postDate = post_date;
}
public String getSiteNetwork() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.alfresco.support.alfrescodb.beans;

import java.io.Serializable;
import java.math.BigInteger;
import java.sql.Timestamp;

import com.fasterxml.jackson.annotation.JsonFormat;

public class DbMsSQLIndexBean implements Serializable {
private String tableName;
private String indexName;
private Integer indexID;
private BigInteger indexSizeBytes;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssXXX")
private Timestamp statisticsUpdateDate;

public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public String getIndexName() {
return indexName;
}
public void setIndexName(String indexName) {
this.indexName = indexName;
}
public Integer getIndexID() {
return indexID;
}
public void setIndexID(Integer indexID) {
this.indexID = indexID;
}
public BigInteger getIndexSizeBytes() {
return indexSizeBytes;
}
public void setIndexSizeBytes(BigInteger indexSizeBytes) {
this.indexSizeBytes = indexSizeBytes;
}
public Timestamp getStatisticsUpdateDate() {
return statisticsUpdateDate;
}
public void setStatisticsUpdateDate(Timestamp statisticsUpdateDate) {
this.statisticsUpdateDate = statisticsUpdateDate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.alfresco.support.alfrescodb.beans;

import java.io.Serializable;
import java.math.BigInteger;
import java.sql.Timestamp;

import com.fasterxml.jackson.annotation.JsonFormat;

public class DbMsSQLTableBean implements Serializable {
private String tableName;
private BigInteger totalReservedBytes;
private BigInteger usedSpaceBytes;
private BigInteger rowsCount;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssXXX")
private Timestamp statisticsUpdateDate;

public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public BigInteger getTotalReservedBytes() {
return totalReservedBytes;
}
public void setTotalReservedBytes(BigInteger totalReservedBytes) {
this.totalReservedBytes = totalReservedBytes;
}
public BigInteger getUsedSpaceBytes() {
return usedSpaceBytes;
}
public void setUsedSpaceBytes(BigInteger usedSpaceBytes) {
this.usedSpaceBytes = usedSpaceBytes;
}
public BigInteger getRowsCount() {
return rowsCount;
}
public void setRowsCount(BigInteger rowsCount) {
this.rowsCount = rowsCount;
}
public Timestamp getStatisticsUpdateDate() {
return statisticsUpdateDate;
}
public void setStatisticsUpdateDate(Timestamp statisticsUpdateDate) {
this.statisticsUpdateDate = statisticsUpdateDate;
}
}
Loading