Skip to content
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
19 changes: 13 additions & 6 deletions Project/Sources/Classes/form_Explorer.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,31 @@ Function RefreshIndexedFieldInfo()


Function PerformIndexAnalysis()
var $field_detail : Object
var $indexUsageRatio : Real
var $field_detail; $fieldStatistics : Object
var $numberOfRecordsInTable : Integer
For each ($field_detail; This:C1470._form.filteredIndexedFieldList)
$numberOfRecordsInTable:=Records in table:C83(Table:C252($field_detail.tableNumber)->)
If ($numberOfRecordsInTable=0)
$field_detail.index_analysis_notes:="n/a - Table is empty"
Else
$indexUsageRatio:=Structure_GetFieldIndexRatio($field_detail.tableNumber; $field_detail.fieldNumber)*100
$fieldStatistics:={}
Structure_GetFieldIndexRatio($field_detail.tableNumber; $field_detail.fieldNumber; $fieldStatistics)
$fieldStatistics.indexUsageRatio:=$fieldStatistics.indexUsageRatio*100
If ($fieldStatistics.numberOfRecords>0)
$field_detail.numberOfRecords:=$fieldStatistics.numberOfRecords
End if
If ($fieldStatistics.distinctValues>0)
$field_detail.distinctValues:=$fieldStatistics.distinctValues
End if
Case of
: ($indexUsageRatio>=100)
: ($fieldStatistics.indexUsageRatio>=100)
$field_detail.index_analysis_notes:="ALL values are unique"

: ($indexUsageRatio<1)
: ($fieldStatistics.indexUsageRatio<1)
$field_detail.index_analysis_notes:="Less than 1% of the values are unique"

Else
$field_detail.index_analysis_notes:=String:C10($indexUsageRatio; "#0.000")+"% of the values are unique"
$field_detail.index_analysis_notes:=String:C10($fieldStatistics.indexUsageRatio; "#0.000")+"% of the values are unique"
End case
End if
End for each
Expand Down
42 changes: 39 additions & 3 deletions Project/Sources/Forms/Explorer_d/form.4DForm
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@
"dataSource": "Form:C1466.filteredIndexedFieldList",
"metaSource": "This:C1470.meta",
"selectionMode": "none",
"scrollbarHorizontal": "hidden",
"scrollbarHorizontal": "automatic",
"alternateFill": "#EEEEEE",
"events": [
"onClick",
Expand All @@ -1458,7 +1458,7 @@
{
"name": "name1",
"dataSource": "This:C1470.name",
"width": 320,
"width": 280,
"minWidth": 10,
"maxWidth": 32000,
"resizable": false,
Expand Down Expand Up @@ -1571,10 +1571,46 @@
"textAlign": "center",
"alternateFill": "automaticAlternate"
},
{
"header": {
"name": "Header30",
"text": "Records",
"textAlign": "left",
"fontWeight": "bold"
},
"name": "Column25",
"width": 100,
"dataSource": "This:C1470.numberOfRecords",
"dataSourceTypeHint": "number",
"textAlign": "left",
"numberFormat": "###,###,###,###,###,###,###",
"footer": {
"name": "Footer33"
},
"alternateFill": "automaticAlternate"
},
{
"header": {
"name": "Header31",
"text": "Distinct\\Values",
"textAlign": "left",
"fontWeight": "bold"
},
"name": "Column26",
"numberFormat": "###,###,###,###,###,###,###",
"dataSourceTypeHint": "number",
"textAlign": "left",
"width": 75,
"footer": {
"name": "Footer34"
},
"dataSource": "This:C1470.distinctValues",
"alternateFill": "automaticAlternate"
},
{
"name": "Column24",
"dataSource": "This:C1470.index_analysis_notes",
"width": 204,
"width": 200,
"minWidth": 10,
"maxWidth": 32000,
"stroke": "automatic",
Expand Down
7 changes: 5 additions & 2 deletions Project/Sources/Methods/Compiler_Methods.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -906,9 +906,9 @@ C_LONGINT:C283(Structure_GetFieldIndexType; $1)
C_LONGINT:C283(Structure_GetFieldIndexType; $2)

//Structure_GetFieldIndexRatio
C_REAL:C285(Structure_GetFieldIndexRatio; $0)
C_LONGINT:C283(Structure_GetFieldIndexRatio; $1)
C_LONGINT:C283(Structure_GetFieldIndexRatio; $2)
C_OBJECT:C1216(Structure_GetFieldIndexRatio; $3)

//Digest_GetForMethodText
C_TEXT:C284(Digest_GetForMethodText; $0)
Expand Down Expand Up @@ -1391,4 +1391,7 @@ C_BOOLEAN:C305(XML__XPathNewSyntax; $0)

//UTL_lowerCamelCase
C_TEXT:C284(UTL_lowerCamelCase; $0)
C_TEXT:C284(UTL_lowerCamelCase; $1)
C_TEXT:C284(UTL_lowerCamelCase; $1)

//Structure_GetFieldIndexRatio
C_OBJECT:C1216(Structure_GetFieldIndexRatio; $3)
34 changes: 16 additions & 18 deletions Project/Sources/Methods/Structure_GetFieldIndexRatio.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,66 +6,64 @@
// Returns the uniqueness ratio for the specified field.
// Value range between 1.00 (100% unique) to 0 (1 value for every record).
//
#DECLARE($tableNo : Integer; $fieldNo : Integer)->$indexUsageRatio : Real
#DECLARE($tableNo : Integer; $fieldNo : Integer; $fieldStatistics : Object)
// ----------------------------------------------------
ASSERT:C1129(Count parameters:C259=2)
$indexUsageRatio:=1 // Default to fully unique
ASSERT:C1129(Count parameters:C259=3)
$fieldStatistics.indexUsageRatio:=1 // Default to fully unique

OnErr_Install_Handler("OnErr_GENERIC")

If (Is table number valid:C999($tableNo))
If (Is field number valid:C1000($tableNo; $fieldNo))

C_LONGINT:C283($fieldtype; $fieldLength)
C_BOOLEAN:C305($indexed; $unique)
var $fieldtype; $fieldLength : Integer
var $indexed; $unique : Boolean
GET FIELD PROPERTIES:C258($tableNo; $fieldNo; $fieldtype; $fieldLength; $indexed; $unique)

If ($indexed)
C_LONGINT:C283($numberOfRecordsInTable; $numberOfRecordsHaveDistinctVals)
$numberOfRecordsInTable:=Records in table:C83(Table:C252($tableNo)->)
$fieldStatistics.numberOfRecords:=Records in table:C83(Table:C252($tableNo)->)
ALL RECORDS:C47(Table:C252($tableNo)->)

If ($numberOfRecordsInTable>0)
If ($fieldStatistics.numberOfRecords>0)
Case of
: ($unique)
$numberOfRecordsHaveDistinctVals:=$numberOfRecordsInTable
$fieldStatistics.distinctValues:=$fieldStatistics.numberOfRecords

: (($fieldtype=Is alpha field:K8:1) | ($fieldtype=Is text:K8:3))
ARRAY TEXT:C222($aText; 0)
DISTINCT VALUES:C339(Field:C253($tableNo; $fieldNo)->; $aText)
$numberOfRecordsHaveDistinctVals:=Size of array:C274($aText)
$fieldStatistics.distinctValues:=Size of array:C274($aText)
ARRAY TEXT:C222($aText; 0)

: (($fieldtype=Is integer:K8:5) | ($fieldtype=Is longint:K8:6) | ($fieldtype=Is time:K8:8))
ARRAY LONGINT:C221($aiLongInt; 0)
DISTINCT VALUES:C339(Field:C253($tableNo; $fieldNo)->; $aiLongInt)
$numberOfRecordsHaveDistinctVals:=Size of array:C274($aiLongInt)
$fieldStatistics.distinctValues:=Size of array:C274($aiLongInt)
ARRAY LONGINT:C221($aiLongInt; 0)

: (($fieldtype=Is real:K8:4) | ($fieldtype=_o_Is float:K8:26))
ARRAY REAL:C219($arReals; 0)
DISTINCT VALUES:C339(Field:C253($tableNo; $fieldNo)->; $arReals)
$numberOfRecordsHaveDistinctVals:=Size of array:C274($arReals)
$fieldStatistics.distinctValues:=Size of array:C274($arReals)
ARRAY REAL:C219($arReals; 0)

: (($fieldtype=Is date:K8:7))
ARRAY DATE:C224($addates; 0)
DISTINCT VALUES:C339(Field:C253($tableNo; $fieldNo)->; $addates)
$numberOfRecordsHaveDistinctVals:=Size of array:C274($addates)
$fieldStatistics.distinctValues:=Size of array:C274($addates)
ARRAY DATE:C224($addates; 0)

Else
$numberOfRecordsHaveDistinctVals:=$numberOfRecordsInTable
$fieldStatistics.distinctValues:=$fieldStatistics.numberOfRecords
End case
REDUCE SELECTION:C351(Table:C252($tableNo)->; 0)

$indexUsageRatio:=$numberOfRecordsHaveDistinctVals/$numberOfRecordsInTable
$fieldStatistics.indexUsageRatio:=$fieldStatistics.distinctValues/$fieldStatistics.numberOfRecords
$fieldStatistics.distinctValues:=$fieldStatistics.distinctValues
End if

Else
$indexUsageRatio:=-1 // no index
$fieldStatistics.indexUsageRatio:=-1
End if

End if
End if

Expand Down