잊지 않겠습니다.

1. 인덱스 컬럼절의 변형

 

select ename from emp where sal * 2.1 > 950 (X)

select ename from emp where sal > 950/2.1   (O)

 

select ename from emp where to_char(hiredate, 'DDMMYY') = '250884'   (X)

select ename from emp where hiredate = to_date('250884', 'DDMMYY')    (O)

 

=> 인덱스 컬럼에 변형을 가하면 사용할수 없다. 단 변형가능 하더라도 쓰고 싶다면 쓸수야 있지만..

    create index .... on emp to_char(hiredate, 'DDMMYY') ....이렇게 해야할까.ㅋ;;

 

2. 내부적인 데이터변환

 

select * from emp where hiredate = '14-JAN-85' (X)

select * from emp hiredate = to_date('71-10-22', 'YY/DD/MM')   (O)

 

select * from emp where empno = '7936' (X)

select * from emp where empno = to_numer('7936')                   (O)

 

=> 내부적인 데이터변환에서 가장 많이 실수하는 부분은 문자값 데이터타입을 갖는 컬럼에 '값'->값 으로 하는

     유형이랄까... 딱 맞는 데이터타입을 사용해야만 함!!

 

3. NULL 조건의 사용

 

select ename from emp where comm is null          (X)

select ename from emp where comm is not null    (X)

 

select ename from emp where ename > ''            (O)

select ename from emp where comm >= 0            (O)

 

=> NULL 조건으로 검색한다는 가정하에는 거의 인덱스 풀 스캔이 일어남.적절히 사용할것!!

 

4. 부정형 조건의 사용

 

select ename from emp where deptno != 30 (X)

select ename from emp wehre deptno < 30 and deptno > 30      (O)

 

=> 논리적으로 부정형을 이용하여 인덱스를 사용하겠다는것은 말이 안됨.

5. Like 연산자 사용

 

select * from emp where ename like 'S%'         (O)

select * from emp where ename like '%S%'      (X)

 

=> %S% 부분을 꼭 쓰고 싶다면 이런식으로 하는것이...다 넣는거다.ㅋ

    AS%, BS%, ..... 본문찾기 기능은 없어지는 추세.

 

6. 최적기가 판단

 

RBO경우 무조건 탄다. CBO는 통계값을 기준으로 하기 때문에 DBA가 잘해야지..HINT를 적절히..

 

 

기타. 인덱스를 이용한 sort 회피 방법

 

select empno, ename, job, comm from emp order by empno             (정렬)

select empno, ename, job, comm from emp where empno >= 0         (정렬제거)

 

Index를 사용하지 않고 개발을 하는 경우가 많은데, 이 부분에 대한 고려는 항시 필요하다. 언제나 이런 내용까지 같이 고민을 하는 개발자가 될 수 있을지... 참 길이 멀고도 험한것 같다.
Posted by Y2K
,

AD Update source

.NET Framework 2009. 11. 16. 09:44
AD와 같은 분산 시스템에서의 업데이트는 개발자뿐 아니라 시스템 관리자들에게 매우 중요한 일이 된다.
특히 Exchange나 Domain에서의 권한문제 등을 다룰때, AD의 값을 어떻게 변경하느냐에 따라서 각 시스템의 운영자체가 달라지기 때문에 특히 주의를 해야지 된다. 그리고, 시스템측에서는 이러한 AD의 일괄 업데이트를 Powershell이 나오기 전에는 할 방법이 마땅치 않아서 곤란해지는 경우가 많다. PowerShell의 경우에는 매우 쉽게 이런 일을 할 수 있다.

먼저, AD는 모두 DirectoryEntry로 접근을 한다. 각 DirectoryEntry를 통해서 AD Query를 이용한 결과값을 차례대로 업데이트를 하는 것이 가장 유용한 방법이다. 

string ldap = String.Format("LDAP://{0}", LdapPath);  //AD Path 설정

using(DirectoryEntry entry = new DirectoryEntry(ldap, UserName, Password, AuthenticationTypes.Sealing))
{
    //AD Search query
    using(DirectorySearcher searcher = new DirectorySearcher(entry, filter, null, SearchScope.Subtree))
    {
        //Update 할 item의 limit 갯수 설정, 너무나 많은 값들을 업데이트 하는 경우에, 실수라도 하게 되면 큰일도 날수도 있고.;
        searcher.SizeLimit = Buffer;
        SearchResultCollection results = searcher.FindAll();

        foreach(SearchResult result in results)
        {
            try
            {
                //각 Entry의 Directory 값들을 모두 가지고 온다. AD에서의 하나의 Item은 여러개의 Property로 구성이 되기 때문에, 각 Property의 값들의 변경을 행할때 유용하다.
                DirectoryEntry objectEntry = result.GetDirectoryEntry();
                //integer값으로 변경시켜주는 상태이다. 각 값의 type에 따라서 변경하게 해주는 것은 좀더 연구가 필요하다.
                int changeValue = int.Parse(value);
                objectEntry.Properties[propertyName].Value = changeValue;
                objectEntry.CommitChanges();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
    }
}
Posted by Y2K
,

IIS Configuration

.NET Framework 2009. 10. 9. 15:22
IIS를 직접 제어해서 WebSite를 구성해주는 Setup 파일이라던지, 아니면 자신의 요구대로 IIS의 설정을 변경할 수 있는 방법을 제공

참고 : 
http://www.iis.net/ConfigReference

Microsoft.Web.Administration를 사용하면 IIS 7.0에서부터 사용되는 모든 설정의 Config를 변경시킬 수 있다. 기본적으로 복사되는 Machine.config의 세부 설정을 변경시켜줄 수 있게 된다. 간단히 Wrapping시킨 IisSite class의 코드는 다음과 같다. 




public class IisSite
  {
      public string SiteName { get; private set; }
      public string LastErrorMessage { get; private set; }

      public IisSite(string siteName)
      {
          SiteName = siteName;
      }

      public bool AddApplication(string applicationPool, string applicationName, string path)
      {
          try
          {
              using (ServerManager mgr = new ServerManager())
              {
                  Site site = mgr.Sites[SiteName];
                  if (site != null)
                  {
                      string appName;
                      if(applicationName.StartsWith("/"))
                      {
                          appName = applicationName;
                      }
                      else
                      {
                          appName = "/" + applicationName;
                      }

                      site.Applications.Add(appName, path);
                      Application app = site.Applications[appName];
                      app.ApplicationPoolName = applicationPool;
                      mgr.CommitChanges();
                  }

                  return true;
              }
          }
          catch(Exception ex)
          {
              LastErrorMessage = ex.StackTrace;
              return false;
          }
      }

      public bool SetAuthicationForAnonymous(string applicationName, bool enable)
      {
          return SetAuthicationEnable(applicationName, IisConfigConstant.AnonymousAuth, enable);
      }

      public bool SetAuthicationForBasic(string applicationName, bool enable)
      {
          return SetAuthicationEnable(applicationName, IisConfigConstant.BasicAuth, enable);
      }

      private bool SetAuthicationEnable(string applicationName, string authType, bool enable)
      {
          try
          {
              string appPath = string.Format("{0}/{1}", SiteName, applicationName);
              using (ServerManager mgr = new ServerManager())
              {
                  Configuration config = mgr.GetApplicationHostConfiguration();
                  ConfigurationSection basicAuthenticationSection = config.GetSection(authType, appPath);
                  basicAuthenticationSection[IisConfigConstant.Enabled] = enable;
                  mgr.CommitChanges();

                  return true;
              }
          }
          catch(Exception ex)
          {
              LastErrorMessage = ex.Message;
              return false;
          }
      }

      public bool SetDefaultDomainForBasic(string applicationName, string defaultDomain)
      {
          return SetAuthDefaultDomain(applicationName, IisConfigConstant.BasicAuth, defaultDomain);
      }

      private bool SetAuthDefaultDomain(string applicationName, string authType, string defaultDomainName)
      {
          try
          {
              using (ServerManager mgr = new ServerManager())
              {
                  string appPath = string.Format("{0}/{1}", SiteName, applicationName);

                  //NOTE : Set Auth
                  Configuration config = mgr.GetApplicationHostConfiguration();
                  ConfigurationSection basicAuthenticationSection = config.GetSection(authType, appPath);
                  basicAuthenticationSection[IisConfigConstant.DefaultDomain] = defaultDomainName;
                  mgr.CommitChanges();

                  return true;
              }
          }
          catch(Exception ex)
          {
              LastErrorMessage = ex.Message;
              return false;
          }
      }
Posted by Y2K
,