조건

flask 환경에서 in 을 사용하여 검색

방법

flask에서 변수를 받을때 리스트 형태( getlist('ip_group[]' )로 받음

sql 쿼리에 매개변수 전달 시, 리스트 형태를 전달

[html]

<select class="select2" multiple="multiple" name="ip_group[]" id="ip_group" />
  <option value="127.0.0.1">127.0.0.1</option>
  <option value="127.0.0.2">127.0.0.2</option>
</select>


[js]

var ip_group = $('#ip_group').val();

$.ajax({
        url:'/project/server_info',
        type:'POST',
        data: {ip_group:ip_group},
        success: function(data){
           showAlert('Server Info', data.info, 2, 2000);
       }     


[python + flask]

@project_blueprint.route('project/server_info', methods=['POST'])
@login_required
def project_server_info():
    ip_group = request.form.getlist('ip_group[]')
    
    ql = text('select a, b, c, d, e from tblServer where ip in :ip_group')
    connection = db.session.connection()
    results = db.engine.execute(sql, ip_group=ip_group)
    
    if results != None:
        details = []
        
        for r in results:
            details.append(r[0])
            details.append(r[1])
            details.append(r[2])
            details.append(r[3])
            details.append(r[4])
            
        return jsonify(details=details)

참고

https://stackoverflow.com/questions/8603088/sqlalchemy-in-clause

문제

MySQL의 like 조건에서 \가 포함된 경우 원하는 형태로 조회가 되지 않음

해결

조건

title 컬럼의 \m가 포함된 형태로 검색 ( 검색 내용에 \ 가 포함 )

1. \를 두개 더 붙인다

where title like '%\\\m%'


2. escape를 사용
   기본적으로 escape가 \로 설정되어 있음. 이걸 다른 문자로 변경(예제는 | 를 사용)

where title like '%|m%' escape '|'

참고

https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=leokevin&logNo=220645049628

현상

동일한 OS 버전 / 동일한 MSSQL 버전 / 동일한 구조 / 동일한 요청량 

동일한 조건이지만 트랜잭션 로그 및 로그 백업 파일의 사이즈가 약 8배 차이가 나는 경우

원인

Physical Disk Sector 크기의 차이

기존에는 Physical Disk Sector 사이즈를 512 Byte를 사용하였지만, 최근 H/W 스펙이 올라가며 4096 Byte를 디폴트로 설정되어 구성되는 경우가 있음.

 

확인

명령프롬포트(CMD)를 관리자모드로 실행하여 아래 명령어 실행

fsutil fsinfo ntfsinfo yourLogDrive:
fsutil fsinfo sectorinfo yourLogDrive:

------------- 실행 예

C:\WINDOWS\system32>fsutil fsinfo ntfsinfo D:
NTFS 볼륨 일련 번호 :        0x???????????????
NTFS 버전      :                3.1
LFS 버전       :                2.0
총 섹터     :                1,953,519,615  (931.5 GB)
총 클러스터    :                  244,189,951  (931.5 GB)
사용 가능한 클러스터     :                  217,448,760  (829.5 GB)
예약된 총 클러스터 :                  5,087  ( 19.9 MB)
저장소 예약을 위해 예약됨 :                 0  (  0.0 KB)
섹터당 바이트  :                512
실제 섹터당 바이트 :        4096
클러스터당 바이트 :                4096


C:\WINDOWS\system32>fsutil fsinfo sectorinfo D:
LogicalBytesPerSector:                                 512
PhysicalBytesPerSectorForAtomicity:                    4096
PhysicalBytesPerSectorForPerformance:                  4096
FileSystemEffectivePhysicalBytesPerSectorForAtomicity: 4096
장치 맞춤:                                      정렬됨(0x000)
장치 파티션 맞춤:                         정렬됨(0x000)
일반 검색 수행
자르기 지원 안 됨
DAX 지원 안 함
씬 프로비저닝되지 않음

C:\WINDOWS\system32>

 

PhysicalBytesPerSector Transaction Log I/O간의 관계

SQL Server transaction log 파일은 physical sector-aligned boundary  생성되며, sector-aligned sizes  sector-aligned boundaries  데이터가 쓰여집니다.
, PhysicalBytesPerSector 크기에 따라 IO 단위가 달라지며,  값이 512 bytes  경우 트랜잭션 로그는 512 Bytes – 60KB 단위로 저장  있습니다.
또한 PhysicalBytesPerSector 크기가 4KB 경우 4 KB – 60KB 단위로 저장  있습니다.


to Top