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

Complex Query Takes Forever - but I think it's query generation #4394

Open
jogibear9988 opened this issue Jan 26, 2024 · 4 comments · May be fixed by #4395
Open

Complex Query Takes Forever - but I think it's query generation #4394

jogibear9988 opened this issue Jan 26, 2024 · 4 comments · May be fixed by #4395
Labels
status: has-pr There is active PR for issue
Milestone

Comments

@jogibear9988
Copy link
Member

jogibear9988 commented Jan 26, 2024

Describe your issue

I've a very complex query, wich Takes forever to run (over 1 Minute. without any data in the database).
But for me it looks like the query generation is taking so long.
It needs #4339 merged to work in current linq2db

Steps to reproduce

I've created an sample - #4395

Environment details

Linq To DB version: master

Database (with version): Sqlite and MSSql

@jogibear9988
Copy link
Member Author

I now added this interceptor:

	class QueryStartedInterceptor : LinqToDB.Interceptors.CommandInterceptor
	{
		public Action? Action { get; set; }

		public override Option<DbDataReader> ExecuteReader(CommandEventData eventData, DbCommand command, CommandBehavior commandBehavior, Option<DbDataReader> result)
		{
			Action?.Invoke();
			return base.ExecuteReader(eventData, command, commandBehavior, result);
		}
	}

and messured query generation time:

			var i = new QueryStartedInterceptor();
			s.AddInterceptor(i);
			var sw = Stopwatch.StartNew();
			var sw2 = Stopwatch.StartNew();
			i.Action = () => sw.Stop();
			var res = query.Select(x => new ChannelInfoCombinedDTO() { Id = x.Id, ChannelInfo = x.ChannelInfo, Shelf1 = x.Shelf1 }).ToList();
			var gt1 = sw2.ElapsedMilliseconds;
			var t1 = sw.ElapsedMilliseconds;

			sw = Stopwatch.StartNew();
			sw2 = Stopwatch.StartNew();
			i.Action = () => sw.Stop();
			var res8 = query.Select(x => new ChannelInfoCombinedDTO() { Id = x.Id, ChannelInfo = x.ChannelInfo, Shelf1 = x.Shelf1, Shelf2 = x.Shelf2, Shelf3 = x.Shelf3, Shelf4 = x.Shelf4, Shelf5 = x.Shelf5, Shelf6 = x.Shelf6, Shelf7 = x.Shelf7, Shelf8 = x.Shelf8 }).ToList();
			var gt8 = sw2.ElapsedMilliseconds;
			var t8 = sw.ElapsedMilliseconds;

It looks like, nearly 50s are needed to generate the query (or am I wrong?)

image

@jogibear9988
Copy link
Member Author

Removeing OVERRIDETOSTRING
reduces Time for query generation to 5 seconds!

@jogibear9988
Copy link
Member Author

Should we generate a static switch instead of a compile switch?

@jogibear9988
Copy link
Member Author

jogibear9988 commented Jan 26, 2024

Okay, in release mode, it takes about 2seconds to generate the query

@viceroypenguin viceroypenguin linked a pull request Jan 27, 2024 that will close this issue
@MaceWindu MaceWindu added this to the In-progress milestone Jan 28, 2024
@MaceWindu MaceWindu added the status: has-pr There is active PR for issue label Jan 28, 2024
@MaceWindu MaceWindu modified the milestones: In-progress, 6.0.0 Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: has-pr There is active PR for issue
Development

Successfully merging a pull request may close this issue.

2 participants