2014年10月

Execution sequence of IN and JOIN in MySQL

I have a SQL query which looks like the following.



SELECT A.a, count(B.id)
FROM TableA A inner join TableA B on A.referId = B.id
WHERE A.id in (123,2424,232...)
GROUP BY A.id


While executing this query




The rows are filtered using where clause first and then join is performed or
First join is performed, then the rows are filtered?


I am running this query on MySQL Server. Assuming TableA contains million rows. Is there any alternative and efficient way of writing this query?



Answers

The order of execution is determined by the query planner.



You can influence it by creating indexes.



For this query I suggest changing COUNT(b.ID) to COUNT(*). I also suggest creating a compound index on (id, referId). That should provide coverage for the stuff you need from the first instance of your table.



For more information on query performance, this is an excellent resource. http://planet.mysql.com/entry/?id=661727



Answers

The rows selected by a query are filtered first by the FROM clause join conditions, then the WHERE clause search conditions, and then the HAVING clause search conditions. Inner joins can be specified in either the FROM or WHERE clause without affecting the final result.





The following sections have been defined but have not been rendered for the layout page “~/Views/Shared/_Layout.cshtml”: “featured”

Stack Trace:



[HttpException (0x80004005): The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "featured".]
System.Web.WebPages.WebPageBase.VerifyRenderedBodyOrSections() +192327
System.Web.WebPages.WebPageBase.PopContext() +316
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +95
System.Web.WebPages.<>c__DisplayClass7.b__6(TextWriter writer) +233
System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +10
System.Web.WebPages.WebPageBase.Write(HelperResult result) +71
System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action1 body) +64
System.Web.WebPages.WebPageBase.PopContext() +246
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +95
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +260
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +295
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +23
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func
1 continuation) +242
System.Web.Mvc.<>c__DisplayClass1c.b__19() +21
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) +177
System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +89
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +102
System.Web.Mvc.Async.WrappedAsyncResult
1.End() +57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +43
System.Web.Mvc.<>c__DisplayClass1d.b__18(IAsyncResult asyncResult) +14
System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult1.End() +62
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +57
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult
1.End() +62
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +47
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.<>c__DisplayClass8.b__3(IAsyncResult asyncResult) +25
System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +47
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9658396
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155



Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34249



Answers

you have to include **




"@RenderSection("featured", required: false)"




** in the header section of the _layout.cshtml





Question

I'm being deposed in couple hours.

Is it better to give a short "incriminating" answer or a qualified "non-incriminating" answer?

Example: "Did you wreck your vehicle into the telephone pole?"

Short "incriminating" answer: "Yes!"

Qualified answer: "To avoid the child who ran in front of my vehicle, I swerved and wrecked into the pole."



Answer

You wait until now to ask the question! The answer depends upon whether you have an attorney to clear up your responses, the question itself, what your answer will be, etc. The term wrecked.is objectionable as being a conclusion. My guess is that it would be better for you to give short answers as otherwise you will appear to be a combative, poor witness.





Laravel5 illuminate composer messagebag package

I'd like to install the illuminate/support/messagebag but can't seem to find a composer address to do this.



Is this still available for Laravel5 and if so, what composer details do I need to use?



Answers

If you need a general purpouse message package, you can try this one here, if you just need a Flash message bag, you can try this one



EDIT: As I said in the comments, I thought you needed another one. MessageBag is there, wasn't removed. I've done a fresh installation and I got it working. Check my composer.json, there's nothing rare in there, just laravel:



"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},


Maybe there's a problem with your installation, but it should be there.





Question

License Agreement instead of a Rental Lease


I saw an apt recently, and the landlord is asking that I sign a License Agreement instead of a Lease. Are they the same thing?



Answer

Re: License Agreement instead of a Rental Lease


They are not the same and depending on where (and type) the property is, it may not be enforceable.



Answer

Re: License Agreement instead of a Rental Lease


No. A license can be revoked, a lease can not. A lease offers you protections that a license does not.






↑このページのトップヘ