Skip to content

Commit

Permalink
Merge pull request dotnet/corefx#34393 from Wraith2/sqlperf-metadata
Browse files Browse the repository at this point in the history
SqlClient reduce metadata size

Commit migrated from dotnet/corefx@f0f5141
  • Loading branch information
AfsanehR-zz authored Feb 13, 2019
2 parents 1ba3ae7 + 55a0e53 commit 0560bcc
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet i

// Check for excluded types
if ((metadata.type == SqlDbType.Timestamp)
|| ((metadata.isIdentity) && !IsCopyOption(SqlBulkCopyOptions.KeepIdentity)))
|| ((metadata.IsIdentity) && !IsCopyOption(SqlBulkCopyOptions.KeepIdentity)))
{
// Remove metadata for excluded columns
metaDataSet[i] = null;
Expand Down Expand Up @@ -1386,7 +1386,7 @@ private object ConvertValue(object value, _SqlMetaData metadata, bool isNull, re

if (isNull)
{
if (!metadata.isNullable)
if (!metadata.IsNullable)
{
throw SQL.BulkLoadBulkLoadNotAllowDBNull(metadata.column);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1615,16 +1615,16 @@ private Assembly ResolveTypeAssembly(AssemblyName asmRef, bool throwOnError)

internal void CheckGetExtendedUDTInfo(SqlMetaDataPriv metaData, bool fThrow)
{
if (metaData.udtType == null)
if (metaData.udt?.Type == null)
{ // If null, we have not obtained extended info.
Debug.Assert(!string.IsNullOrEmpty(metaData.udtAssemblyQualifiedName), "Unexpected state on GetUDTInfo");
Debug.Assert(!string.IsNullOrEmpty(metaData.udt?.AssemblyQualifiedName), "Unexpected state on GetUDTInfo");
// Parameter throwOnError determines whether exception from Assembly.Load is thrown.
metaData.udtType =
Type.GetType(typeName: metaData.udtAssemblyQualifiedName, assemblyResolver: asmRef => ResolveTypeAssembly(asmRef, fThrow), typeResolver: null, throwOnError: fThrow);
metaData.udt.Type =
Type.GetType(typeName: metaData.udt.AssemblyQualifiedName, assemblyResolver: asmRef => ResolveTypeAssembly(asmRef, fThrow), typeResolver: null, throwOnError: fThrow);

if (fThrow && metaData.udtType == null)
if (fThrow && metaData.udt.Type == null)
{
throw SQL.UDTUnexpectedResult(metaData.udtAssemblyQualifiedName);
throw SQL.UDTUnexpectedResult(metaData.udt.AssemblyQualifiedName);
}
}
}
Expand All @@ -1641,7 +1641,7 @@ internal object GetUdtValue(object value, SqlMetaDataPriv metaData, bool returnD
// Since the serializer doesn't handle nulls...
if (ADP.IsNull(value))
{
Type t = metaData.udtType;
Type t = metaData.udt?.Type;
Debug.Assert(t != null, "Unexpected null of udtType on GetUdtValue!");
o = t.InvokeMember("Null", BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.Static, null, null, Array.Empty<object>(), CultureInfo.InvariantCulture);
Debug.Assert(o != null);
Expand All @@ -1652,7 +1652,7 @@ internal object GetUdtValue(object value, SqlMetaDataPriv metaData, bool returnD

MemoryStream stm = new MemoryStream((byte[])value);

o = SerializationHelperSql9.Deserialize(stm, metaData.udtType);
o = SerializationHelperSql9.Deserialize(stm, metaData.udt?.Type);

Debug.Assert(o != null, "object could NOT be created");
return o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ internal virtual SmiExtendedMetaData[] GetInternalSmiMetaData()
{
_SqlMetaData colMetaData = metaData[index];

if (!colMetaData.isHidden)
if (!colMetaData.IsHidden)
{
SqlCollation collation = colMetaData.collation;

Expand All @@ -278,17 +278,17 @@ internal virtual SmiExtendedMetaData[] GetInternalSmiMetaData()

if (SqlDbType.Xml == colMetaData.type)
{
typeSpecificNamePart1 = colMetaData.xmlSchemaCollectionDatabase;
typeSpecificNamePart2 = colMetaData.xmlSchemaCollectionOwningSchema;
typeSpecificNamePart3 = colMetaData.xmlSchemaCollectionName;
typeSpecificNamePart1 = colMetaData.xmlSchemaCollection?.Database;
typeSpecificNamePart2 = colMetaData.xmlSchemaCollection?.OwningSchema;
typeSpecificNamePart3 = colMetaData.xmlSchemaCollection?.Name;
}
else if (SqlDbType.Udt == colMetaData.type)
{
Connection.CheckGetExtendedUDTInfo(colMetaData, true); // Ensure that colMetaData.udtType is set

typeSpecificNamePart1 = colMetaData.udtDatabaseName;
typeSpecificNamePart2 = colMetaData.udtSchemaName;
typeSpecificNamePart3 = colMetaData.udtTypeName;
typeSpecificNamePart1 = colMetaData.udt?.DatabaseName;
typeSpecificNamePart2 = colMetaData.udt?.SchemaName;
typeSpecificNamePart3 = colMetaData.udt?.TypeName;
}

int length = colMetaData.length;
Expand All @@ -310,26 +310,27 @@ internal virtual SmiExtendedMetaData[] GetInternalSmiMetaData()
colMetaData.scale,
(null != collation) ? collation.LCID : _defaultLCID,
(null != collation) ? collation.SqlCompareOptions : SqlCompareOptions.None,
colMetaData.udtType,
colMetaData.udt?.Type,
false, // isMultiValued
null, // fieldmetadata
null, // extended properties
colMetaData.column,
typeSpecificNamePart1,
typeSpecificNamePart2,
typeSpecificNamePart3,
colMetaData.isNullable,
colMetaData.IsNullable,
colMetaData.serverName,
colMetaData.catalogName,
colMetaData.schemaName,
colMetaData.tableName,
colMetaData.baseColumn,
colMetaData.isKey,
colMetaData.isIdentity,
0 == colMetaData.updatability,
colMetaData.isExpression,
colMetaData.isDifferentName,
colMetaData.isHidden);
colMetaData.IsKey,
colMetaData.IsIdentity,
colMetaData.IsReadOnly,
colMetaData.IsExpression,
colMetaData.IsDifferentName,
colMetaData.IsHidden
);
}
}
}
Expand Down Expand Up @@ -573,14 +574,14 @@ internal DataTable BuildSchemaTable()
if (col.type == SqlDbType.Udt)
{ // Additional metadata for UDTs.
Debug.Assert(Connection.IsKatmaiOrNewer, "Invalid Column type received from the server");
schemaRow[udtAssemblyQualifiedName] = col.udtAssemblyQualifiedName;
schemaRow[udtAssemblyQualifiedName] = col.udt?.AssemblyQualifiedName;
}
else if (col.type == SqlDbType.Xml)
{ // Additional metadata for Xml.
Debug.Assert(Connection.IsKatmaiOrNewer, "Invalid DataType (Xml) for the column");
schemaRow[xmlSchemaCollectionDatabase] = col.xmlSchemaCollectionDatabase;
schemaRow[xmlSchemaCollectionOwningSchema] = col.xmlSchemaCollectionOwningSchema;
schemaRow[xmlSchemaCollectionName] = col.xmlSchemaCollectionName;
schemaRow[xmlSchemaCollectionDatabase] = col.xmlSchemaCollection?.Database;
schemaRow[xmlSchemaCollectionOwningSchema] = col.xmlSchemaCollection?.OwningSchema;
schemaRow[xmlSchemaCollectionName] = col.xmlSchemaCollection?.Name;
}
}
else
Expand Down Expand Up @@ -613,19 +614,19 @@ internal DataTable BuildSchemaTable()
schemaRow[scale] = col.metaType.Scale;
}

schemaRow[allowDBNull] = col.isNullable;
schemaRow[allowDBNull] = col.IsNullable;

// If no ColInfo token received, do not set value, leave as null.
if (_browseModeInfoConsumed)
{
schemaRow[isAliased] = col.isDifferentName;
schemaRow[isKey] = col.isKey;
schemaRow[isHidden] = col.isHidden;
schemaRow[isExpression] = col.isExpression;
schemaRow[isAliased] = col.IsDifferentName;
schemaRow[isKey] = col.IsKey;
schemaRow[isHidden] = col.IsHidden;
schemaRow[isExpression] = col.IsExpression;
}

schemaRow[isIdentity] = col.isIdentity;
schemaRow[isAutoIncrement] = col.isIdentity;
schemaRow[isIdentity] = col.IsIdentity;
schemaRow[isAutoIncrement] = col.IsIdentity;

schemaRow[isLong] = col.metaType.IsLong;

Expand All @@ -641,8 +642,8 @@ internal DataTable BuildSchemaTable()
schemaRow[isRowVersion] = false;
}

schemaRow[isReadOnly] = (0 == col.updatability);
schemaRow[isColumnSet] = col.isColumnSet;
schemaRow[isReadOnly] = col.IsReadOnly;
schemaRow[isColumnSet] = col.IsColumnSet;

if (!string.IsNullOrEmpty(col.serverName))
{
Expand Down Expand Up @@ -1095,7 +1096,7 @@ private bool TryConsumeMetaData()
{
indexMap[i] = _metaData.visibleColumns;

if (!(_metaData[i].isHidden))
if (!(_metaData[i].IsHidden))
{
_metaData.visibleColumns++;
}
Expand Down Expand Up @@ -1148,7 +1149,7 @@ private string GetDataTypeNameInternal(_SqlMetaData metaData)

if (metaData.type == SqlDbType.Udt)
{
dataTypeName = metaData.udtDatabaseName + "." + metaData.udtSchemaName + "." + metaData.udtTypeName;
dataTypeName = metaData.udt?.DatabaseName + "." + metaData.udt?.SchemaName + "." + metaData.udt?.TypeName;
}
else
{ // For all other types, including Xml - use data in MetaType.
Expand Down Expand Up @@ -1221,7 +1222,7 @@ private Type GetFieldTypeInternal(_SqlMetaData metaData)
if (metaData.type == SqlDbType.Udt)
{
Connection.CheckGetExtendedUDTInfo(metaData, false);
fieldType = metaData.udtType;
fieldType = metaData.udt?.Type;
}
else
{ // For all other types, including Xml - use data in MetaType.
Expand Down Expand Up @@ -1301,7 +1302,7 @@ private Type GetProviderSpecificFieldTypeInternal(_SqlMetaData metaData)
if (metaData.type == SqlDbType.Udt)
{
Connection.CheckGetExtendedUDTInfo(metaData, false);
providerSpecificFieldType = metaData.udtType;
providerSpecificFieldType = metaData.udt?.Type;
}
else
{
Expand Down Expand Up @@ -4968,10 +4969,10 @@ private ReadOnlyCollection<DbColumn> BuildColumnSchema()

if (_browseModeInfoConsumed)
{
dbColumn.SqlIsAliased = col.isDifferentName;
dbColumn.SqlIsKey = col.isKey;
dbColumn.SqlIsHidden = col.isHidden;
dbColumn.SqlIsExpression = col.isExpression;
dbColumn.SqlIsAliased = col.IsDifferentName;
dbColumn.SqlIsKey = col.IsKey;
dbColumn.SqlIsHidden = col.IsHidden;
dbColumn.SqlIsExpression = col.IsExpression;
}

dbColumn.SqlDataType = GetFieldTypeInternal(col);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal SqlDbColumn(_SqlMetaData md)

private void Populate()
{
AllowDBNull = _metadata.isNullable;
AllowDBNull = _metadata.IsNullable;
BaseCatalogName = _metadata.catalogName;
BaseColumnName = _metadata.baseColumn;
BaseSchemaName = _metadata.schemaName;
Expand All @@ -28,8 +28,8 @@ private void Populate()
ColumnName = _metadata.column;
ColumnOrdinal = _metadata.ordinal;
ColumnSize = (_metadata.metaType.IsSizeInCharacters && (_metadata.length != 0x7fffffff)) ? (_metadata.length / 2) : _metadata.length;
IsAutoIncrement = _metadata.isIdentity;
IsIdentity = _metadata.isIdentity;
IsAutoIncrement = _metadata.IsIdentity;
IsIdentity = _metadata.IsIdentity;
IsLong = _metadata.metaType.IsLong;

if (SqlDbType.Timestamp == _metadata.type)
Expand All @@ -50,9 +50,9 @@ private void Populate()
NumericPrecision = _metadata.metaType.Precision;
}

IsReadOnly = (0 == _metadata.updatability);
IsReadOnly = _metadata.IsReadOnly;

UdtAssemblyQualifiedName = _metadata.udtAssemblyQualifiedName;
UdtAssemblyQualifiedName = _metadata.udt?.AssemblyQualifiedName;

}

Expand Down
Loading

0 comments on commit 0560bcc

Please sign in to comment.