[Solved] GeoArea.STAsText() in sql server
Looking to automatically optimize YOUR SQL query? Start for free.

EverSQL Database Performance Knowledge Base

GeoArea.STAsText() in sql server

Database type:

Is there any alternative of GeoArea.STAsText() in sql server? I have the below query:

Select
    T.ClassType, 
    G.CorporationID, 
    G.ClassName,
    GeoArea.STAsText() As GeoText 
 From 
    Classtypes t 
    Inner Join Class g On T.PKClassTypeID = G.FKClassTypeID 
Where 
    T.ClassType In ('Shop','Home') And
    G.quarterid=10

This is taking very huge time to compute. But if I eliminate the GeoArea.STAsText() then my query runs in a fraction of seconds. Is there a fast alternative to GeoArea.STAsText()?

How to optimize this SQL query?

The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:

  1. Description of the steps you can take to speed up the query.
  2. The optimal indexes for this query, which you can copy and create in your database.
  3. An automatically re-written query you can copy and execute in your database.
The optimization process and recommendations:
  1. Create Optimal Indexes (modified query below): The recommended indexes are an integral part of this optimization effort and should be created before testing the execution duration of the optimized query.
Optimal indexes for this query:
CREATE INDEX class_idx_quarterid ON Class (quarterid);
CREATE INDEX classtypes_idx_pkclasstypeid_classtype ON Classtypes (PKClassTypeID,ClassType);
The optimized query:
SELECT
        T.ClassType,
        G.CorporationID,
        G.ClassName,
        GeoArea.STAsText() AS GeoText 
    FROM
        Classtypes t 
    INNER JOIN
        Class g 
            ON T.PKClassTypeID = G.FKClassTypeID 
    WHERE
        T.ClassType IN (
            'Shop', 'Home'
        ) 
        AND G.quarterid = 10

Related Articles



* original question posted on StackOverflow here.