Stream migration commands

Open
#19,710 8 comments 0 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

Assessment

This issue has not been assessed yet.

Description

area-migrations area-perf customer-reported needs-design

When using migrationBuilder.InsertData(... to insert seed data, there is a memory leak of Microsoft.EntityFrameworkCore.Storage.RelationalCommand.

I batch insert the data in 1,000 item page (max supported).

Reproduce (insert 18,250‬ rows):

int pageSize = 1000;

var startDate = new DateTime(1990, 01, 01);
var endDate = new DateTime(2040, 12, 31);
var dateValueCount = (endDate - startDate).Days;
var dateData = new object[dateValueCount + 1, 6];

for (DateTime date = startDate; date <= endDate; date = date.AddDays(1))
{
	var dateIndex = (date - startDate).Days;
	dateData[dateIndex, 0] = date.Date;
	dateData[dateIndex, 1] = (byte)date.Day;
	dateData[dateIndex, 2] = (byte)CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
	dateData[dateIndex, 3] = (byte)date.Month;
	dateData[dateIndex, 4] = (byte)((date.Month + 2) / 3);
	dateData[dateIndex, 5] = (Int16)date.Year;
}


int currentDatePage = 0;
while ((currentDatePage * pageSize) < dateData.GetLength(0))
{
	var startIndex = currentDatePage * pageSize;
	var endIndex = dateData.GetLength(0) < startIndex + pageSize ? startIndex + dateData.GetLength(0) - startIndex : startIndex + pageSize;

	var dataPart = new object[endIndex - startIndex, 6];
	for (int i = startIndex; i < endIndex; i++)
	{
		dataPart[i - startIndex, 0] = dateData[i, 0];
		dataPart[i - startIndex, 1] = dateData[i, 1];
		dataPart[i - startIndex, 2] = dateData[i, 2];
		dataPart[i - startIndex, 3] = dateData[i, 3];
		dataPart[i - startIndex, 4] = dateData[i, 4];
		dataPart[i - startIndex, 5] = dateData[i, 5];

		migrationBuilder.InsertData(
			table: "Date",
			schema: "dim",
			columns: new string[]
			{
				"Date",
				"Day",
				"Week",
				"Month",
				"Quarter",
				"Year"
			},
			values: dataPart);
	}

	currentDatePage++;
}

Environment: Net Core 3.1, EF Core 3.1.1

Dominant language
C#
Stars
14.8k
Forks
3.4k
Avg merge
2d 5h
Merged PRs (30d)
134

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/efcore

All issues in dotnet/efcore

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.